Skip to content

Commit f0120e9

Browse files
authored
fix corner case collapse_vars (#5569)
fixes #5568
1 parent ec4558b commit f0120e9

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

lib/ast.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ var AST_Node = DEFNODE("Node", "start end", {
141141
}, null);
142142

143143
DEF_BITPROPS(AST_Node, [
144+
// AST_Node
144145
"_optimized",
145146
"_squeezed",
146147
// AST_Call
@@ -175,6 +176,8 @@ DEF_BITPROPS(AST_Node, [
175176
"pure",
176177
// AST_Assign
177178
"redundant",
179+
// AST_Node
180+
"single_use",
178181
// AST_ClassProperty
179182
"static",
180183
// AST_Call

lib/compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ Compressor.prototype.compress = function(node) {
20802080
return node;
20812081
}
20822082
// Skip transient nodes caused by single-use variable replacement
2083-
if (node.single_use && parent instanceof AST_VarDef && parent.value === node) return node;
2083+
if (node.single_use) return node;
20842084
// Replace variable with assignment when found
20852085
var hit_rhs;
20862086
if (!(node instanceof AST_SymbolDeclaration)

test/compress/collapse_vars.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9979,3 +9979,25 @@ issue_5396: {
99799979
}
99809980
expect_stdout: "PASS"
99819981
}
9982+
9983+
issue_5568: {
9984+
options = {
9985+
collapse_vars: true,
9986+
evaluate: true,
9987+
reduce_vars: true,
9988+
toplevel: true,
9989+
unused: true,
9990+
}
9991+
input: {
9992+
A = "FAIL";
9993+
var a = (A = "PASS", !1);
9994+
for (var b in a);
9995+
console.log(A);
9996+
}
9997+
expect: {
9998+
A = "FAIL";
9999+
for (var b in !(A = "PASS"));
10000+
console.log(A);
10001+
}
10002+
expect_stdout: "PASS"
10003+
}

test/reduce.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
460460
return to_statement(node.definitions[0].value);
461461
}
462462
}
463+
else if (node instanceof U.AST_VarDef) {
464+
if (node.value) {
465+
node.start._permute++;
466+
CHANGED = true;
467+
return new U.AST_VarDef({
468+
name: node.name,
469+
start: {},
470+
});
471+
}
472+
}
463473

464474
if (in_list) {
465475
// drop switch branches

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy