Update dependencies
This commit is contained in:
parent
1b38ef7002
commit
6a7b019026
952 changed files with 3721 additions and 8653 deletions
144
node_modules/uglify-js/lib/compress.js
generated
vendored
144
node_modules/uglify-js/lib/compress.js
generated
vendored
|
@ -501,6 +501,23 @@ Compressor.prototype.compress = function(node) {
|
|||
if (parent instanceof AST_VarDef) return parent.value === node;
|
||||
}
|
||||
|
||||
function make_ref(ref, fixed) {
|
||||
var node = make_node(AST_SymbolRef, ref);
|
||||
node.fixed = fixed || make_node(AST_Undefined, ref);
|
||||
return node;
|
||||
}
|
||||
|
||||
function replace_ref(resolve, fixed) {
|
||||
return function(node) {
|
||||
var ref = resolve(node);
|
||||
var node = make_ref(ref, fixed);
|
||||
var def = ref.definition();
|
||||
def.references.push(node);
|
||||
def.replaced++;
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
var RE_POSITIVE_INTEGER = /^(0|[1-9][0-9]*)$/;
|
||||
(function(def) {
|
||||
def(AST_Node, noop);
|
||||
|
@ -705,22 +722,6 @@ Compressor.prototype.compress = function(node) {
|
|||
});
|
||||
}
|
||||
|
||||
function make_ref(ref, fixed) {
|
||||
var node = make_node(AST_SymbolRef, ref);
|
||||
node.fixed = fixed || make_node(AST_Undefined, ref);
|
||||
return node;
|
||||
}
|
||||
|
||||
function replace_ref(ref, fixed) {
|
||||
return function() {
|
||||
var node = make_ref(ref, fixed);
|
||||
var def = ref.definition();
|
||||
def.references.push(node);
|
||||
def.replaced++;
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
function ref_once(compressor, def) {
|
||||
return compressor.option("unused")
|
||||
&& !def.scope.pinned()
|
||||
|
@ -1021,7 +1022,9 @@ Compressor.prototype.compress = function(node) {
|
|||
};
|
||||
left.fixed.assigns = !fixed || !fixed.assigns ? [ ld.orig[0] ] : fixed.assigns.slice();
|
||||
left.fixed.assigns.push(node);
|
||||
left.fixed.to_binary = replace_ref(left, fixed);
|
||||
left.fixed.to_binary = replace_ref(function(node) {
|
||||
return node.left;
|
||||
}, fixed);
|
||||
} else {
|
||||
left.walk(tw);
|
||||
ld.fixed = false;
|
||||
|
@ -1529,7 +1532,9 @@ Compressor.prototype.compress = function(node) {
|
|||
});
|
||||
};
|
||||
exp.fixed.assigns = fixed && fixed.assigns;
|
||||
exp.fixed.to_prefix = replace_ref(exp, d.fixed);
|
||||
exp.fixed.to_prefix = replace_ref(function(node) {
|
||||
return node.expression;
|
||||
}, d.fixed);
|
||||
}
|
||||
} else {
|
||||
exp.walk(tw);
|
||||
|
@ -2156,7 +2161,7 @@ Compressor.prototype.compress = function(node) {
|
|||
abort = true;
|
||||
folded = make_node(AST_Binary, candidate, {
|
||||
operator: compound,
|
||||
left: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_binary() : lhs,
|
||||
left: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_binary(candidate) : lhs,
|
||||
right: rvalue,
|
||||
});
|
||||
}
|
||||
|
@ -2220,7 +2225,7 @@ Compressor.prototype.compress = function(node) {
|
|||
}
|
||||
if (candidate instanceof AST_UnaryPostfix) return make_node(AST_UnaryPrefix, candidate, {
|
||||
operator: candidate.operator,
|
||||
expression: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_prefix() : lhs,
|
||||
expression: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_prefix(candidate) : lhs,
|
||||
});
|
||||
if (candidate instanceof AST_UnaryPrefix) {
|
||||
clear_write_only(candidate);
|
||||
|
@ -3536,7 +3541,7 @@ Compressor.prototype.compress = function(node) {
|
|||
var declare_only, jump, merge_jump;
|
||||
var in_iife = in_lambda && parent && parent.TYPE == "Call" && parent.expression === self;
|
||||
var chain_if_returns = in_lambda && compressor.option("conditionals") && compressor.option("sequences");
|
||||
var drop_return_void = !(in_try && in_try.bfinally && in_async_generator(in_lambda));
|
||||
var drop_return_void = !(in_try && in_try.bfinally && in_async_generator(scope));
|
||||
var multiple_if_returns = has_multiple_if_returns(statements);
|
||||
for (var i = statements.length; --i >= 0;) {
|
||||
var stat = statements[i];
|
||||
|
@ -6662,15 +6667,15 @@ Compressor.prototype.compress = function(node) {
|
|||
do {
|
||||
var head = first.shift();
|
||||
if (tail.index > head.index) continue;
|
||||
var id = head.definition.id;
|
||||
if (!(id in prev)) continue;
|
||||
var head_refs = references[id];
|
||||
var prev_def = head.definition;
|
||||
if (!(prev_def.id in prev)) continue;
|
||||
var head_refs = references[prev_def.id];
|
||||
if (!head_refs) continue;
|
||||
if (head_refs.start.block !== tail_refs.start.block
|
||||
|| !mergeable(head_refs, tail_refs)
|
||||
|| (head_refs.start.loop || !same_scope(def)) && !mergeable(tail_refs, head_refs)
|
||||
|| compressor.option("webkit") && is_funarg(def) !== is_funarg(head.definition)
|
||||
|| head.definition.const_redefs
|
||||
|| compressor.option("webkit") && is_funarg(def) !== is_funarg(prev_def)
|
||||
|| prev_def.const_redefs
|
||||
|| !all(head_refs.scopes, function(scope) {
|
||||
return scope.find_variable(def.name) === def;
|
||||
})) {
|
||||
|
@ -6682,12 +6687,14 @@ Compressor.prototype.compress = function(node) {
|
|||
sym.name = def.name;
|
||||
if (sym instanceof AST_SymbolRef) {
|
||||
def.references.push(sym);
|
||||
prev_def.replaced++;
|
||||
} else {
|
||||
def.orig.push(sym);
|
||||
prev_def.eliminated++;
|
||||
}
|
||||
});
|
||||
if (!head.definition.fixed) def.fixed = false;
|
||||
merged[id] = def;
|
||||
if (!prev_def.fixed) def.fixed = false;
|
||||
merged[prev_def.id] = def;
|
||||
changed = true;
|
||||
break;
|
||||
} while (first.length);
|
||||
|
@ -7263,6 +7270,7 @@ Compressor.prototype.compress = function(node) {
|
|||
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
|
||||
}
|
||||
}
|
||||
descend_scope();
|
||||
if (node instanceof AST_LambdaExpression && node.name && drop_fn_name(node.name.definition())) {
|
||||
node.name = null;
|
||||
}
|
||||
|
@ -7357,6 +7365,7 @@ Compressor.prototype.compress = function(node) {
|
|||
}
|
||||
fns_with_marked_args.push(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
if (node instanceof AST_Catch && node.argname instanceof AST_Destructured) {
|
||||
node.argname.transform(trimmer);
|
||||
|
@ -8823,7 +8832,8 @@ Compressor.prototype.compress = function(node) {
|
|||
var negated = node.clone();
|
||||
negated.operator = op == "&&" ? "||" : "&&";
|
||||
negated.left = left.negate(compressor, first_in_statement);
|
||||
if (negated.operator == negated.right.operator) swap_chain(negated);
|
||||
var negated_rhs = negated.right.tail_node();
|
||||
if (negated_rhs instanceof AST_Binary && negated.operator == negated_rhs.operator) swap_chain(negated);
|
||||
var best = first_in_statement ? best_of_statement : best_of_expression;
|
||||
return op == "&&" ? best(node, negated) : best(negated, node);
|
||||
}
|
||||
|
@ -11607,7 +11617,14 @@ Compressor.prototype.compress = function(node) {
|
|||
}
|
||||
|
||||
function swap_chain(self, compressor) {
|
||||
var rhs = self.right;
|
||||
var rhs = self.right.tail_node();
|
||||
if (rhs !== self.right) {
|
||||
var exprs = self.right.expressions.slice(0, -1);
|
||||
exprs.push(rhs.left);
|
||||
rhs = rhs.clone();
|
||||
rhs.left = make_sequence(self.right, exprs);
|
||||
self.right = rhs;
|
||||
}
|
||||
self.left = make_node(AST_Binary, self, {
|
||||
operator: self.operator,
|
||||
left: self.left,
|
||||
|
@ -11799,15 +11816,16 @@ Compressor.prototype.compress = function(node) {
|
|||
left: self.left.right,
|
||||
right: self.right,
|
||||
});
|
||||
var after = before.optimize(compressor);
|
||||
var after = before.transform(compressor);
|
||||
if (before !== after) {
|
||||
self.left = self.left.left;
|
||||
self.right = after;
|
||||
}
|
||||
}
|
||||
// x && (y && z) ---> x && y && z
|
||||
// x || (y || z) ---> x || y || z
|
||||
if (self.right instanceof AST_Binary && self.operator == self.right.operator) swap_chain(self, compressor);
|
||||
// w || (x, y || z) ---> w || (x, y) || z
|
||||
var rhs = self.right.tail_node();
|
||||
if (rhs instanceof AST_Binary && self.operator == rhs.operator) swap_chain(self, compressor);
|
||||
}
|
||||
if (compressor.option("strings") && self.operator == "+") {
|
||||
// "foo" + 42 + "" ---> "foo" + 42
|
||||
|
@ -11833,12 +11851,13 @@ Compressor.prototype.compress = function(node) {
|
|||
return self.optimize(compressor);
|
||||
}
|
||||
// "x" + (y + "z") ---> "x" + y + "z"
|
||||
// x + ("y" + z) ---> x + "y" + z
|
||||
if (self.right instanceof AST_Binary
|
||||
&& self.operator == self.right.operator
|
||||
&& (self.left.is_string(compressor) && self.right.is_string(compressor)
|
||||
|| self.right.left.is_string(compressor)
|
||||
&& (self.left.is_constant() || !self.right.right.has_side_effects(compressor)))) {
|
||||
// w + (x, "y" + z) ---> w + (x, "y") + z
|
||||
var rhs = self.right.tail_node();
|
||||
if (rhs instanceof AST_Binary
|
||||
&& self.operator == rhs.operator
|
||||
&& (self.left.is_string(compressor) && rhs.is_string(compressor)
|
||||
|| rhs.left.is_string(compressor)
|
||||
&& (self.left.is_constant() || !rhs.right.has_side_effects(compressor)))) {
|
||||
swap_chain(self, compressor);
|
||||
}
|
||||
}
|
||||
|
@ -12766,34 +12785,19 @@ Compressor.prototype.compress = function(node) {
|
|||
}
|
||||
if (compressor.option("assignments")) {
|
||||
if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) {
|
||||
var ref;
|
||||
// x = expr1 OP expr2
|
||||
if ((ref = self.right.left) instanceof AST_SymbolRef
|
||||
&& ref.name == self.left.name
|
||||
if (self.right.left instanceof AST_SymbolRef
|
||||
&& self.right.left.name == self.left.name
|
||||
&& ASSIGN_OPS[self.right.operator]) {
|
||||
// x = x - 2 ---> x -= 2
|
||||
if (self.left.fixed) self.left.fixed.to_binary = function() {
|
||||
return ref;
|
||||
};
|
||||
return make_node(AST_Assign, self, {
|
||||
operator: self.right.operator + "=",
|
||||
left: self.left,
|
||||
right: self.right.right,
|
||||
});
|
||||
return make_compound(self.right.right);
|
||||
}
|
||||
if ((ref = self.right.right) instanceof AST_SymbolRef
|
||||
&& ref.name == self.left.name
|
||||
if (self.right.right instanceof AST_SymbolRef
|
||||
&& self.right.right.name == self.left.name
|
||||
&& ASSIGN_OPS_COMMUTATIVE[self.right.operator]
|
||||
&& !self.right.left.has_side_effects(compressor)) {
|
||||
// x = 2 & x ---> x &= 2
|
||||
if (self.left.fixed) self.left.fixed.to_binary = function() {
|
||||
return ref;
|
||||
};
|
||||
return make_node(AST_Assign, self, {
|
||||
operator: self.right.operator + "=",
|
||||
left: self.left,
|
||||
right: self.right.left,
|
||||
});
|
||||
return make_compound(self.right.left);
|
||||
}
|
||||
}
|
||||
if ((self.operator == "-=" || self.operator == "+="
|
||||
|
@ -12856,6 +12860,18 @@ Compressor.prototype.compress = function(node) {
|
|||
return find_try(compressor, level, node, scope, may_throw, sync);
|
||||
}
|
||||
|
||||
function make_compound(rhs) {
|
||||
var fixed = self.left.fixed;
|
||||
if (fixed) fixed.to_binary = replace_ref(function(node) {
|
||||
return node.left;
|
||||
}, fixed);
|
||||
return make_node(AST_Assign, self, {
|
||||
operator: self.right.operator + "=",
|
||||
left: self.left,
|
||||
right: rhs,
|
||||
});
|
||||
}
|
||||
|
||||
function strip_assignment(def) {
|
||||
if (def) def.fixed = false;
|
||||
return (self.operator != "=" ? make_node(AST_Binary, self, {
|
||||
|
@ -13101,7 +13117,7 @@ Compressor.prototype.compress = function(node) {
|
|||
operator: "||",
|
||||
left: booleanize(condition),
|
||||
right: alternative,
|
||||
});
|
||||
}).optimize(compressor);
|
||||
}
|
||||
if (is_false(consequent)) {
|
||||
// c ? false : true ---> !c
|
||||
|
@ -13111,20 +13127,20 @@ Compressor.prototype.compress = function(node) {
|
|||
operator: "&&",
|
||||
left: booleanize(condition.negate(compressor)),
|
||||
right: alternative,
|
||||
});
|
||||
}).optimize(compressor);
|
||||
}
|
||||
// c ? x : true ---> !c || x
|
||||
if (is_true(alternative)) return make_node(AST_Binary, self, {
|
||||
operator: "||",
|
||||
left: booleanize(condition.negate(compressor)),
|
||||
right: consequent,
|
||||
});
|
||||
}).optimize(compressor);
|
||||
// c ? x : false ---> !!c && x
|
||||
if (is_false(alternative)) return make_node(AST_Binary, self, {
|
||||
operator: "&&",
|
||||
left: booleanize(condition),
|
||||
right: consequent,
|
||||
});
|
||||
}).optimize(compressor);
|
||||
if (compressor.option("typeofs")) mark_locally_defined(condition, consequent, alternative);
|
||||
return self;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue