feat(parser): check for illegal modifiers in modules and namespaces (#4126)

This commit is contained in:
DonIsaac 2024-07-09 02:54:06 +00:00
parent d347aedfda
commit 3a0f2aa7ef
2 changed files with 50 additions and 0 deletions

View file

@ -265,6 +265,11 @@ impl<'a> ParserImpl<'a> {
kind: TSModuleDeclarationKind,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, TSModuleDeclaration<'a>>> {
self.verify_modifiers(
modifiers,
ModifierFlags::DECLARE | ModifierFlags::EXPORT,
diagnostics::modifier_cannot_be_used_here,
);
let id = match self.cur_kind() {
Kind::Str => self.parse_literal_string().map(TSModuleDeclarationName::StringLiteral),
_ => self.parse_identifier_name().map(TSModuleDeclarationName::Identifier),

View file

@ -10826,6 +10826,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
2 │ }
╰────
× 'async' modifier cannot be used here.
╭─[conformance/async/es5/asyncModule_es5.ts:1:1]
1 │ async module M {
· ─────
2 │ }
╰────
× Expected `(` but found `Identifier`
╭─[conformance/async/es5/asyncSetter_es5.ts:2:13]
1 │ class C {
@ -10961,6 +10968,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
2 │ }
╰────
× 'async' modifier cannot be used here.
╭─[conformance/async/es6/asyncModule_es6.ts:1:1]
1 │ async module M {
· ─────
2 │ }
╰────
× Expected `(` but found `Identifier`
╭─[conformance/async/es6/asyncSetter_es6.ts:2:13]
1 │ class C {
@ -16569,6 +16583,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
× 'public' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:19:5]
18 │ module Y3 {
19 │ public module Module {
· ──────
20 │ class A { s: string }
╰────
× 'public' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:19:5]
18 │ module Y3 {
19 │ public module Module {
· ──────
20 │ class A { s: string }
@ -16625,6 +16647,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
× 'private' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:44:5]
43 │ module YY3 {
44 │ private module Module {
· ───────
45 │ class A { s: string }
╰────
× 'private' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:44:5]
43 │ module YY3 {
44 │ private module Module {
· ───────
45 │ class A { s: string }
@ -16681,6 +16711,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
× 'static' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:70:5]
69 │ module YYY3 {
70 │ static module Module {
· ──────
71 │ class A { s: string }
╰────
× 'static' modifier cannot be used here.
╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:70:5]
69 │ module YYY3 {
70 │ static module Module {
· ──────
71 │ class A { s: string }
@ -18128,6 +18166,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
2 │ }
╰────
× 'protected' modifier cannot be used here.
╭─[conformance/parser/ecmascript5/Protected/Protected2.ts:1:1]
1 │ protected module M {
· ─────────
2 │ }
╰────
× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[conformance/parser/ecmascript5/RealWorld/parserharness.ts:1430:16]
1429 │ // Regex for parsing options in the format "@Alpha: Value of any sort"