diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-25 01:57:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-25 01:57:11 +0800 |
commit | cb6a92892f9a5d66d36c766213c19e274efb9796 (patch) | |
tree | 7f6376c0bed7b1625f5374ffb12d8a6997c77458 | |
parent | f1556cb9451e9532896f9e553087c9ce83801170 (diff) | |
download | tracifyjs-cb6a92892f9a5d66d36c766213c19e274efb9796.tar.gz tracifyjs-cb6a92892f9a5d66d36c766213c19e274efb9796.zip |
fix infinite loop during `inline` (#2645)
fixes #2644
-rw-r--r-- | lib/compress.js | 14 | ||||
-rw-r--r-- | test/compress/functions.js | 24 |
2 files changed, 30 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js index 315a18c7..cc360950 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 07147663..02b4ab39 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: {} +} |