Skip to content

Commit

Permalink
handle global constant collision with local variable after inline (#…
Browse files Browse the repository at this point in the history
…2617)

fixes #2616
  • Loading branch information
alexlamsl committed Dec 18, 2017
1 parent 8ddcbc3 commit 4b334ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/compress.js
Expand Up @@ -4028,13 +4028,16 @@ merge(Compressor.prototype, {
expressions.unshift(value || make_node(AST_Undefined, self));
}
} else {
var def = name.definition();
scope.var_names()[name.name] = true;
scope.variables.set(name.name, def);
scope.enclosed.push(def);
decls.unshift(make_node(AST_VarDef, name, {
name: name,
value: null
}));
var sym = make_node(AST_SymbolRef, name, name);
name.definition().references.push(sym);
def.references.push(sym);
expressions.unshift(make_node(AST_Assign, self, {
operator: "=",
left: sym,
Expand Down
34 changes: 34 additions & 0 deletions test/compress/functions.js
Expand Up @@ -1049,3 +1049,37 @@ unsafe_call_2: {
}
expect_stdout: true
}

issue_2616: {
options = {
evaluate: true,
inline: true,
reduce_vars: true,
side_effects: true,
unused: true,
}
input: {
var c = "FAIL";
(function() {
function f() {
function g(NaN) {
(true << NaN) - 0/0 || (c = "PASS");
}
g([]);
}
f();
})();
console.log(c);
}
expect: {
var c = "FAIL";
(function() {
(function() {
NaN = [], (true << NaN) - 0/0 || (c = "PASS");
var NaN;
})();
})();
console.log(c);
}
expect_stdout: "PASS"
}

0 comments on commit 4b334ed

Please sign in to comment.