Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5928)
Browse files Browse the repository at this point in the history
fixes #5927
  • Loading branch information
alexlamsl authored Aug 25, 2024
1 parent 4a92cdc commit cf87290
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ Compressor.prototype.compress = function(node) {
if (node instanceof AST_Function) {
return compressor.option("ie") && node.name && lvalues.has(node.name.name);
}
if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node, parent);
if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node);
if (node instanceof AST_PropAccess) {
var exp = node.expression;
if (compressor.option("unsafe")) {
Expand All @@ -2751,8 +2751,9 @@ Compressor.prototype.compress = function(node) {
}
if (node instanceof AST_Spread) return true;
if (node instanceof AST_SymbolRef) {
var assign_direct = symbol_in_lvalues(node);
if (is_undeclared_ref(node) && node.is_declared(compressor)) return false;
if (symbol_in_lvalues(node, parent)) return !is_direct_assignment(node, parent);
if (assign_direct) return !is_direct_assignment(node, parent);
if (side_effects && may_modify(node)) return true;
var def = node.definition();
return (in_try || def.scope.resolve() !== scope) && !can_drop_symbol(node);
Expand Down Expand Up @@ -3618,7 +3619,7 @@ Compressor.prototype.compress = function(node) {
return true;
}

function symbol_in_lvalues(sym, parent) {
function symbol_in_lvalues(sym) {
var lvalue = lvalues.get(sym.name);
if (!lvalue || all(lvalue, function(lhs) {
return !lhs;
Expand Down
24 changes: 24 additions & 0 deletions test/compress/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -1827,3 +1827,27 @@ issue_5682_sub_2: {
}
expect_stdout: "PASS"
}

issue_5927: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: "strict",
reduce_vars: true,
}
input: {
A = {};
while (console.log("PASS"));
A.p;
A.q = 42;
A.q.r = 42;
}
expect: {
A = {};
while (console.log("PASS"));
A.p;
A.q = 42;
A.q.r = 42;
}
expect_stdout: "PASS"
}

0 comments on commit cf87290

Please sign in to comment.