fix corner case in arguments (#4293)

fixes #4291
This commit is contained in:
Alex Lam S.L
2020-11-18 00:54:58 +00:00
committed by GitHub
parent 0bedd031da
commit aff842f2f9
3 changed files with 27 additions and 2 deletions

View File

@@ -9575,7 +9575,8 @@ merge(Compressor.prototype, {
&& expr instanceof AST_SymbolRef && expr instanceof AST_SymbolRef
&& is_arguments(def = expr.definition()) && is_arguments(def = expr.definition())
&& prop instanceof AST_Number && prop instanceof AST_Number
&& (fn = expr.scope.resolve()) === find_lambda()) { && (fn = expr.scope.resolve()) === find_lambda()
&& fn.uses_arguments !== "d") {
var index = prop.value; var index = prop.value;
if (parent instanceof AST_UnaryPrefix && parent.operator == "delete") { if (parent instanceof AST_UnaryPrefix && parent.operator == "delete") {
if (!def.deleted) def.deleted = []; if (!def.deleted) def.deleted = [];

View File

@@ -235,7 +235,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
if (!sym) { if (!sym) {
sym = self.def_global(node); sym = self.def_global(node);
} else if (name == "arguments" && sym.scope instanceof AST_Lambda) { } else if (name == "arguments" && sym.scope instanceof AST_Lambda) {
sym.scope.uses_arguments = true; if (!(tw.parent() instanceof AST_PropAccess)) {
sym.scope.uses_arguments = "d";
} else if (!sym.scope.uses_arguments) {
sym.scope.uses_arguments = true;
}
} }
if (name == "eval") { if (name == "eval") {
var parent = tw.parent(); var parent = tw.parent();

View File

@@ -807,3 +807,23 @@ issue_4200: {
} }
expect_stdout: "undefined" expect_stdout: "undefined"
} }
issue_4291: {
options = {
arguments: true,
keep_fargs: "strict",
}
input: {
console.log(function() {
arguments[0] = "PASS";
return arguments;
}()[0]);
}
expect: {
console.log(function() {
arguments[0] = "PASS";
return arguments;
}()[0]);
}
expect_stdout: "PASS"
}