diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-15 12:47:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 19:47:12 +0800 |
commit | 335456cf7766938be44e08102efffc94c6cbd07c (patch) | |
tree | 2fa574b4393e35e9eaa24a2d00991bad6fda4038 | |
parent | d64d0b0bec426f77e0ca73d2463de3c1a2e71c98 (diff) | |
download | tracifyjs-335456cf7766938be44e08102efffc94c6cbd07c.tar.gz tracifyjs-335456cf7766938be44e08102efffc94c6cbd07c.zip |
fix corner case in `merge_vars` (#4104)
fixes #4103
-rw-r--r-- | lib/compress.js | 3 | ||||
-rw-r--r-- | test/compress/merge_vars.js | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 171746ac..b605dda7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4315,10 +4315,11 @@ merge(Compressor.prototype, { var prev = Object.create(null); var tw = new TreeWalker(function(node, descend) { if (node instanceof AST_Assign) { + if (node.operator != "=") return; var sym = node.left; if (!(sym instanceof AST_SymbolRef)) return; node.right.walk(tw); - mark(sym, node.operator == "="); + mark(sym, true); return true; } if (node instanceof AST_Binary) { diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 076668e5..6923fe73 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -260,3 +260,30 @@ read_before_assign_2: { } expect_stdout: "PASS" } + +issue_4103: { + options = { + merge_vars: true, + side_effects: true, + toplevel: true, + } + input: { + function f(a) { + console.log(a); + } + var b = 0; + var c = f(b++ + (c %= 1 >> console.log(c = 0))); + b; + } + expect: { + function f(a) { + console.log(a); + } + var b = 0; + var c = f(b++ + (c %= 1 >> console.log(c = 0))); + } + expect_stdout: [ + "0", + "NaN", + ] +} |