From cb6a92892f9a5d66d36c766213c19e274efb9796 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 25 Dec 2017 01:57:11 +0800 Subject: [PATCH 1/3] fix infinite loop during `inline` (#2645) fixes #2644 --- lib/compress.js | 14 ++++++-------- test/compress/functions.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 315a18c7177..cc360950fcf 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3934,7 +3934,7 @@ merge(Compressor.prototype, { } } if (fn instanceof AST_Function) { - var def, scope, value; + var def, value, scope, level = -1; if (compressor.option("inline") && !fn.uses_arguments && !fn.uses_eval @@ -3946,7 +3946,7 @@ 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); expressions.push(value.clone(true)); @@ -3981,10 +3981,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) { @@ -3998,10 +3997,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;) { @@ -4035,8 +4034,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 })); diff --git a/test/compress/functions.js b/test/compress/functions.js index 07147663e1b..02b4ab39991 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -1423,3 +1423,27 @@ issue_2630_5: { } expect_stdout: "155" } + +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: {} +} From 1476c78b53e760507a56189dfbdf82f8c07483f8 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 25 Dec 2017 03:07:46 +0800 Subject: [PATCH 2/3] add `html-minifier` to benchmarks (#2646) --- lib/compress.js | 2 +- test/benchmark.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index cc360950fcf..8cfb56be5c5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3948,7 +3948,7 @@ merge(Compressor.prototype, { && !fn.contains_this() && 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); } diff --git a/test/benchmark.js b/test/benchmark.js index 8b20ec13c78..593836061dd 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -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; From 8701a99a158d8f041b6956822b632258b40ba68e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 25 Dec 2017 03:08:28 +0800 Subject: [PATCH 3/3] v3.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f42ac272026..a7db0af577e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.3.0", + "version": "3.3.1", "engines": { "node": ">=0.8.0" },