diff options
-rw-r--r-- | lib/compress.js | 6 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 5f35b98a..efc7c47f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1240,7 +1240,10 @@ merge(Compressor.prototype, { } function should_stop(node, parent) { - if (node instanceof AST_Assign) return node.operator != "=" && lhs.equivalent_to(node.left); + if (parent instanceof AST_For) return node !== parent.init; + if (node instanceof AST_Assign) { + return node.operator != "=" && lhs.equivalent_to(node.left); + } if (node instanceof AST_Call) { return lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression); } @@ -1249,7 +1252,6 @@ merge(Compressor.prototype, { if (node instanceof AST_LoopControl) return true; if (node instanceof AST_Try) return true; if (node instanceof AST_With) return true; - if (parent instanceof AST_For) return node !== parent.init; if (replace_all) return false; return node instanceof AST_SymbolRef && !node.is_declared(compressor); } diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index c915041f..bcc8b833 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -4931,6 +4931,27 @@ collapse_rhs_lhs_2: { expect_stdout: "PASS" } +collapse_rhs_loop: { + options = { + collapse_vars: true, + } + input: { + var s; + s = "<tpl>PASS</tpl>"; + for (var m, r = /<tpl>(.*)<\/tpl>/; m = s.match(r);) + s = s.replace(m[0], m[1]); + console.log(s); + } + expect: { + var s; + s = "<tpl>PASS</tpl>"; + for (var m, r = /<tpl>(.*)<\/tpl>/; m = s.match(r);) + s = s.replace(m[0], m[1]); + console.log(s); + } + expect_stdout: "PASS" +} + collapse_rhs_side_effects: { options = { collapse_vars: true, |