Skip to content

Commit d4ff004

Browse files
overlookmotelcamc314
authored andcommitted
fix(parser): forbid invalid modifiers on module and global (#15723)
Error on invalid modifiers before `module` and `global` declarations. Previously illegal syntax like this would be parsed without error: ```ts protected accessor readonly async declare global {} protected accessor readonly async global {} protected accessor readonly async module "foo" {} ``` Discovered this bug while working on #15712. Similar to #11713.
1 parent f7ef032 commit d4ff004

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

crates/oxc_parser/src/ts/statement.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ impl<'a> ParserImpl<'a> {
334334
self.asi();
335335
None
336336
};
337+
self.verify_modifiers(
338+
modifiers,
339+
ModifierFlags::DECLARE,
340+
true,
341+
diagnostics::modifier_cannot_be_used_here,
342+
);
337343
self.ast.alloc_ts_module_declaration(
338344
self.end_span(span),
339345
id,
@@ -393,6 +399,13 @@ impl<'a> ParserImpl<'a> {
393399

394400
let body = self.parse_ts_module_block().unbox();
395401

402+
self.verify_modifiers(
403+
modifiers,
404+
ModifierFlags::DECLARE,
405+
true,
406+
diagnostics::modifier_cannot_be_used_here,
407+
);
408+
396409
self.ast.alloc_ts_global_declaration(
397410
self.end_span(span),
398411
keyword_span,

tasks/coverage/snapshots/parser_typescript.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9671,6 +9671,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/statements/Va
96719671
327 │ namespace m2 {
96729672
╰────
96739673

9674+
× 'export' modifier cannot be used here.
9675+
╭─[typescript/tests/cases/compiler/privacyImportParseErrors.ts:326:9]
9676+
325 │
9677+
326 │ declare export module "anotherParseError2" {
9678+
· ──────
9679+
327 │ namespace m2 {
9680+
╰────
9681+
help: Only 'declare' modifier is allowed here.
9682+
96749683
× Unexpected token
96759684
╭─[typescript/tests/cases/compiler/privateNameJsx.tsx:4:22]
96769685
3 │ render() {

0 commit comments

Comments
 (0)