diff --git a/crates/oxc_parser/src/modifiers.rs b/crates/oxc_parser/src/modifiers.rs index f235356053e16..f099dd61c1be1 100644 --- a/crates/oxc_parser/src/modifiers.rs +++ b/crates/oxc_parser/src/modifiers.rs @@ -460,7 +460,14 @@ impl<'a> ParserImpl<'a> { } fn check_for_duplicate_modifiers(&mut self, seen_flags: ModifierFlags, modifier: &Modifier) { - if seen_flags.contains(modifier.kind.into()) { + if seen_flags.contains(modifier.kind.into()) + || (matches!( + modifier.kind, + ModifierKind::Public | ModifierKind::Protected | ModifierKind::Private + ) && seen_flags.intersects( + ModifierFlags::PUBLIC | ModifierFlags::PROTECTED | ModifierFlags::PRIVATE, + )) + { self.error(diagnostics::modifier_already_seen(modifier)); } } diff --git a/tasks/coverage/snapshots/parser_babel.snap b/tasks/coverage/snapshots/parser_babel.snap index 47bcc3bab24a4..e9f6c0ac0196b 100644 --- a/tasks/coverage/snapshots/parser_babel.snap +++ b/tasks/coverage/snapshots/parser_babel.snap @@ -12121,6 +12121,51 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc ╰──── help: Remove the duplicate modifier. + × TS(1030): 'public' modifier already seen. + ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicates-accessibility/input.ts:3:11] + 2 │ public public a; + 3 │ private public b; + · ────── + 4 │ protected private c; + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'private' modifier already seen. + ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicates-accessibility/input.ts:4:13] + 3 │ private public b; + 4 │ protected private c; + · ─────── + 5 │ public protected d; + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'protected' modifier already seen. + ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicates-accessibility/input.ts:5:10] + 4 │ protected private c; + 5 │ public protected d; + · ───────── + 6 │ public protected private e; + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'protected' modifier already seen. + ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicates-accessibility/input.ts:6:10] + 5 │ public protected d; + 6 │ public protected private e; + · ───────── + 7 │ } + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'private' modifier already seen. + ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicates-accessibility/input.ts:6:20] + 5 │ public protected d; + 6 │ public protected private e; + · ─────── + 7 │ } + ╰──── + help: Remove the duplicate modifier. + × TS(1098): Type parameter list cannot be empty. ╭─[babel/packages/babel-parser/test/fixtures/typescript/class/empty-type-parameters/input.ts:1:8] 1 │ class C<> {} diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index 079eaf069708d..ab403662ec919 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -3,7 +3,7 @@ commit: 81c95189 parser_typescript Summary: AST Parsed : 6569/6576 (99.89%) Positive Passed: 6558/6576 (99.73%) -Negative Passed: 1418/5722 (24.78%) +Negative Passed: 1422/5722 (24.85%) Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment7.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment8.ts @@ -800,8 +800,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constraintWi Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constraints0.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constructorArgsErrors4.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constructorAsType.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts @@ -7134,8 +7132,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration4.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration2.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration3.d.ts @@ -7284,12 +7280,8 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList2.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Protected/Protected4.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Protected/Protected6.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Protected/Protected7.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/RealWorld/parserindenter.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509534.ts @@ -11159,6 +11151,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × TS(1030): 'public' modifier already seen. + ╭─[typescript/tests/cases/compiler/constructorArgsErrors4.ts:2:26] + 1 │ class foo { + 2 │ constructor (private public a: number) { + · ────── + 3 │ } + ╰──── + help: Remove the duplicate modifier. + × Identifier expected. 'export' is a reserved word that cannot be used here. ╭─[typescript/tests/cases/compiler/constructorArgsErrors5.ts:2:18] 1 │ class foo { @@ -20483,6 +20484,42 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private 3 │ } ╰──── + × TS(1030): 'public' modifier already seen. + ╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts:39:13] + 38 │ class E { + 39 │ private public protected property; + · ────── + 40 │ public protected method() { } + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'protected' modifier already seen. + ╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts:39:20] + 38 │ class E { + 39 │ private public protected property; + · ───────── + 40 │ public protected method() { } + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'protected' modifier already seen. + ╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts:40:12] + 39 │ private public protected property; + 40 │ public protected method() { } + · ───────── + 41 │ private protected get getter() { return 0; } + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'protected' modifier already seen. + ╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts:41:13] + 40 │ public protected method() { } + 41 │ private protected get getter() { return 0; } + · ───────── + 42 │ public public set setter(a: number) { } + ╰──── + help: Remove the duplicate modifier. + × TS(1030): 'public' modifier already seen. ╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts:42:12] 41 │ private protected get getter() { return 0; } @@ -26554,6 +26591,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × TS(1030): 'private' modifier already seen. + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts:2:10] + 1 │ class C { + 2 │ public private constructor() { } + · ─────── + 3 │ } + ╰──── + help: Remove the duplicate modifier. + × Expected `(` but found `;` ╭─[typescript/tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration8.ts:3:21] 2 │ // Not a constructor @@ -27832,6 +27878,24 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private 2 │ } ╰──── + × TS(1030): 'public' modifier already seen. + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/Protected/Protected4.ts:2:13] + 1 │ class C { + 2 │ protected public m() { } + · ────── + 3 │ } + ╰──── + help: Remove the duplicate modifier. + + × TS(1030): 'private' modifier already seen. + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/Protected/Protected7.ts:2:13] + 1 │ class C { + 2 │ protected private m() { } + · ─────── + 3 │ } + ╰──── + help: Remove the duplicate modifier. + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[typescript/tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts:1430:16] 1429 │ // Regex for parsing options in the format "@Alpha: Value of any sort"