maintain order between side-effects and externally observable assignments (#2879)
fixes #2878
This commit is contained in:
@@ -1040,7 +1040,6 @@ merge(Compressor.prototype, {
|
|||||||
|| node instanceof AST_PropAccess
|
|| node instanceof AST_PropAccess
|
||||||
&& (side_effects || node.expression.may_throw_on_access(compressor))
|
&& (side_effects || node.expression.may_throw_on_access(compressor))
|
||||||
|| node instanceof AST_SymbolRef
|
|| node instanceof AST_SymbolRef
|
||||||
&& !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node)
|
|
||||||
&& (lvalues[node.name] || side_effects && may_modify(node))
|
&& (lvalues[node.name] || side_effects && may_modify(node))
|
||||||
|| node instanceof AST_VarDef && node.value
|
|| node instanceof AST_VarDef && node.value
|
||||||
&& (node.name.name in lvalues || side_effects && may_modify(node.name))
|
&& (node.name.name in lvalues || side_effects && may_modify(node.name))
|
||||||
|
|||||||
@@ -4433,3 +4433,37 @@ issue_2873_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2878: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function (a, b) {
|
||||||
|
function f2() {
|
||||||
|
if (a) c++;
|
||||||
|
}
|
||||||
|
b = f2();
|
||||||
|
a = 1;
|
||||||
|
b && b.b;
|
||||||
|
f2();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function (a, b) {
|
||||||
|
function f2() {
|
||||||
|
if (a) c++;
|
||||||
|
}
|
||||||
|
b = f2(),
|
||||||
|
a = 1,
|
||||||
|
b && b.b,
|
||||||
|
f2();
|
||||||
|
})(),
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user