fix variable scope determination (#3449)

fixes #3444
This commit is contained in:
Alex Lam S.L
2019-10-06 05:13:44 +08:00
committed by GitHub
parent bde7418ce1
commit a31c477fea
2 changed files with 36 additions and 3 deletions

View File

@@ -3399,16 +3399,22 @@ merge(Compressor.prototype, {
def(AST_Lambda, function(scope) {
var self = this;
var result = true;
self.walk(new TreeWalker(function(node) {
var inner_scopes = [];
self.walk(new TreeWalker(function(node, descend) {
if (!result) return true;
if (node instanceof AST_Scope && node !== self) {
inner_scopes.push(node);
descend();
inner_scopes.pop();
return true;
}
if (node instanceof AST_SymbolRef) {
if (self.inlined) {
result = false;
return true;
}
var def = node.definition();
if (member(def, self.enclosed)
&& !self.variables.has(def.name)) {
if (!self.variables.has(def.name) && !member(def.scope, inner_scopes)) {
if (scope) {
var scope_def = scope.find_variable(node);
if (def.undeclared ? !scope_def : scope_def === def) {