mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(parser): remove parse_ts_index_signature_member function (#7017)
This commit is contained in:
parent
5b11cdf611
commit
aa1b29c0cf
3 changed files with 9 additions and 33 deletions
|
|
@ -231,7 +231,7 @@ impl<'a> ParserImpl<'a> {
|
||||||
if self.is_at_ts_index_signature_member() {
|
if self.is_at_ts_index_signature_member() {
|
||||||
return self
|
return self
|
||||||
.parse_index_signature_declaration(span, &modifiers)
|
.parse_index_signature_declaration(span, &modifiers)
|
||||||
.map(ClassElement::TSIndexSignature)
|
.map(|sig| self.ast.class_element_from_ts_index_signature(sig))
|
||||||
.map(Some);
|
.map(Some);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,12 @@ impl<'a> ParserImpl<'a> {
|
||||||
|
|
||||||
pub(crate) fn parse_ts_type_signature(&mut self) -> Result<Option<TSSignature<'a>>> {
|
pub(crate) fn parse_ts_type_signature(&mut self) -> Result<Option<TSSignature<'a>>> {
|
||||||
if self.is_at_ts_index_signature_member() {
|
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() {
|
match self.cur_kind() {
|
||||||
|
|
|
||||||
|
|
@ -1271,7 +1271,7 @@ impl<'a> ParserImpl<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
modifiers: &Modifiers<'a>,
|
modifiers: &Modifiers<'a>,
|
||||||
) -> Result<Box<'a, TSIndexSignature<'a>>> {
|
) -> Result<TSIndexSignature<'a>> {
|
||||||
self.verify_modifiers(
|
self.verify_modifiers(
|
||||||
modifiers,
|
modifiers,
|
||||||
ModifierFlags::READONLY | ModifierFlags::STATIC,
|
ModifierFlags::READONLY | ModifierFlags::STATIC,
|
||||||
|
|
@ -1284,7 +1284,7 @@ impl<'a> ParserImpl<'a> {
|
||||||
return Err(self.unexpected());
|
return Err(self.unexpected());
|
||||||
};
|
};
|
||||||
self.parse_type_member_semicolon();
|
self.parse_type_member_semicolon();
|
||||||
Ok(self.ast.alloc_ts_index_signature(
|
Ok(self.ast.ts_index_signature(
|
||||||
self.end_span(span),
|
self.end_span(span),
|
||||||
parameters,
|
parameters,
|
||||||
type_annotation,
|
type_annotation,
|
||||||
|
|
@ -1303,35 +1303,6 @@ impl<'a> ParserImpl<'a> {
|
||||||
self.bump(Kind::Semicolon);
|
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>> {
|
fn parse_ts_index_signature_name(&mut self) -> Result<TSIndexSignatureName<'a>> {
|
||||||
let span = self.start_span();
|
let span = self.start_span();
|
||||||
let name = self.parse_identifier_name()?.name;
|
let name = self.parse_identifier_name()?.name;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue