mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(parser): avoid crashing on invalid const modifier (#4267)
Followup on https://github.com/oxc-project/oxc/pull/3977, fixing one of the crashes at https://github.com/oxc-project/oxc/pull/3977.
This commit is contained in:
parent
f144082a60
commit
9a87e41332
3 changed files with 14 additions and 2 deletions
|
|
@ -414,7 +414,11 @@ impl<'a> ParserImpl<'a> {
|
|||
let span = self.start_span();
|
||||
let kind = self.cur_kind();
|
||||
|
||||
if matches!(self.cur_kind(), Kind::Const) && permit_const_as_modifier {
|
||||
if matches!(self.cur_kind(), Kind::Const) {
|
||||
if !permit_const_as_modifier {
|
||||
return None;
|
||||
}
|
||||
|
||||
// We need to ensure that any subsequent modifiers appear on the same line
|
||||
// so that when 'const' is a standalone declaration, we don't issue
|
||||
// an error.
|
||||
|
|
|
|||
1
tasks/coverage/misc/fail/oxc-4212-1.ts
Normal file
1
tasks/coverage/misc/fail/oxc-4212-1.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
class a { const enum b(); }
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
parser_misc Summary:
|
||||
AST Parsed : 24/24 (100.00%)
|
||||
Positive Passed: 24/24 (100.00%)
|
||||
Negative Passed: 12/12 (100.00%)
|
||||
Negative Passed: 13/13 (100.00%)
|
||||
|
||||
× Unexpected token
|
||||
╭─[fail/oxc-169.js:2:1]
|
||||
|
|
@ -166,6 +166,13 @@ Negative Passed: 12/12 (100.00%)
|
|||
╰────
|
||||
help: Try insert a semicolon here
|
||||
|
||||
× Expected a semicolon or an implicit semicolon after a statement, but found none
|
||||
╭─[fail/oxc-4212-1.ts:1:16]
|
||||
1 │ class a { const enum b(); }
|
||||
· ▲
|
||||
╰────
|
||||
help: Try insert a semicolon here
|
||||
|
||||
× The keyword 'let' is reserved
|
||||
╭─[fail/oxc.js:1:1]
|
||||
1 │ let.a = 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue