extend escape analysis on constant expression properties

fixes #2508
This commit is contained in:
alexlamsl 2017-11-24 12:53:44 +08:00
parent eb001dc1d9
commit f5c6118afd
2 changed files with 52 additions and 2 deletions

View File

@ -625,8 +625,10 @@ merge(Compressor.prototype, {
function mark_escaped(d, node, value, level) {
var parent = tw.parent(level);
if (value instanceof AST_Constant) return;
if (level > 0 && value instanceof AST_Function) return;
if (value) {
if (value.is_constant()) return;
if (level > 0 && value.is_constant_expression()) return;
}
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|| parent instanceof AST_Call && node !== parent.expression
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope

View File

@ -500,3 +500,51 @@ issue_2473_4: {
}
expect_stdout: "1 2"
}
issue_2508_1: {
options = {
collapse_vars: true,
hoist_props: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var o = {
a: [ 1 ],
f: function(x) {
console.log(x);
}
};
o.f(o.a);
}
expect: {
(function(x) {
console.log(x);
})([ 1 ]);
}
}
issue_2508_2: {
options = {
collapse_vars: true,
hoist_props: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var o = {
a: { b: 2 },
f: function(x) {
console.log(x);
}
};
o.f(o.a);
}
expect: {
(function(x) {
console.log(x);
})({ b: 2 });
}
}