forbid AST_Await in computed function arguments (#4352)

fixes #4351
This commit is contained in:
Alex Lam S.L
2020-12-08 04:59:08 +00:00
committed by GitHub
parent 4733159782
commit fea9da9866
2 changed files with 53 additions and 6 deletions

View File

@@ -653,14 +653,15 @@ function parse($TEXT, options) {
input : typeof $TEXT == "string"
? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang)
: $TEXT,
token : null,
prev : null,
peeked : null,
in_async : false,
in_function : 0,
in_directives : true,
in_funarg : -1,
in_function : 0,
in_loop : 0,
labels : []
labels : [],
peeked : null,
prev : null,
token : null,
};
S.token = next();
@@ -1053,9 +1054,12 @@ function parse($TEXT, options) {
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
unexpected(prev());
expect("(");
var was_funarg = S.in_funarg;
S.in_funarg = S.in_function;
var argnames = expr_list(")", !options.strict, false, function() {
return maybe_destructured(AST_SymbolFunarg);
});
S.in_funarg = was_funarg;
var loop = S.in_loop;
var labels = S.labels;
++S.in_function;
@@ -1638,6 +1642,7 @@ function parse($TEXT, options) {
function maybe_await() {
var start = S.token;
if (!(S.in_async && is("name", "await"))) return maybe_unary();
if (S.in_funarg === S.in_function) croak("Invalid use of await in function argument");
S.input.context().regex_allowed = true;
next();
return new AST_Await({