fix corner case in reduce_vars (#5121)

fixes #5120
This commit is contained in:
Alex Lam S.L
2021-08-25 03:39:35 +01:00
committed by GitHub
parent db94d21980
commit c3aef23614
3 changed files with 41 additions and 13 deletions

View File

@@ -11231,21 +11231,20 @@ merge(Compressor.prototype, {
if (!(node instanceof AST_SymbolRef)) return; if (!(node instanceof AST_SymbolRef)) return;
var def = node.definition(); var def = node.definition();
if (def === defun_def) { if (def === defun_def) {
node.thedef = lambda_def; node.thedef = def = lambda_def;
lambda_def.references.push(node);
} else { } else {
def.single_use = false; def.single_use = false;
var fn = node.fixed_value(); var fn = node.fixed_value();
if (!is_lambda(fn)) return; if (is_lambda(fn)
if (!fn.name) return; && fn.name
if (fn.name.definition() !== def) return; && fn.name.definition() === def
if (def.scope !== fn.name.scope) return; && def.scope === fn.name.scope
if (fixed.variables.get(fn.name.name) !== def) return; && fixed.variables.get(fn.name.name) === def) {
fn.name = fn.name.clone(); fn.name = fn.name.clone();
var value_def = value.variables.get(fn.name.name) || value[def_fn_name](fn.name); node.thedef = def = value.variables.get(fn.name.name) || value[def_fn_name](fn.name);
node.thedef = value_def; }
value_def.references.push(node);
} }
def.references.push(node);
})); }));
} else { } else {
if (fixed instanceof AST_Scope) { if (fixed instanceof AST_Scope) {

View File

@@ -99,8 +99,8 @@ issue_4664: {
expect: { expect: {
(function f() { (function f() {
new function(a) { new function(a) {
console.log(typeof f, 1073741824, typeof this); console.log(typeof f, a, typeof this);
}(A = 0); }((A = 0, 2 ** 30));
})(); })();
} }
expect_stdout: "function 1073741824 object" expect_stdout: "function 1073741824 object"

View File

@@ -6600,3 +6600,32 @@ shorter_without_void: {
"baz", "baz",
] ]
} }
issue_5120: {
options = {
functions: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = function f() {
function g() {
f || g();
}
g();
return f.valueOf();
};
console.log(a() === a ? "PASS" : "FAIL");
}
expect: {
function a() {
(function g() {
a || g();
})();
return a.valueOf();
}
console.log(a() === a ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
}