Skip to content

Commit cf87290

Browse files
authored
fix corner case in collapse_vars (#5928)
fixes #5927
1 parent 4a92cdc commit cf87290

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/compress.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,7 @@ Compressor.prototype.compress = function(node) {
27342734
if (node instanceof AST_Function) {
27352735
return compressor.option("ie") && node.name && lvalues.has(node.name.name);
27362736
}
2737-
if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node, parent);
2737+
if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node);
27382738
if (node instanceof AST_PropAccess) {
27392739
var exp = node.expression;
27402740
if (compressor.option("unsafe")) {
@@ -2751,8 +2751,9 @@ Compressor.prototype.compress = function(node) {
27512751
}
27522752
if (node instanceof AST_Spread) return true;
27532753
if (node instanceof AST_SymbolRef) {
2754+
var assign_direct = symbol_in_lvalues(node);
27542755
if (is_undeclared_ref(node) && node.is_declared(compressor)) return false;
2755-
if (symbol_in_lvalues(node, parent)) return !is_direct_assignment(node, parent);
2756+
if (assign_direct) return !is_direct_assignment(node, parent);
27562757
if (side_effects && may_modify(node)) return true;
27572758
var def = node.definition();
27582759
return (in_try || def.scope.resolve() !== scope) && !can_drop_symbol(node);
@@ -3618,7 +3619,7 @@ Compressor.prototype.compress = function(node) {
36183619
return true;
36193620
}
36203621

3621-
function symbol_in_lvalues(sym, parent) {
3622+
function symbol_in_lvalues(sym) {
36223623
var lvalue = lvalues.get(sym.name);
36233624
if (!lvalue || all(lvalue, function(lhs) {
36243625
return !lhs;

test/compress/properties.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,3 +1827,27 @@ issue_5682_sub_2: {
18271827
}
18281828
expect_stdout: "PASS"
18291829
}
1830+
1831+
issue_5927: {
1832+
options = {
1833+
collapse_vars: true,
1834+
evaluate: true,
1835+
pure_getters: "strict",
1836+
reduce_vars: true,
1837+
}
1838+
input: {
1839+
A = {};
1840+
while (console.log("PASS"));
1841+
A.p;
1842+
A.q = 42;
1843+
A.q.r = 42;
1844+
}
1845+
expect: {
1846+
A = {};
1847+
while (console.log("PASS"));
1848+
A.p;
1849+
A.q = 42;
1850+
A.q.r = 42;
1851+
}
1852+
expect_stdout: "PASS"
1853+
}

0 commit comments

Comments
 (0)