fix(es/parser): Don't panic on an invalid import meta property (#4994)

This commit is contained in:
magic-akari 2022-06-18 18:00:52 +08:00 committed by GitHub
parent a2fa4a78e2
commit 53a8cb1209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 0 deletions

View File

@ -1155,6 +1155,10 @@ impl<I: Tokens> Parser<I> {
None
};
if obj.is_import() && !is_one_of!(self, '.', '(') {
unexpected!(self, "`.` or `(`")
}
let question_dot_token = if is!(self, '?') && peeked_is!(self, '.') {
let start = cur_pos!(self);
eat!(self, '?');

View File

@ -0,0 +1,3 @@
const str = "meta";
console.log(import[str]);

View File

@ -0,0 +1,6 @@
x Unexpected token `[`. Expected `.` or `(`
,-[$DIR/tests/errors/issue-4991/1/input.js:3:1]
3 | console.log(import[str]);
: ^
`----

View File

@ -0,0 +1 @@
console.log(import?.[meta]);

View File

@ -0,0 +1,6 @@
x Unexpected token `?`. Expected `.` or `(`
,-[$DIR/tests/errors/issue-4991/2/input.js:1:1]
1 | console.log(import?.[meta]);
: ^
`----

View File

@ -0,0 +1 @@
console.log(import?.meta);

View File

@ -0,0 +1,6 @@
x Unexpected token `?`. Expected `.` or `(`
,-[$DIR/tests/errors/issue-4991/3/input.js:1:1]
1 | console.log(import?.meta);
: ^
`----

View File

@ -0,0 +1 @@
console.log(import.[meta]);

View File

@ -0,0 +1,6 @@
x Expected ident
,-[$DIR/tests/errors/issue-4991/4/input.js:1:1]
1 | console.log(import.[meta]);
: ^
`----