diff --git a/crates/oxc_parser/src/modifiers.rs b/crates/oxc_parser/src/modifiers.rs index 32b0439a557ca..9ed1e7d772a04 100644 --- a/crates/oxc_parser/src/modifiers.rs +++ b/crates/oxc_parser/src/modifiers.rs @@ -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. diff --git a/tasks/coverage/misc/fail/oxc-4212-1.ts b/tasks/coverage/misc/fail/oxc-4212-1.ts new file mode 100644 index 0000000000000..410c8083c5a89 --- /dev/null +++ b/tasks/coverage/misc/fail/oxc-4212-1.ts @@ -0,0 +1 @@ +class a { const enum b(); } \ No newline at end of file diff --git a/tasks/coverage/parser_misc.snap b/tasks/coverage/parser_misc.snap index d964066a55192..ab25c39bb127d 100644 --- a/tasks/coverage/parser_misc.snap +++ b/tasks/coverage/parser_misc.snap @@ -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;