Skip to content

Commit

Permalink
refactor(parser): remove parse_ts_index_signature_member function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 30, 2024
1 parent 5b11cdf commit aa1b29c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ impl<'a> ParserImpl<'a> {

pub(crate) fn parse_ts_type_signature(&mut self) -> Result<Option<TSSignature<'a>>> {
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() {
Expand Down
33 changes: 2 additions & 31 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ impl<'a> ParserImpl<'a> {
&mut self,
span: Span,
modifiers: &Modifiers<'a>,
) -> Result<Box<'a, TSIndexSignature<'a>>> {
) -> Result<TSIndexSignature<'a>> {
self.verify_modifiers(
modifiers,
ModifierFlags::READONLY | ModifierFlags::STATIC,
Expand All @@ -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,
Expand All @@ -1303,35 +1303,6 @@ impl<'a> ParserImpl<'a> {
self.bump(Kind::Semicolon);
}

pub(crate) fn parse_ts_index_signature_member(&mut self) -> Result<TSSignature<'a>> {
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<TSIndexSignatureName<'a>> {
let span = self.start_span();
let name = self.parse_identifier_name()?.name;
Expand Down

0 comments on commit aa1b29c

Please sign in to comment.