If without else
Jordi Baylina jordi@baylina.cat
Wed, 24 Oct 2018 19:59:50 +0200
3 files changed,
12 insertions(+),
6 deletions(-)
M
src/compiler.js
→
src/compiler.js
@@ -31,7 +31,7 @@ module.exports = compile;
const parser = require("../parser/jaz.js").parser; -const timeout = ms => new Promise(res => setTimeout(res, ms)) +const timeout = ms => new Promise(res => setTimeout(res, ms)); async function compile(srcFile) { const fullFileName = srcFile;
M
src/exec.js
→
src/exec.js
@@ -578,8 +578,10 @@ if ((v.value.neq(0))&&(!ctx.returnValue)) {
exec(ctx, ast.then); if (ctx.error) return; } else { - exec(ctx, ast.else); - if (ctx.error) return; + if (ast.else) { + exec(ctx, ast.else); + if (ctx.error) return; + } } }
M
src/gencode.js
→
src/gencode.js
@@ -246,9 +246,13 @@ const condition = gen(ctx, ast.condition);
if (ctx.error) return; const thenBody = gen(ctx, ast.then); if (ctx.error) return; - const elseBody = gen(ctx, ast.else); - if (ctx.error) return; - return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`; + if (ast.else) { + const elseBody = gen(ctx, ast.else); + if (ctx.error) return; + return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`; + } else { + return `if (${condition}) {\n${thenBody}\n}\n`; + } }