diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-11 18:18:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 01:18:57 +0800 |
commit | 55451e7b78c1765c6c3011d880c7980c10b7330f (patch) | |
tree | 8e63243cf2c73dd25867e2cb1ba3c8d7cf0ed1e9 /lib/output.js | |
parent | ffcce28ce15afe9f0b8d8a4a83b901508eb866de (diff) | |
download | tracifyjs-55451e7b78c1765c6c3011d880c7980c10b7330f.tar.gz tracifyjs-55451e7b78c1765c6c3011d880c7980c10b7330f.zip |
support `const` (#4190)
Diffstat (limited to 'lib/output.js')
-rw-r--r-- | lib/output.js | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/lib/output.js b/lib/output.js index d99c61b8..05baa239 100644 --- a/lib/output.js +++ b/lib/output.js @@ -835,10 +835,6 @@ function OutputStream(options) { use_asm = was_asm; } - AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) { - force_statement(this.body, output); - }); - DEFPRINT(AST_Statement, function(output) { this.body.print(output); output.semicolon(); @@ -897,7 +893,7 @@ function OutputStream(options) { self.condition.print(output); }); output.space(); - self._do_print_body(output); + force_statement(self.body, output); }); DEFPRINT(AST_For, function(output) { var self = this; @@ -927,7 +923,7 @@ function OutputStream(options) { } }); output.space(); - self._do_print_body(output); + force_statement(self.body, output); }); DEFPRINT(AST_ForIn, function(output) { var self = this; @@ -941,7 +937,7 @@ function OutputStream(options) { self.object.print(output); }); output.space(); - self._do_print_body(output); + force_statement(self.body, output); }); DEFPRINT(AST_With, function(output) { var self = this; @@ -951,7 +947,7 @@ function OutputStream(options) { self.expression.print(output); }); output.space(); - self._do_print_body(output); + force_statement(self.body, output); }); /* -----[ functions ]----- */ @@ -1036,7 +1032,7 @@ function OutputStream(options) { else force_statement(self.alternative, output); } else { - self._do_print_body(output); + force_statement(self.body, output); } }); @@ -1114,17 +1110,21 @@ function OutputStream(options) { print_braced(this, output); }); - DEFPRINT(AST_Var, function(output) { - var self = this; - output.print("var"); - output.space(); - self.definitions.forEach(function(def, i) { - if (i) output.comma(); - def.print(output); - }); - var p = output.parent(); - if (p && p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon(); - }); + function print_definitinos(type) { + return function(output) { + var self = this; + output.print(type); + output.space(); + self.definitions.forEach(function(def, i) { + if (i) output.comma(); + def.print(output); + }); + var p = output.parent(); + if (p && p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon(); + }; + } + DEFPRINT(AST_Const, print_definitinos("const")); + DEFPRINT(AST_Var, print_definitinos("var")); function parenthesize_for_noin(node, output, noin) { var parens = false; @@ -1383,11 +1383,12 @@ function OutputStream(options) { function force_statement(stat, output) { if (output.option("braces")) { make_block(stat, output); + } else if (!stat || stat instanceof AST_EmptyStatement) { + output.force_semicolon(); + } else if (stat instanceof AST_Const) { + make_block(stat, output); } else { - if (!stat || stat instanceof AST_EmptyStatement) - output.force_semicolon(); - else - stat.print(output); + stat.print(output); } } |