Skip to content

Commit 3a0f2aa

Browse files
committed
feat(parser): check for illegal modifiers in modules and namespaces (#4126)
1 parent d347aed commit 3a0f2aa

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

crates/oxc_parser/src/ts/statement.rs

+5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ impl<'a> ParserImpl<'a> {
265265
kind: TSModuleDeclarationKind,
266266
modifiers: &Modifiers<'a>,
267267
) -> Result<Box<'a, TSModuleDeclaration<'a>>> {
268+
self.verify_modifiers(
269+
modifiers,
270+
ModifierFlags::DECLARE | ModifierFlags::EXPORT,
271+
diagnostics::modifier_cannot_be_used_here,
272+
);
268273
let id = match self.cur_kind() {
269274
Kind::Str => self.parse_literal_string().map(TSModuleDeclarationName::StringLiteral),
270275
_ => self.parse_identifier_name().map(TSModuleDeclarationName::Identifier),

tasks/coverage/parser_typescript.snap

+45
Original file line numberDiff line numberDiff line change
@@ -10826,6 +10826,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1082610826
2 │ }
1082710827
╰────
1082810828

10829+
× 'async' modifier cannot be used here.
10830+
╭─[conformance/async/es5/asyncModule_es5.ts:1:1]
10831+
1 │ async module M {
10832+
· ─────
10833+
2 │ }
10834+
╰────
10835+
1082910836
× Expected `(` but found `Identifier`
1083010837
╭─[conformance/async/es5/asyncSetter_es5.ts:2:13]
1083110838
1 │ class C {
@@ -10961,6 +10968,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1096110968
2 │ }
1096210969
╰────
1096310970

10971+
× 'async' modifier cannot be used here.
10972+
╭─[conformance/async/es6/asyncModule_es6.ts:1:1]
10973+
1 │ async module M {
10974+
· ─────
10975+
2 │ }
10976+
╰────
10977+
1096410978
× Expected `(` but found `Identifier`
1096510979
╭─[conformance/async/es6/asyncSetter_es6.ts:2:13]
1096610980
1 │ class C {
@@ -16569,6 +16583,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1656916583
× 'public' modifier cannot be used here.
1657016584
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:19:5]
1657116585
18 │ module Y3 {
16586+
19 │ public module Module {
16587+
· ──────
16588+
20 │ class A { s: string }
16589+
╰────
16590+
16591+
× 'public' modifier cannot be used here.
16592+
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:19:5]
16593+
18 │ module Y3 {
1657216594
19 │ public module Module {
1657316595
· ──────
1657416596
20 │ class A { s: string }
@@ -16625,6 +16647,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1662516647
× 'private' modifier cannot be used here.
1662616648
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:44:5]
1662716649
43 │ module YY3 {
16650+
44 │ private module Module {
16651+
· ───────
16652+
45 │ class A { s: string }
16653+
╰────
16654+
16655+
× 'private' modifier cannot be used here.
16656+
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:44:5]
16657+
43 │ module YY3 {
1662816658
44 │ private module Module {
1662916659
· ───────
1663016660
45 │ class A { s: string }
@@ -16681,6 +16711,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1668116711
× 'static' modifier cannot be used here.
1668216712
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:70:5]
1668316713
69 │ module YYY3 {
16714+
70 │ static module Module {
16715+
· ──────
16716+
71 │ class A { s: string }
16717+
╰────
16718+
16719+
× 'static' modifier cannot be used here.
16720+
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:70:5]
16721+
69 │ module YYY3 {
1668416722
70 │ static module Module {
1668516723
· ──────
1668616724
71 │ class A { s: string }
@@ -18128,6 +18166,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1812818166
2 │ }
1812918167
╰────
1813018168

18169+
× 'protected' modifier cannot be used here.
18170+
╭─[conformance/parser/ecmascript5/Protected/Protected2.ts:1:1]
18171+
1 │ protected module M {
18172+
· ─────────
18173+
2 │ }
18174+
╰────
18175+
1813118176
× Expected a semicolon or an implicit semicolon after a statement, but found none
1813218177
╭─[conformance/parser/ecmascript5/RealWorld/parserharness.ts:1430:16]
1813318178
1429 │ // Regex for parsing options in the format "@Alpha: Value of any sort"

0 commit comments

Comments
 (0)