fix corner cases with new.target (#4784)

This commit is contained in:
Alex Lam S.L
2021-03-16 06:34:36 +00:00
committed by GitHub
parent 77c9116c91
commit 352a944868
5 changed files with 126 additions and 30 deletions

View File

@@ -1737,28 +1737,23 @@ function parse($TEXT, options) {
var new_ = function(allow_calls) {
var start = S.token;
expect_token("operator", "new");
var call;
if (is("punc", ".") && is_token(peek(), "name", "target")) {
next();
next();
return new AST_NewTarget({
name: "new.target",
start: start,
end: prev(),
});
}
var newexp = expr_atom(false), args;
if (is("punc", "(")) {
next();
args = expr_list(")", !options.strict);
call = new AST_NewTarget();
} else {
args = [];
var exp = expr_atom(false), args;
if (is("punc", "(")) {
next();
args = expr_list(")", !options.strict);
} else {
args = [];
}
call = new AST_New({ expression: exp, args: args });
}
var call = new AST_New({
start : start,
expression : newexp,
args : args,
end : prev()
});
call.start = start;
call.end = prev();
return subscripts(call, allow_calls);
};