fix corner case in merge_vars (#4299)

fixes #4298
This commit is contained in:
Alex Lam S.L
2020-11-18 15:43:55 +00:00
committed by GitHub
parent 35283e5dd1
commit f6a83f7944
2 changed files with 45 additions and 3 deletions

View File

@@ -4749,9 +4749,13 @@ merge(Compressor.prototype, {
var def = ref.definition(); var def = ref.definition();
var ldef = node.variables.get(ref.name); var ldef = node.variables.get(ref.name);
if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) { if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) {
references[def.id] = false;
references[ldef.id] = false; references[ldef.id] = false;
} else { } else {
var save = segment;
pop();
mark(ref, true, false); mark(ref, true, false);
segment = save;
} }
return true; return true;
}); });

View File

@@ -1490,10 +1490,10 @@ issue_4294: {
expect: { expect: {
A = "PASS"; A = "PASS";
(function() { (function() {
var a = function({ var b = function({
[a]: {}, [b]: {},
}) {}({ }) {}({
[a]: 0, [b]: 0,
}); });
var b = A; var b = A;
console.log(b); console.log(b);
@@ -1502,3 +1502,41 @@ issue_4294: {
expect_stdout: "PASS" expect_stdout: "PASS"
node_version: ">=6" node_version: ">=6"
} }
issue_4298: {
options = {
merge_vars: true,
}
input: {
(function() {
var a = {
object: "PASS",
};
function f({
[typeof a]: b,
}) {
var a = b;
return a;
}
var c = f(a);
console.log(c);
})();
}
expect: {
(function() {
var a = {
object: "PASS",
};
function f({
[typeof a]: b,
}) {
var a = b;
return a;
}
var c = f(a);
console.log(c);
})();
}
expect_stdout: "PASS"
node_version: ">=6"
}