Skip to content

Commit

Permalink
fix collapse_vars on default function argument (#2299)
Browse files Browse the repository at this point in the history
Avoid collision with local variable `undefined` under certain corner cases.

fixes #2298
  • Loading branch information
alexlamsl committed Sep 3, 2017
1 parent 3f35586 commit 395a17c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -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"
}

0 comments on commit 395a17c

Please sign in to comment.