@@ -313,19 +313,14 @@ merge(Compressor.prototype, {
|
||||
if (node instanceof AST_SymbolRef) {
|
||||
var d = node.definition();
|
||||
d.references.push(node);
|
||||
var value;
|
||||
if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") {
|
||||
d.fixed = false;
|
||||
} else if (d.fixed) {
|
||||
var value = node.fixed_value();
|
||||
value = node.fixed_value();
|
||||
if (value && ref_once(d)) {
|
||||
if (value instanceof AST_Lambda) {
|
||||
d.single_use = d.scope === node.scope
|
||||
&& !(d.orig[0] instanceof AST_SymbolFunarg)
|
||||
|| value.is_constant_expression(node.scope);
|
||||
} else {
|
||||
d.single_use = d.scope === node.scope
|
||||
&& value.is_constant_expression();
|
||||
}
|
||||
d.single_use = value instanceof AST_Lambda
|
||||
|| d.scope === node.scope && value.is_constant_expression();
|
||||
} else {
|
||||
d.single_use = false;
|
||||
}
|
||||
@@ -335,11 +330,10 @@ merge(Compressor.prototype, {
|
||||
} else {
|
||||
d.fixed = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
mark_escaped(d, node, value, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node instanceof AST_SymbolCatch) {
|
||||
node.definition().fixed = false;
|
||||
}
|
||||
@@ -385,10 +379,7 @@ merge(Compressor.prototype, {
|
||||
d.fixed = node;
|
||||
loop_ids[d.id] = in_loop;
|
||||
mark(d, true);
|
||||
if (ref_once(d)) {
|
||||
d.single_use = d.scope === d.references[0].scope
|
||||
|| node.is_constant_expression(d.references[0].scope);
|
||||
}
|
||||
d.single_use = ref_once(d);
|
||||
}
|
||||
var save_ids = safe_ids;
|
||||
safe_ids = Object.create(null);
|
||||
@@ -2209,7 +2200,10 @@ merge(Compressor.prototype, {
|
||||
&& !self.variables.has(def.name)) {
|
||||
if (scope) {
|
||||
var scope_def = scope.find_variable(node);
|
||||
if (def.undeclared ? !scope_def : scope_def === def) return true;
|
||||
if (def.undeclared ? !scope_def : scope_def === def) {
|
||||
result = "f";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = false;
|
||||
}
|
||||
@@ -4256,11 +4250,20 @@ merge(Compressor.prototype, {
|
||||
if (fixed instanceof AST_Defun) {
|
||||
d.fixed = fixed = make_node(AST_Function, fixed, fixed);
|
||||
}
|
||||
if (fixed
|
||||
&& d.single_use
|
||||
&& !(fixed instanceof AST_Function
|
||||
&& (d.escaped && d.scope !== self.scope
|
||||
|| recursive_ref(compressor, d)))) {
|
||||
if (d.single_use && fixed instanceof AST_Function) {
|
||||
if (d.escaped && d.scope !== self.scope || recursive_ref(compressor, d)) {
|
||||
d.single_use = false;
|
||||
} else if (d.scope !== self.scope || d.orig[0] instanceof AST_SymbolFunarg) {
|
||||
d.single_use = fixed.is_constant_expression(self.scope);
|
||||
if (d.single_use == "f") {
|
||||
var scope = self.scope;
|
||||
do {
|
||||
if (scope.name) scope.name.definition().single_use = false;
|
||||
} while (scope = scope.parent_scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d.single_use && fixed) {
|
||||
var value = fixed.optimize(compressor);
|
||||
return value === fixed ? fixed.clone(true) : value;
|
||||
}
|
||||
|
||||
@@ -3036,6 +3036,7 @@ issue_2437: {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
sequences: true,
|
||||
|
||||
@@ -1113,7 +1113,7 @@ issue_2105_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
@@ -1153,7 +1153,7 @@ issue_2105_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
properties: true,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
|
||||
@@ -513,7 +513,7 @@ issue_2428: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
|
||||
@@ -3714,6 +3714,7 @@ recursive_inlining_2: {
|
||||
|
||||
recursive_inlining_3: {
|
||||
options = {
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
@@ -3989,3 +3990,38 @@ issue_2450_5: {
|
||||
"true",
|
||||
]
|
||||
}
|
||||
|
||||
issue_2449: {
|
||||
options = {
|
||||
passes: 10,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
function g() {
|
||||
return f();
|
||||
}
|
||||
(function() {
|
||||
var a = "FAIL";
|
||||
if (a == a) console.log(g());
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function g() {
|
||||
return function() {
|
||||
return a;
|
||||
}();
|
||||
}
|
||||
(function() {
|
||||
var a = "FAIL";
|
||||
if (a == a) console.log(g());
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user