updated npm modules
This commit is contained in:
117
node_modules/uglify-js/lib/compress.js
generated
vendored
117
node_modules/uglify-js/lib/compress.js
generated
vendored
@@ -106,10 +106,16 @@ function Compressor(options, false_by_default) {
|
||||
var pure_funcs = this.options["pure_funcs"];
|
||||
if (typeof pure_funcs == "function") {
|
||||
this.pure_funcs = pure_funcs;
|
||||
} else {
|
||||
this.pure_funcs = pure_funcs ? function(node) {
|
||||
} else if (typeof pure_funcs == "string") {
|
||||
this.pure_funcs = function(node) {
|
||||
return pure_funcs !== node.expression.print_to_string();
|
||||
};
|
||||
} else if (Array.isArray(pure_funcs)) {
|
||||
this.pure_funcs = function(node) {
|
||||
return pure_funcs.indexOf(node.expression.print_to_string()) < 0;
|
||||
} : return_true;
|
||||
};
|
||||
} else {
|
||||
this.pure_funcs = return_true;
|
||||
}
|
||||
var top_retain = this.options["top_retain"];
|
||||
if (top_retain instanceof RegExp) {
|
||||
@@ -497,6 +503,15 @@ merge(Compressor.prototype, {
|
||||
d.direct_access = true;
|
||||
}
|
||||
|
||||
function mark_assignment_to_arguments(node) {
|
||||
if (!(node instanceof AST_Sub)) return;
|
||||
var expr = node.expression;
|
||||
var prop = node.property;
|
||||
if (expr instanceof AST_SymbolRef && expr.name == "arguments" && prop instanceof AST_Number) {
|
||||
expr.definition().reassigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
var suppressor = new TreeWalker(function(node) {
|
||||
if (!(node instanceof AST_Symbol)) return;
|
||||
var d = node.definition();
|
||||
@@ -515,7 +530,10 @@ merge(Compressor.prototype, {
|
||||
def(AST_Assign, function(tw, descend, compressor) {
|
||||
var node = this;
|
||||
var sym = node.left;
|
||||
if (!(sym instanceof AST_SymbolRef)) return;
|
||||
if (!(sym instanceof AST_SymbolRef)) {
|
||||
mark_assignment_to_arguments(sym);
|
||||
return;
|
||||
}
|
||||
var d = sym.definition();
|
||||
var safe = safe_to_assign(tw, d, sym.scope, node.right);
|
||||
d.assignments++;
|
||||
@@ -758,7 +776,10 @@ merge(Compressor.prototype, {
|
||||
var node = this;
|
||||
if (node.operator != "++" && node.operator != "--") return;
|
||||
var exp = node.expression;
|
||||
if (!(exp instanceof AST_SymbolRef)) return;
|
||||
if (!(exp instanceof AST_SymbolRef)) {
|
||||
mark_assignment_to_arguments(exp);
|
||||
return;
|
||||
}
|
||||
var d = exp.definition();
|
||||
var safe = safe_to_assign(tw, d, exp.scope, true);
|
||||
d.assignments++;
|
||||
@@ -1570,13 +1591,19 @@ merge(Compressor.prototype, {
|
||||
var found = false;
|
||||
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
|
||||
if (found) return node;
|
||||
if (node === expr || node.body === expr) {
|
||||
if (node !== expr && node.body !== expr) return;
|
||||
if (node instanceof AST_VarDef) {
|
||||
found = true;
|
||||
if (node instanceof AST_VarDef) {
|
||||
node.value = null;
|
||||
return node;
|
||||
}
|
||||
return in_list ? MAP.skip : null;
|
||||
node.value = null;
|
||||
return node;
|
||||
}
|
||||
if (in_list) {
|
||||
found = true;
|
||||
return MAP.skip;
|
||||
}
|
||||
if (!this.parent()) {
|
||||
found = true;
|
||||
return null;
|
||||
}
|
||||
}, function(node) {
|
||||
if (node instanceof AST_Sequence) switch (node.expressions.length) {
|
||||
@@ -1616,7 +1643,7 @@ merge(Compressor.prototype, {
|
||||
function symbol_in_lvalues(sym, parent) {
|
||||
var lvalue = lvalues[sym.name];
|
||||
if (!lvalue) return;
|
||||
if (lvalue !== lhs) return !(parent instanceof AST_Call);
|
||||
if (lvalue !== lhs) return !(parent instanceof AST_Call && parent.expression === sym);
|
||||
scan_rhs = false;
|
||||
}
|
||||
|
||||
@@ -2700,19 +2727,25 @@ merge(Compressor.prototype, {
|
||||
return typeof function(){};
|
||||
}
|
||||
if (!non_converting_unary[this.operator]) depth++;
|
||||
e = e._eval(compressor, cached, depth);
|
||||
if (e === this.expression) return this;
|
||||
var v = e._eval(compressor, cached, depth);
|
||||
if (v === this.expression) return this;
|
||||
switch (this.operator) {
|
||||
case "!": return !e;
|
||||
case "!": return !v;
|
||||
case "typeof":
|
||||
// typeof <RegExp> returns "object" or "function" on different platforms
|
||||
// so cannot evaluate reliably
|
||||
if (e instanceof RegExp) return this;
|
||||
return typeof e;
|
||||
case "void": return void e;
|
||||
case "~": return ~e;
|
||||
case "-": return -e;
|
||||
case "+": return +e;
|
||||
if (v instanceof RegExp) return this;
|
||||
return typeof v;
|
||||
case "void": return void v;
|
||||
case "~": return ~v;
|
||||
case "-": return -v;
|
||||
case "+": return +v;
|
||||
case "++":
|
||||
case "--":
|
||||
if (e instanceof AST_SymbolRef) {
|
||||
var refs = e.definition().references;
|
||||
if (refs[refs.length - 1] === e) return v;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
});
|
||||
@@ -5772,8 +5805,8 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (single_use && fixed) {
|
||||
def.single_use = false;
|
||||
fixed._squeezed = true;
|
||||
if (fixed instanceof AST_Defun) {
|
||||
fixed._squeezed = true;
|
||||
fixed = make_node(AST_Function, fixed, fixed);
|
||||
fixed.name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
|
||||
}
|
||||
@@ -5797,6 +5830,14 @@ merge(Compressor.prototype, {
|
||||
lambda_def.references.push(node);
|
||||
} else {
|
||||
def.single_use = false;
|
||||
var fn = node.fixed_value();
|
||||
if (!(fn instanceof AST_Lambda)) return;
|
||||
if (!fn.name) return;
|
||||
if (fixed.variables.get(fn.name.name) !== fn.name.definition()) return;
|
||||
fn.name = fn.name.clone();
|
||||
var value_def = value.variables.get(fn.name.name) || value.def_function(fn.name);
|
||||
node.thedef = value_def;
|
||||
value_def.references.push(node);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
@@ -6051,12 +6092,14 @@ merge(Compressor.prototype, {
|
||||
if (seq_tail instanceof AST_Assign) {
|
||||
var is_eq = seq_tail.operator == "=";
|
||||
var alt_tail = is_eq ? alternative.tail_node() : alternative;
|
||||
if ((is_eq || consequent instanceof AST_Assign)
|
||||
if ((is_eq || consequent === seq_tail)
|
||||
&& alt_tail instanceof AST_Assign
|
||||
&& seq_tail.operator == alt_tail.operator
|
||||
&& seq_tail.left.equivalent_to(alt_tail.left)
|
||||
&& (!condition.has_side_effects(compressor)
|
||||
|| is_eq && !seq_tail.left.has_side_effects(compressor))) {
|
||||
&& (is_eq && !seq_tail.left.has_side_effects(compressor)
|
||||
|| !condition.has_side_effects(compressor)
|
||||
&& can_shift_lhs_of_tail(consequent)
|
||||
&& can_shift_lhs_of_tail(alternative))) {
|
||||
return make_node(AST_Assign, self, {
|
||||
operator: seq_tail.operator,
|
||||
left: seq_tail.left,
|
||||
@@ -6221,6 +6264,19 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
function can_shift_lhs_of_tail(node) {
|
||||
if (node === node.tail_node()) return true;
|
||||
var exprs = node.expressions;
|
||||
for (var i = exprs.length - 1; --i >= 0;) {
|
||||
var expr = exprs[i];
|
||||
if (!(expr instanceof AST_Assign) && expr.has_side_effects(compressor)
|
||||
|| expr.operator != "="
|
||||
|| expr.left.has_side_effects(compressor)
|
||||
|| expr.right.has_side_effects(compressor)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function pop_lhs(node) {
|
||||
if (!(node instanceof AST_Sequence)) return node.right;
|
||||
var exprs = node.expressions.slice();
|
||||
@@ -6304,13 +6360,16 @@ merge(Compressor.prototype, {
|
||||
&& expr instanceof AST_SymbolRef
|
||||
&& expr.name == "arguments"
|
||||
&& expr.definition().orig.length == 1
|
||||
&& (fn = expr.scope) instanceof AST_Lambda
|
||||
&& prop instanceof AST_Number) {
|
||||
&& prop instanceof AST_Number
|
||||
&& (fn = expr.scope) === compressor.find_parent(AST_Lambda)) {
|
||||
var index = prop.getValue();
|
||||
var argname = fn.argnames[index];
|
||||
if (argname && compressor.has_directive("use strict")) {
|
||||
var def = argname.definition();
|
||||
if (!compressor.option("reduce_vars") || def.assignments || def.orig.length > 1) {
|
||||
if (!compressor.option("reduce_vars")
|
||||
|| expr.definition().reassigned
|
||||
|| def.assignments
|
||||
|| def.orig.length > 1) {
|
||||
argname = null;
|
||||
}
|
||||
} else if (!argname && !compressor.option("keep_fargs") && index < fn.argnames.length + 5) {
|
||||
@@ -6423,7 +6482,7 @@ merge(Compressor.prototype, {
|
||||
|
||||
OPT(AST_Dot, function(self, compressor) {
|
||||
if (self.property == "arguments" || self.property == "caller") {
|
||||
compressor.warn("Function.protoype.{prop} not supported [{file}:{line},{col}]", {
|
||||
compressor.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]", {
|
||||
prop: self.property,
|
||||
file: self.start.file,
|
||||
line: self.start.line,
|
||||
|
||||
29
node_modules/uglify-js/lib/parse.js
generated
vendored
29
node_modules/uglify-js/lib/parse.js
generated
vendored
@@ -758,17 +758,21 @@ function parse($TEXT, options) {
|
||||
croak(msg, token.line, token.col);
|
||||
}
|
||||
|
||||
function token_to_string(type, value) {
|
||||
return type + (value === undefined ? "" : " «" + value + "»");
|
||||
}
|
||||
|
||||
function unexpected(token) {
|
||||
if (token == null)
|
||||
token = S.token;
|
||||
token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
|
||||
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||
}
|
||||
|
||||
function expect_token(type, val) {
|
||||
if (is(type, val)) {
|
||||
return next();
|
||||
}
|
||||
token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
||||
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||
}
|
||||
|
||||
function expect(punc) {
|
||||
@@ -788,7 +792,7 @@ function parse($TEXT, options) {
|
||||
|
||||
function semicolon(optional) {
|
||||
if (is("punc", ";")) next();
|
||||
else if (!optional && !can_insert_semicolon()) unexpected();
|
||||
else if (!optional && !can_insert_semicolon()) expect_token("punc", ";");
|
||||
}
|
||||
|
||||
function parenthesised() {
|
||||
@@ -1069,7 +1073,7 @@ function parse($TEXT, options) {
|
||||
var in_statement = ctor === AST_Defun;
|
||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||
if (in_statement && !name)
|
||||
unexpected();
|
||||
expect_token("name");
|
||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||
unexpected(prev());
|
||||
expect("(");
|
||||
@@ -1119,7 +1123,7 @@ function parse($TEXT, options) {
|
||||
expect("{");
|
||||
var a = [];
|
||||
while (!is("punc", "}")) {
|
||||
if (is("eof")) unexpected();
|
||||
if (is("eof")) expect_token("punc", "}");
|
||||
a.push(statement(strict_defun));
|
||||
}
|
||||
next();
|
||||
@@ -1130,7 +1134,7 @@ function parse($TEXT, options) {
|
||||
expect("{");
|
||||
var a = [], cur = null, branch = null, tmp;
|
||||
while (!is("punc", "}")) {
|
||||
if (is("eof")) unexpected();
|
||||
if (is("eof")) expect_token("punc", "}");
|
||||
if (is("keyword", "case")) {
|
||||
if (branch) branch.end = prev();
|
||||
cur = [];
|
||||
@@ -1141,8 +1145,7 @@ function parse($TEXT, options) {
|
||||
});
|
||||
a.push(branch);
|
||||
expect(":");
|
||||
}
|
||||
else if (is("keyword", "default")) {
|
||||
} else if (is("keyword", "default")) {
|
||||
if (branch) branch.end = prev();
|
||||
cur = [];
|
||||
branch = new AST_Default({
|
||||
@@ -1150,8 +1153,7 @@ function parse($TEXT, options) {
|
||||
body : cur
|
||||
});
|
||||
a.push(branch);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!cur) unexpected();
|
||||
cur.push(statement());
|
||||
}
|
||||
@@ -1420,10 +1422,10 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
function as_name() {
|
||||
var tmp = S.token;
|
||||
if (tmp.type != "name") unexpected();
|
||||
if (!is("name")) expect_token("name");
|
||||
var name = S.token.value;
|
||||
next();
|
||||
return tmp.value;
|
||||
return name;
|
||||
}
|
||||
|
||||
function _make_symbol(type) {
|
||||
@@ -1625,6 +1627,7 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
if (options.expression) {
|
||||
handle_regexp();
|
||||
return expression(true);
|
||||
}
|
||||
|
||||
|
||||
4
node_modules/uglify-js/lib/scope.js
generated
vendored
4
node_modules/uglify-js/lib/scope.js
generated
vendored
@@ -309,8 +309,12 @@ function names_in_use(scope, options) {
|
||||
if (!names) {
|
||||
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
||||
scope.cname_holes = [];
|
||||
var cache = options.cache && options.cache.props;
|
||||
scope.enclosed.forEach(function(def) {
|
||||
if (def.unmangleable(options)) names[def.name] = true;
|
||||
if (def.global && cache && cache.has(def.name)) {
|
||||
names[cache.get(def.name)] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return names;
|
||||
|
||||
Reference in New Issue
Block a user