fix corner case in inline & reduce_vars (#5579)
This commit is contained in:
@@ -8387,9 +8387,8 @@ Compressor.prototype.compress = function(node) {
|
|||||||
var scopes = [ this ];
|
var scopes = [ this ];
|
||||||
if (orig instanceof AST_SymbolDeclaration) orig.definition().references.forEach(function(ref) {
|
if (orig instanceof AST_SymbolDeclaration) orig.definition().references.forEach(function(ref) {
|
||||||
var s = ref.scope;
|
var s = ref.scope;
|
||||||
if (member(s, scopes)) return;
|
|
||||||
do {
|
do {
|
||||||
push_uniq(scopes, s);
|
if (!push_uniq(scopes, s)) return;
|
||||||
s = s.parent_scope;
|
s = s.parent_scope;
|
||||||
} while (s && s !== this);
|
} while (s && s !== this);
|
||||||
});
|
});
|
||||||
@@ -12251,12 +12250,19 @@ Compressor.prototype.compress = function(node) {
|
|||||||
if (fixed instanceof AST_DefClass) fixed = to_class_expr(fixed);
|
if (fixed instanceof AST_DefClass) fixed = to_class_expr(fixed);
|
||||||
if (fixed instanceof AST_LambdaDefinition) fixed = to_func_expr(fixed);
|
if (fixed instanceof AST_LambdaDefinition) fixed = to_func_expr(fixed);
|
||||||
if (is_lambda(fixed)) {
|
if (is_lambda(fixed)) {
|
||||||
var scope = self.scope.resolve();
|
var scopes = [];
|
||||||
|
var scope = self.scope;
|
||||||
|
do {
|
||||||
|
scopes.push(scope);
|
||||||
|
if (scope === def.scope) break;
|
||||||
|
} while (scope = scope.parent_scope);
|
||||||
fixed.enclosed.forEach(function(def) {
|
fixed.enclosed.forEach(function(def) {
|
||||||
if (fixed.variables.has(def.name)) return;
|
if (fixed.variables.has(def.name)) return;
|
||||||
if (scope.var_names().has(def.name)) return;
|
for (var i = 0; i < scopes.length; i++) {
|
||||||
scope.enclosed.push(def);
|
var scope = scopes[i];
|
||||||
scope.var_names().set(def.name, true);
|
if (!push_uniq(scope.enclosed, def)) return;
|
||||||
|
scope.var_names().set(def.name, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var value;
|
var value;
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
// ensure mangling works if `catch` reuses a scope variable
|
// ensure mangling works if `catch` reuses a scope variable
|
||||||
var redef = def.redefined();
|
var redef = def.redefined();
|
||||||
if (redef) for (var s = node.scope; s; s = s.parent_scope) {
|
if (redef) for (var s = node.scope; s; s = s.parent_scope) {
|
||||||
push_uniq(s.enclosed, redef);
|
if (!push_uniq(s.enclosed, redef)) break;
|
||||||
if (s === redef.scope) break;
|
if (s === redef.scope) break;
|
||||||
}
|
}
|
||||||
} else if (node instanceof AST_SymbolConst) {
|
} else if (node instanceof AST_SymbolConst) {
|
||||||
@@ -480,7 +480,7 @@ AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) {
|
|||||||
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
for (var s = this.scope; s; s = s.parent_scope) {
|
for (var s = this.scope; s; s = s.parent_scope) {
|
||||||
push_uniq(s.enclosed, def);
|
if (!push_uniq(s.enclosed, def)) break;
|
||||||
if (!options) {
|
if (!options) {
|
||||||
s._var_names = undefined;
|
s._var_names = undefined;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8646,3 +8646,42 @@ module_inline: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "true"
|
expect_stdout: "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
single_use_inline_collision: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
var f = function() {
|
||||||
|
while (console.log(a));
|
||||||
|
};
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
a || a("FAIL");
|
||||||
|
})(console.log);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
while (console.log(a));
|
||||||
|
return;
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
a || a("FAIL");
|
||||||
|
})(console.log);
|
||||||
|
return;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -160,6 +160,11 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
return expr instanceof U.AST_Spread ? expr.expression : expr;
|
return expr instanceof U.AST_Spread ? expr.expression : expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (node instanceof U.AST_Await) {
|
||||||
|
node.start._permute++;
|
||||||
|
CHANGED = true;
|
||||||
|
return node.expression;
|
||||||
|
}
|
||||||
else if (node instanceof U.AST_Binary) {
|
else if (node instanceof U.AST_Binary) {
|
||||||
var permute = ((node.start._permute += step) * steps | 0) % 4;
|
var permute = ((node.start._permute += step) * steps | 0) % 4;
|
||||||
var expr = [
|
var expr = [
|
||||||
|
|||||||
Reference in New Issue
Block a user