fix corner case collapse_vars (#5569)

fixes #5568
This commit is contained in:
Alex Lam S.L
2022-07-18 02:04:51 +01:00
committed by GitHub
parent ec4558be29
commit f0120e90b6
4 changed files with 36 additions and 1 deletions

View File

@@ -141,6 +141,7 @@ var AST_Node = DEFNODE("Node", "start end", {
}, null);
DEF_BITPROPS(AST_Node, [
// AST_Node
"_optimized",
"_squeezed",
// AST_Call
@@ -175,6 +176,8 @@ DEF_BITPROPS(AST_Node, [
"pure",
// AST_Assign
"redundant",
// AST_Node
"single_use",
// AST_ClassProperty
"static",
// AST_Call

View File

@@ -2080,7 +2080,7 @@ Compressor.prototype.compress = function(node) {
return node;
}
// Skip transient nodes caused by single-use variable replacement
if (node.single_use && parent instanceof AST_VarDef && parent.value === node) return node;
if (node.single_use) return node;
// Replace variable with assignment when found
var hit_rhs;
if (!(node instanceof AST_SymbolDeclaration)

View File

@@ -9979,3 +9979,25 @@ issue_5396: {
}
expect_stdout: "PASS"
}
issue_5568: {
options = {
collapse_vars: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
A = "FAIL";
var a = (A = "PASS", !1);
for (var b in a);
console.log(A);
}
expect: {
A = "FAIL";
for (var b in !(A = "PASS"));
console.log(A);
}
expect_stdout: "PASS"
}

View File

@@ -460,6 +460,16 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
return to_statement(node.definitions[0].value);
}
}
else if (node instanceof U.AST_VarDef) {
if (node.value) {
node.start._permute++;
CHANGED = true;
return new U.AST_VarDef({
name: node.name,
start: {},
});
}
}
if (in_list) {
// drop switch branches