fix pre-existing issues
- reference counting on assignment - walking of anonymous functions
This commit is contained in:
parent
9dc5247bc7
commit
79d533a560
|
|
@ -298,6 +298,7 @@ merge(Compressor.prototype, {
|
|||
&& node.left instanceof AST_SymbolRef) {
|
||||
var d = node.left.definition();
|
||||
if (HOP(safe_ids, d.id) && safe_to_assign(d, node.right)) {
|
||||
d.references.push(node.left);
|
||||
d.fixed = function() {
|
||||
return node.right;
|
||||
};
|
||||
|
|
@ -321,13 +322,11 @@ merge(Compressor.prototype, {
|
|||
safe_ids = save_ids;
|
||||
return true;
|
||||
}
|
||||
var iife;
|
||||
if (node instanceof AST_Function
|
||||
&& (iife = tw.parent()) instanceof AST_Call
|
||||
&& iife.expression === node) {
|
||||
if (node.name) {
|
||||
node.name.definition().fixed = node;
|
||||
} else {
|
||||
if (node instanceof AST_Function) {
|
||||
var iife;
|
||||
if (!node.name
|
||||
&& (iife = tw.parent()) instanceof AST_Call
|
||||
&& iife.expression === node) {
|
||||
// Virtually turn IIFE parameters into variable definitions:
|
||||
// (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})()
|
||||
// So existing transformation rules can work on them.
|
||||
|
|
@ -339,6 +338,10 @@ merge(Compressor.prototype, {
|
|||
mark(d, true);
|
||||
});
|
||||
}
|
||||
push();
|
||||
descend();
|
||||
pop();
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Binary
|
||||
&& (node.operator == "&&" || node.operator == "||")) {
|
||||
|
|
|
|||
|
|
@ -1592,3 +1592,25 @@ var_side_effects_3: {
|
|||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
reduce_vars_assign: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a = 1;
|
||||
a = [].length,
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var a = 1;
|
||||
a = [].length,
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2258,3 +2258,34 @@ cond_assign: {
|
|||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
iife_assign: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a = 1, b = 0;
|
||||
!function() {
|
||||
b++;
|
||||
return;
|
||||
a = 2;
|
||||
}();
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var a = 1, b = 0;
|
||||
!function() {
|
||||
b++;
|
||||
return;
|
||||
a = 2;
|
||||
}();
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user