diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-09-04 02:32:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-04 02:32:33 +0800 |
commit | 395a17ccda95362b1a7a5bd9ac0e6cda7f0946a8 (patch) | |
tree | 0db53fc17b4f8e090af5f99250cbf86dc184c468 | |
parent | 3f355866cf903c40c2bab2cd841ab2b56a2bacf1 (diff) | |
download | tracifyjs-395a17ccda95362b1a7a5bd9ac0e6cda7f0946a8.tar.gz tracifyjs-395a17ccda95362b1a7a5bd9ac0e6cda7f0946a8.zip |
fix `collapse_vars` on default function argument (#2299)
Avoid collision with local variable `undefined` under certain corner cases.
fixes #2298
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index b6a984cc..6e766fb0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -847,7 +847,7 @@ merge(Compressor.prototype, { if (sym.name in names) continue; names[sym.name] = true; var arg = iife.args[i]; - if (!arg) arg = make_node(AST_Undefined, sym); + if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor); else { var tw = new TreeWalker(function(node) { if (!arg) return true; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 7686addf..72123d4b 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -2342,3 +2342,45 @@ duplicate_argname: { } expect_stdout: "PASS" } + +issue_2298: { + options = { + collapse_vars: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + function f() { + var a = undefined; + var undefined = a++; + try { + !function g(b) { + b[1] = "foo"; + }(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + f(); + }(); + } + expect: { + !function() { + (function() { + var a = undefined; + var undefined = a++; + try { + !function(b) { + (void 0)[1] = "foo"; + }(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + })(); + }(); + } + expect_stdout: "PASS" +} |