fix corner case in functions (#5035)

fixes #5034
This commit is contained in:
Alex Lam S.L
2021-06-24 12:43:46 +01:00
committed by GitHub
parent 82772ccb12
commit 1a064b6e74
3 changed files with 82 additions and 3 deletions

View File

@@ -6562,10 +6562,25 @@ merge(Compressor.prototype, {
if (def.orig.length > 1) return null;
if (def.assignments > 0) return false;
if (def.name == name) return def;
if (name == "await" && is_async(fn)) return false;
if (name == "yield" && is_generator(fn)) return false;
var forbidden;
switch (name) {
case "await":
forbidden = is_async;
break;
case "yield":
forbidden = is_generator;
break;
}
return all(def.references, function(ref) {
return ref.scope.find_variable(name) === sym;
var scope = ref.scope;
if (scope.find_variable(name) !== sym) return false;
if (forbidden) {
scope = scope.resolve();
do {
if (forbidden(scope)) return false;
} while ((scope = scope.parent_scope.resolve()) && scope !== fn);
}
return true;
}) && def;
}

View File

@@ -1989,3 +1989,37 @@ issue_5032_webkit: {
]
node_version: ">=8"
}
issue_5034: {
options = {
functions: true,
reduce_vars: true,
unused: true,
}
input: {
(function() {
var await = function f() {
return async function() {
return f;
};
};
await()().then(function(value) {
console.log(value === await ? "PASS" : "FAIL");
});
})();
}
expect: {
(function() {
var await = function f() {
return async function() {
return f;
};
};
await()().then(function(value) {
console.log(value === await ? "PASS" : "FAIL");
});
})();
}
expect_stdout: "PASS"
node_version: ">=8"
}

View File

@@ -1216,3 +1216,33 @@ issue_5032_webkit: {
]
node_version: ">=4"
}
issue_5034: {
options = {
functions: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function() {
var yield = function f() {
return function*() {
return f;
};
};
return yield()().next().value === yield;
}() ? "PASS" : "FAIL");
}
expect: {
console.log(function() {
var yield = function f() {
return function*() {
return f;
};
};
return yield()().next().value === yield;
}() ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=4"
}