suppress hoist_props for embedded assignments (#3074)

This commit is contained in:
Alex Lam S.L
2018-04-11 05:19:16 +08:00
committed by GitHub
parent 4dd7d0e39b
commit ba7069d52b
2 changed files with 36 additions and 1 deletions

View File

@@ -3639,7 +3639,10 @@ merge(Compressor.prototype, {
var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
var defs_by_id = Object.create(null);
return self.transform(new TreeTransformer(function(node, descend) {
if (node instanceof AST_Assign && node.operator == "=" && can_hoist(node.left, node.right, 1)) {
if (node instanceof AST_Assign
&& node.operator == "="
&& node.write_only
&& can_hoist(node.left, node.right, 1)) {
descend(node, this);
var defs = new Dictionary();
var assignments = [];

View File

@@ -824,3 +824,35 @@ issue_3071_2_toplevel: {
}
expect_stdout: "1"
}
issue_3071_3: {
options = {
hoist_props: true,
reduce_vars: true,
}
input: {
var c = 0;
(function(a, b) {
(function f(o) {
var n = 2;
while (--b + (o = {
p: c++,
}) && --n > 0);
})();
})();
console.log(c);
}
expect: {
var c = 0;
(function(a, b) {
(function f(o) {
var n = 2;
while (--b + (o = {
p: c++,
}) && --n > 0);
})();
})();
console.log(c);
}
expect_stdout: "2"
}