diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index 1e5f432ab9653..f4346df57f628 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -231,7 +231,7 @@ impl<'a> ParserImpl<'a> { if self.is_at_ts_index_signature_member() { return self .parse_index_signature_declaration(span, &modifiers) - .map(ClassElement::TSIndexSignature) + .map(|sig| self.ast.class_element_from_ts_index_signature(sig)) .map(Some); } diff --git a/crates/oxc_parser/src/ts/statement.rs b/crates/oxc_parser/src/ts/statement.rs index 4123f05b859ef..9a81d0debfbc3 100644 --- a/crates/oxc_parser/src/ts/statement.rs +++ b/crates/oxc_parser/src/ts/statement.rs @@ -206,7 +206,12 @@ impl<'a> ParserImpl<'a> { pub(crate) fn parse_ts_type_signature(&mut self) -> Result>> { if self.is_at_ts_index_signature_member() { - return self.parse_ts_index_signature_member().map(Some); + let span = self.start_span(); + let modifiers = self.parse_modifiers(false, false, false); + return self + .parse_index_signature_declaration(span, &modifiers) + .map(|sig| self.ast.ts_signature_from_ts_index_signature(sig)) + .map(Some); } match self.cur_kind() { diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 732c1b36b3895..a985bd99f7499 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -1271,7 +1271,7 @@ impl<'a> ParserImpl<'a> { &mut self, span: Span, modifiers: &Modifiers<'a>, - ) -> Result>> { + ) -> Result> { self.verify_modifiers( modifiers, ModifierFlags::READONLY | ModifierFlags::STATIC, @@ -1284,7 +1284,7 @@ impl<'a> ParserImpl<'a> { return Err(self.unexpected()); }; self.parse_type_member_semicolon(); - Ok(self.ast.alloc_ts_index_signature( + Ok(self.ast.ts_index_signature( self.end_span(span), parameters, type_annotation, @@ -1303,35 +1303,6 @@ impl<'a> ParserImpl<'a> { self.bump(Kind::Semicolon); } - pub(crate) fn parse_ts_index_signature_member(&mut self) -> Result> { - let span = self.start_span(); - - let modifiers = self.parse_class_element_modifiers(false); - self.verify_modifiers( - &modifiers, - ModifierFlags::READONLY | ModifierFlags::STATIC, - diagnostics::cannot_appear_on_an_index_signature, - ); - - self.bump(Kind::LBrack); - let index_name = self.parse_ts_index_signature_name()?; - let mut parameters = self.ast.vec(); - parameters.push(index_name); - self.expect(Kind::RBrack)?; - - let type_annotation = self.parse_ts_type_annotation()?; - let Some(type_annotation) = type_annotation else { return Err(self.unexpected()) }; - self.bump(Kind::Comma); - self.bump(Kind::Semicolon); - Ok(self.ast.ts_signature_index_signature( - self.end_span(span), - parameters, - type_annotation, - modifiers.contains(ModifierKind::Readonly), - modifiers.contains(ModifierKind::Static), - )) - } - fn parse_ts_index_signature_name(&mut self) -> Result> { let span = self.start_span(); let name = self.parse_identifier_name()?.name;