Skip to content

Commit 9246354

Browse files
committed
fix corner case in reduce_vars
fixes #5949
1 parent fa85d7e commit 9246354

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

lib/compress.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,22 +1400,23 @@ Compressor.prototype.compress = function(node) {
14001400
pop_scope(tw, fn);
14011401
return true;
14021402
});
1403-
def(AST_Sub, function(tw, descend) {
1403+
def(AST_Sub, function(tw) {
14041404
var node = this;
14051405
var expr = node.expression;
1406+
var prop = node.property;
1407+
expr.walk(tw);
14061408
if (node.optional) {
1407-
expr.walk(tw);
14081409
push(tw, true, true);
1409-
node.property.walk(tw);
1410+
prop.walk(tw);
14101411
pop(tw);
14111412
} else {
1412-
descend();
14131413
while (expr instanceof AST_Assign && expr.operator == "=") {
14141414
var lhs = expr.left;
14151415
if (lhs instanceof AST_SymbolRef) access(tw, lhs.definition());
14161416
expr = expr.right;
14171417
}
14181418
if (expr instanceof AST_SymbolRef) access(tw, expr.definition());
1419+
prop.walk(tw);
14191420
}
14201421
return true;
14211422
});

test/compress/properties.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,3 +1992,57 @@ issue_5927: {
19921992
}
19931993
expect_stdout: "PASS"
19941994
}
1995+
1996+
issue_5949_1: {
1997+
options = {
1998+
pure_getters: "strict",
1999+
reduce_vars: true,
2000+
side_effects: true,
2001+
}
2002+
input: {
2003+
var a = 42;
2004+
a[a = null];
2005+
try {
2006+
a.p;
2007+
console.log("FAIL");
2008+
} catch (e) {
2009+
console.log("PASS");
2010+
}
2011+
}
2012+
expect: {
2013+
var a = 42;
2014+
a[a = null];
2015+
try {
2016+
a.p;
2017+
console.log("FAIL");
2018+
} catch (e) {
2019+
console.log("PASS");
2020+
}
2021+
}
2022+
expect_stdout: "PASS"
2023+
}
2024+
2025+
issue_5949_2: {
2026+
options = {
2027+
pure_getters: "strict",
2028+
reduce_vars: true,
2029+
side_effects: true,
2030+
}
2031+
input: {
2032+
try {
2033+
a[42];
2034+
console.log("FAIL");
2035+
} catch (e) {
2036+
console.log("PASS");
2037+
}
2038+
}
2039+
expect: {
2040+
try {
2041+
a[42];
2042+
console.log("FAIL");
2043+
} catch (e) {
2044+
console.log("PASS");
2045+
}
2046+
}
2047+
expect_stdout: "PASS"
2048+
}

0 commit comments

Comments
 (0)