Skip to content

Commit

Permalink
harmony-v3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Dec 25, 2017
2 parents 49ce573 + a3b8dec commit a53784e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
16 changes: 7 additions & 9 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -4268,10 +4268,9 @@ 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) {
Expand All @@ -4288,10 +4287,10 @@ merge(Compressor.prototype, {
&& !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;) {
Expand Down Expand Up @@ -4325,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
}));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
"author": "Mihai Bazon <[email protected]> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "3.3.0",
"version": "3.3.1",
"engines": {
"node": ">=0.8.0"
},
Expand Down
1 change: 1 addition & 0 deletions test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,3 +1548,27 @@ issue_2647_3: {
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: {}
}

0 comments on commit a53784e

Please sign in to comment.