Skip to content

Commit 3d430d9

Browse files
committed
fix(parser): forbid invalid modifiers on module and global
1 parent 74572d3 commit 3d430d9

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

9686+
× 'export' modifier cannot be used here.
9687+
╭─[typescript/tests/cases/compiler/privacyImportParseErrors.ts:326:9]
9688+
325 │
9689+
326 │ declare export module "anotherParseError2" {
9690+
· ──────
9691+
327 │ namespace m2 {
9692+
╰────
9693+
help: Only 'declare' modifier is allowed here.
9694+
96869695
× Unexpected token
96879696
╭─[typescript/tests/cases/compiler/privateNameJsx.tsx:4:22]
96889697
3 │ render() {

0 commit comments

Comments
 (0)