enhance collapse_vars (#3351)
This commit is contained in:
@@ -1361,6 +1361,7 @@ merge(Compressor.prototype, {
|
||||
hit_stack.push(expr);
|
||||
if (expr instanceof AST_Assign) {
|
||||
candidates.push(hit_stack.slice());
|
||||
extract_candidates(expr.left);
|
||||
extract_candidates(expr.right);
|
||||
} else if (expr instanceof AST_Binary) {
|
||||
extract_candidates(expr.left);
|
||||
@@ -1376,6 +1377,8 @@ merge(Compressor.prototype, {
|
||||
extract_candidates(expr.alternative);
|
||||
} else if (expr instanceof AST_Definitions) {
|
||||
expr.definitions.forEach(extract_candidates);
|
||||
} else if (expr instanceof AST_Dot) {
|
||||
extract_candidates(expr.expression);
|
||||
} else if (expr instanceof AST_DWLoop) {
|
||||
extract_candidates(expr.condition);
|
||||
if (!(expr.body instanceof AST_Block)) {
|
||||
@@ -1407,6 +1410,9 @@ merge(Compressor.prototype, {
|
||||
expr.expressions.forEach(extract_candidates);
|
||||
} else if (expr instanceof AST_SimpleStatement) {
|
||||
extract_candidates(expr.body);
|
||||
} else if (expr instanceof AST_Sub) {
|
||||
extract_candidates(expr.expression);
|
||||
extract_candidates(expr.property);
|
||||
} else if (expr instanceof AST_Switch) {
|
||||
extract_candidates(expr.expression);
|
||||
expr.body.forEach(extract_candidates);
|
||||
@@ -1465,6 +1471,7 @@ merge(Compressor.prototype, {
|
||||
return node;
|
||||
}
|
||||
if (parent instanceof AST_IterationStatement) return node;
|
||||
if (parent instanceof AST_PropAccess) return node;
|
||||
if (parent instanceof AST_Sequence) {
|
||||
return find_stop(parent, level + 1, parent.tail_node() !== node);
|
||||
}
|
||||
|
||||
@@ -3895,11 +3895,11 @@ issue_2436_10: {
|
||||
o = { b: 3 };
|
||||
return n;
|
||||
}
|
||||
console.log((c = o, [
|
||||
c.a,
|
||||
console.log([
|
||||
(c = o).a,
|
||||
f(c.b),
|
||||
c.b,
|
||||
]).join(" "));
|
||||
].join(" "));
|
||||
var c;
|
||||
}
|
||||
expect_stdout: "1 2 2"
|
||||
@@ -6121,3 +6121,39 @@ issue_3327: {
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
}
|
||||
|
||||
assign_left: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
(b = a, b.p).q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
(b = a).p.q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sub_property: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a, b.length - 1)];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a).length - 1];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user