Compare commits
6 Commits
harmony-v3
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a53784e0c5 | ||
|
|
a3b8dec347 | ||
|
|
49ce573971 | ||
|
|
8701a99a15 | ||
|
|
1476c78b53 | ||
|
|
cb6a92892f |
@@ -4220,7 +4220,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
}
|
||||
if (is_func_expr(fn) && !fn.is_generator && !fn.async) {
|
||||
var def, scope, value;
|
||||
var def, value, scope, level = -1;
|
||||
if (compressor.option("inline")
|
||||
&& simple_args
|
||||
&& !fn.uses_arguments
|
||||
@@ -4233,9 +4233,9 @@ merge(Compressor.prototype, {
|
||||
&& fn.is_constant_expression(exp.scope))
|
||||
&& !self.pure
|
||||
&& !fn.contains_this()
|
||||
&& (scope = can_flatten_args(fn))
|
||||
&& can_flatten_args(fn)
|
||||
&& (value = flatten_body(stat))) {
|
||||
var expressions = flatten_args(fn, scope);
|
||||
var expressions = flatten_args(fn);
|
||||
expressions.push(value.clone(true));
|
||||
return make_sequence(self, expressions).optimize(compressor);
|
||||
}
|
||||
@@ -4268,34 +4268,35 @@ merge(Compressor.prototype, {
|
||||
return self;
|
||||
|
||||
function can_flatten_args(fn) {
|
||||
var scope, level = 0;
|
||||
var catches = Object.create(null);
|
||||
do {
|
||||
scope = compressor.parent(level++);
|
||||
scope = compressor.parent(++level);
|
||||
if (scope instanceof AST_SymbolRef) {
|
||||
scope = scope.fixed_value();
|
||||
} else if (scope instanceof AST_Catch) {
|
||||
catches[scope.argname.name] = true;
|
||||
}
|
||||
} while (!(scope instanceof AST_Scope));
|
||||
} while (!(scope instanceof AST_Scope) || scope instanceof AST_Arrow);
|
||||
var safe_to_inject = compressor.toplevel.vars || !(scope instanceof AST_Toplevel);
|
||||
return all(fn.argnames, function(arg) {
|
||||
if (arg instanceof AST_DefaultAssign) return arg.left.__unused;
|
||||
if (arg instanceof AST_Destructuring) return false;
|
||||
if (arg instanceof AST_Expansion) return arg.expression.__unused;
|
||||
return arg.__unused
|
||||
|| safe_to_inject
|
||||
&& !catches[arg.name]
|
||||
&& !identifier_atom(arg.name)
|
||||
&& !scope.var_names()[arg.name];
|
||||
}) && scope;
|
||||
});
|
||||
}
|
||||
|
||||
function flatten_args(fn, scope) {
|
||||
function flatten_args(fn) {
|
||||
var decls = [];
|
||||
var expressions = [];
|
||||
for (var len = fn.argnames.length, i = len; --i >= 0;) {
|
||||
var name = fn.argnames[i];
|
||||
var value = self.args[i];
|
||||
if (name.__unused || name instanceof AST_Expansion) {
|
||||
if (name.__unused || !name.name) {
|
||||
if (value || expressions.length) {
|
||||
expressions.unshift(value || make_node(AST_Undefined, self));
|
||||
}
|
||||
@@ -4323,8 +4324,7 @@ merge(Compressor.prototype, {
|
||||
expressions.push(self.args[i]);
|
||||
}
|
||||
if (decls.length) {
|
||||
for (i = 0; compressor.parent(i) !== scope;) i++;
|
||||
i = scope.body.indexOf(compressor.parent(i - 1)) + 1;
|
||||
i = scope.body.indexOf(compressor.parent(level - 1)) + 1;
|
||||
scope.body.splice(i, 0, make_node(AST_Var, fn, {
|
||||
definitions: decls
|
||||
}));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.3.0",
|
||||
"version": "3.3.1",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ var urls = [
|
||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
||||
"https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js",
|
||||
];
|
||||
var results = {};
|
||||
var remaining = 2 * urls.length;
|
||||
|
||||
@@ -1456,3 +1456,119 @@ issue_2630_5: {
|
||||
}
|
||||
expect_stdout: "155"
|
||||
}
|
||||
|
||||
issue_2647_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(n, o = "FAIL") {
|
||||
console.log(n);
|
||||
})("PASS");
|
||||
(function(n, o = "PASS") {
|
||||
console.log(o);
|
||||
})("FAIL");
|
||||
(function(o = "PASS") {
|
||||
console.log(o);
|
||||
})();
|
||||
(function(n, {o = "FAIL"}) {
|
||||
console.log(n);
|
||||
})("PASS", {});
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
(function(n, o = "PASS") {
|
||||
console.log(o);
|
||||
})();
|
||||
(function(o = "PASS") {
|
||||
console.log(o);
|
||||
})();
|
||||
(function(n, {o = "FAIL"}) {
|
||||
console.log("PASS");
|
||||
})(0, {});
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_2647_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function foo(x) {
|
||||
return x.toUpperCase();
|
||||
}
|
||||
console.log((() => foo("pass"))());
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
console.log("pass".toUpperCase());
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_2647_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function foo(x) {
|
||||
return x.toUpperCase();
|
||||
}
|
||||
console.log((() => {
|
||||
return foo("pass");
|
||||
})());
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
console.log("pass".toUpperCase());
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
recursive_inline: {
|
||||
options = {
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
h();
|
||||
}
|
||||
function g(a) {
|
||||
a();
|
||||
}
|
||||
function h(b) {
|
||||
g();
|
||||
if (b) x();
|
||||
}
|
||||
}
|
||||
expect: {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user