mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-15 14:49:36 +00:00
fix(parser): avoid duplicate index signature modifier diagnostic (#27190)
## Summary - Report TS1071 once for invalid modifiers on class index signatures, while retaining TS1031 for other class members. - Update the TypeScript parser snapshot for `parserIndexMemberDeclaration9.ts`.
This commit is contained in:
1 parent
1a7c902a96
commit
dd0bbb98a0
2 files changed
+16
-15
No files matched your search
@@ -257,6 +257,18 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
}
|
||||
|
||||
fn parse_class_element_impl(&mut self) -> ClassElement<'a> {
|
||||
fn verify_class_element_modifiers<C: Config>(
|
||||
parser: &mut ParserImpl<'_, C>,
|
||||
modifiers: &Modifiers,
|
||||
) {
|
||||
parser.verify_modifiers(
|
||||
modifiers,
|
||||
ModifierKinds::all_except([ModifierKind::Export]),
|
||||
false,
|
||||
diagnostics::cannot_appear_on_class_elements,
|
||||
);
|
||||
}
|
||||
|
||||
let start = self.cur_start();
|
||||
|
||||
let decorators = self.parse_decorators();
|
||||
@@ -279,13 +291,6 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
return self.parse_class_static_block(start);
|
||||
}
|
||||
|
||||
self.verify_modifiers(
|
||||
&modifiers,
|
||||
ModifierKinds::all_except([ModifierKind::Export]),
|
||||
false,
|
||||
diagnostics::cannot_appear_on_class_elements,
|
||||
);
|
||||
|
||||
let r#abstract = modifiers.contains(ModifierKind::Abstract);
|
||||
|
||||
let r#type = if r#abstract {
|
||||
@@ -295,6 +300,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
};
|
||||
|
||||
if self.parse_contextual_modifier(Kind::Get) {
|
||||
verify_class_element_modifiers(self, &modifiers);
|
||||
return self.parse_accessor_declaration(
|
||||
start,
|
||||
r#type,
|
||||
@@ -305,6 +311,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
}
|
||||
|
||||
if self.parse_contextual_modifier(Kind::Set) {
|
||||
verify_class_element_modifiers(self, &modifiers);
|
||||
return self.parse_accessor_declaration(
|
||||
start,
|
||||
r#type,
|
||||
@@ -318,6 +325,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
&& !modifiers.contains(ModifierKind::Static)
|
||||
&& let Some(name) = self.parse_constructor_name()
|
||||
{
|
||||
verify_class_element_modifiers(self, &modifiers);
|
||||
return self.parse_constructor_declaration(start, r#type, name, &modifiers, decorators);
|
||||
}
|
||||
|
||||
@@ -339,6 +347,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
);
|
||||
}
|
||||
|
||||
verify_class_element_modifiers(self, &modifiers);
|
||||
let kind = self.cur_kind();
|
||||
if kind.is_identifier_or_keyword() || kind == Kind::Star || kind == Kind::LBrack {
|
||||
let is_ambient = modifiers.contains(ModifierKind::Declare);
|
||||
|
||||
@@ -27400,14 +27400,6 @@ Expect to Parse: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/
|
||||
╰────
|
||||
help: Allowed modifiers are: static, readonly
|
||||
|
||||
× TS(1031): 'export' modifier cannot appear on class elements of this kind.
|
||||
╭─[typescript/tsc/testdata/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts:2:4]
|
||||
1 │ class C {
|
||||
2 │ export [x: string]: string;
|
||||
· ──────
|
||||
3 │ }
|
||||
╰────
|
||||
|
||||
× TS(1071): 'export' modifier cannot appear on an index signature.
|
||||
╭─[typescript/tsc/testdata/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts:2:4]
|
||||
1 │ class C {
|
||||
|
||||
Reference in new issue
Block a user