fix infinite loop during inline (#2645)

fixes #2644
This commit is contained in:
Alex Lam S.L
2017-12-25 01:57:11 +08:00
committed by GitHub
parent f1556cb945
commit cb6a92892f
2 changed files with 30 additions and 8 deletions

View File

@@ -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
}));