Merge branch 'master' into harmony-v3.1.0

This commit is contained in:
alexlamsl
2017-09-10 15:39:33 +08:00
8 changed files with 258 additions and 47 deletions

View File

@@ -730,7 +730,7 @@ merge(Compressor.prototype, {
return node instanceof AST_SymbolRef && node.definition().undeclared;
}
var global_names = makePredicate("Array Boolean console Error Function Math Number RegExp Object String");
var global_names = makePredicate("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError");
AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
return !this.definition().undeclared
|| compressor.option("unsafe") && global_names(this.name);
@@ -927,7 +927,7 @@ merge(Compressor.prototype, {
}
} else {
var arg = iife.args[i];
if (!arg) arg = make_node(AST_Undefined, sym);
if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor);
else if (has_overlapping_symbol(fn, arg)) arg = null;
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
name: sym,
@@ -2081,16 +2081,27 @@ merge(Compressor.prototype, {
if (!compressor.option("side_effects")) return false;
if (this.pure !== undefined) return this.pure;
var pure = false;
var comments, last_comment;
var comments, pure_comment;
if (this.start
&& (comments = this.start.comments_before)
&& comments.length
&& /[@#]__PURE__/.test((last_comment = comments[comments.length - 1]).value)) {
pure = last_comment;
&& (pure_comment = find_if(function (comment) {
return /[@#]__PURE__/.test(comment.value);
}, comments))) {
pure = pure_comment;
}
return this.pure = pure;
});
var global_pure_fns = makePredicate("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError");
AST_Call.DEFMETHOD("is_expr_pure", function(compressor) {
if (compressor.option("unsafe")) {
var expr = this.expression;
if (is_undeclared_ref(expr) && global_pure_fns(expr.name)) return true;
}
return this.has_pure_annotation(compressor) || !compressor.pure_funcs(this);
});
// determine if expression has side effects
(function(def){
def(AST_Node, return_true);
@@ -2100,7 +2111,7 @@ merge(Compressor.prototype, {
def(AST_This, return_false);
def(AST_Call, function(compressor){
if (!this.has_pure_annotation(compressor) && compressor.pure_funcs(this)) return true;
if (!this.is_expr_pure(compressor)) return true;
for (var i = this.args.length; --i >= 0;) {
if (this.args[i].has_side_effects(compressor))
return true;
@@ -2570,17 +2581,18 @@ merge(Compressor.prototype, {
// We fix it at this stage by moving the `var` outside the `for`.
if (node instanceof AST_For) {
descend(node, this);
var block;
if (node.init instanceof AST_BlockStatement) {
var block = node.init;
block = node.init;
node.init = block.body.pop();
block.body.push(node);
return in_list ? MAP.splice(block.body) : block;
} else if (node.init instanceof AST_SimpleStatement) {
}
if (node.init instanceof AST_SimpleStatement) {
node.init = node.init.body;
} else if (is_empty(node.init)) {
node.init = null;
}
return node;
return !block ? node : in_list ? MAP.splice(block.body) : block;
}
if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) {
descend(node, this);
@@ -2776,7 +2788,7 @@ merge(Compressor.prototype, {
def(AST_Constant, return_null);
def(AST_This, return_null);
def(AST_Call, function(compressor, first_in_statement){
if (!this.has_pure_annotation(compressor) && compressor.pure_funcs(this)) {
if (!this.is_expr_pure(compressor)) {
if (is_func_expr(this.expression)
&& (!this.expression.name || !this.expression.name.definition().references.length)) {
var node = this.clone();
@@ -3286,6 +3298,7 @@ merge(Compressor.prototype, {
});
a.push(var_);
}
remove(def.name.definition().orig, def.name);
return a;
}, []);
if (assignments.length == 0) return null;