From 3ad69fb652f7a364d8d4cf29bb3a37e4a3cc0f63 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sat, 25 Mar 2017 01:58:38 +0800 Subject: [PATCH] fix invalid `AST_For.init` Turns out the only place in `Compressor` which can generate invalid `AST_For.init` is within `drop_unused()`, so focus the fix-up efforts. supercedes #1652 fixes #1656 --- lib/compress.js | 4 +++- test/compress/drop-unused.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index e13985ee..ab7cca6f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1961,6 +1961,9 @@ merge(Compressor.prototype, { return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, { body: body }); + } else if (is_empty(node.init)) { + node.init = null; + return node; } } if (node instanceof AST_Scope && node !== self) @@ -2327,7 +2330,6 @@ merge(Compressor.prototype, { }; OPT(AST_For, function(self, compressor){ - if (is_empty(self.init)) self.init = null; if (!compressor.option("loops")) return self; if (self.condition) { var cond = self.condition.evaluate(compressor); diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 9f3bf77d..fabf8d9f 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -791,3 +791,17 @@ issue_1583: { } } } + +issue_1656: { + options = { + toplevel: true, + unused: true, + } + beautify = { + beautify: true, + } + input: { + for(var a=0;;); + } + expect_exact: "for (;;) ;" +}