diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-04-03 03:07:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 10:07:18 +0800 |
commit | 0df028187d20b83e52d1829e14783284c5d09ad5 (patch) | |
tree | c7daa22f1067ecd74c4d61d2d68c1e085207d6c1 | |
parent | 10fbf8e295d6062fbaefe1b716878b95051dce2a (diff) | |
download | tracifyjs-0df028187d20b83e52d1829e14783284c5d09ad5.tar.gz tracifyjs-0df028187d20b83e52d1829e14783284c5d09ad5.zip |
fix corner case in `hoist_vars` (#4840)
fixes #4839
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/hoist_vars.js | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 2c1757b6..0150ba3d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6937,7 +6937,9 @@ merge(Compressor.prototype, { && vars.has(sym.name)) { var def = vars.get(sym.name); if (def.value) break; - def.value = expr.right.clone(); + var value = expr.right; + if (value instanceof AST_Sequence) value = value.clone(); + def.value = value; remove(defs, def); defs.push(def); body.shift(); diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js index 4118f765..8db060df 100644 --- a/test/compress/hoist_vars.js +++ b/test/compress/hoist_vars.js @@ -140,7 +140,6 @@ issue_4487: { functions: true, hoist_vars: true, keep_fnames: true, - passes: 2, reduce_vars: true, toplevel: true, unused: true, @@ -240,3 +239,29 @@ issue_4736: { } expect_stdout: "1073741824" } + +issue_4839: { + options = { + evaluate: true, + hoist_vars: true, + keep_fargs: false, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var o = function(a, b) { + return b && b; + }("foo"); + for (var k in o) + throw "FAIL"; + console.log("PASS"); + } + expect: { + var k, o = void 0; + for (k in o) + throw "FAIL"; + console.log("PASS"); + } + expect_stdout: "PASS" +} |