Skip to content

Commit 8523f78

Browse files
committed
fix(parser): forbid invalid modifiers on module and global
1 parent b4b0ed8 commit 8523f78

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
@@ -9688,6 +9688,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/statements/Va
96889688
327 │ namespace m2 {
96899689
╰────
96909690

9691+
× 'export' modifier cannot be used here.
9692+
╭─[typescript/tests/cases/compiler/privacyImportParseErrors.ts:326:9]
9693+
325 │
9694+
326 │ declare export module "anotherParseError2" {
9695+
· ──────
9696+
327 │ namespace m2 {
9697+
╰────
9698+
help: Only 'declare' modifier is allowed here.
9699+
96919700
× Unexpected token
96929701
╭─[typescript/tests/cases/compiler/privateNameJsx.tsx:4:22]
96939702
3 │ render() {

0 commit comments

Comments
 (0)