Skip to content

Commit

Permalink
fix corner case in reduce_vars
Browse files Browse the repository at this point in the history
fixes #5949
  • Loading branch information
alexlamsl committed Oct 27, 2024
1 parent af71274 commit 846783f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,22 +1400,23 @@ Compressor.prototype.compress = function(node) {
pop_scope(tw, fn);
return true;
});
def(AST_Sub, function(tw, descend) {
def(AST_Sub, function(tw) {
var node = this;
var expr = node.expression;
var prop = node.property;
expr.walk(tw);
if (node.optional) {
expr.walk(tw);
push(tw, true, true);
node.property.walk(tw);
prop.walk(tw);
pop(tw);
} else {
descend();
while (expr instanceof AST_Assign && expr.operator == "=") {
var lhs = expr.left;
if (lhs instanceof AST_SymbolRef) access(tw, lhs.definition());
expr = expr.right;
}
if (expr instanceof AST_SymbolRef) access(tw, expr.definition());
prop.walk(tw);
}
return true;
});
Expand Down
54 changes: 54 additions & 0 deletions test/compress/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,3 +1992,57 @@ issue_5927: {
}
expect_stdout: "PASS"
}

issue_5949_1: {
options = {
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
}
input: {
var a = 42;
a[a = null];
try {
a.p;
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect: {
var a = 42;
a[a = null];
try {
a.p;
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
}

issue_5949_2: {
options = {
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
}
input: {
try {
a[42];
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect: {
try {
a[42];
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
}

0 comments on commit 846783f

Please sign in to comment.