Arnaud Barré 2024-03-03 07:58:57 +01:00 committed by GitHub
parent 8bb1084863
commit 637cd1dea4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View file

@ -582,6 +582,7 @@ pub struct TSIndexSignature<'a> {
pub span: Span,
pub parameters: Vec<'a, Box<'a, TSIndexSignatureName<'a>>>,
pub type_annotation: Box<'a, TSTypeAnnotation<'a>>,
pub readonly: bool,
}
#[derive(Debug, Hash)]

View file

@ -1365,11 +1365,13 @@ impl<'a> AstBuilder<'a> {
span: Span,
parameters: Vec<'a, Box<'a, TSIndexSignatureName<'a>>>,
type_annotation: Box<'a, TSTypeAnnotation<'a>>,
readonly: bool,
) -> TSSignature<'a> {
TSSignature::TSIndexSignature(self.alloc(TSIndexSignature {
span,
parameters,
type_annotation,
readonly,
}))
}

View file

@ -1077,8 +1077,11 @@ impl<'a> ParserImpl<'a> {
pub(crate) fn parse_ts_index_signature_member(&mut self) -> Result<TSSignature<'a>> {
let span = self.start_span();
let mut readonly = false;
while self.is_nth_at_modifier(0, false) {
if !self.eat(Kind::Readonly) {
if self.eat(Kind::Readonly) {
readonly = true;
} else {
return Err(self.unexpected());
}
}
@ -1093,7 +1096,12 @@ impl<'a> ParserImpl<'a> {
if let Some(type_annotation) = type_annotation {
self.bump(Kind::Comma);
self.bump(Kind::Semicolon);
Ok(self.ast.ts_index_signature(self.end_span(span), parameters, type_annotation))
Ok(self.ast.ts_index_signature(
self.end_span(span),
parameters,
type_annotation,
readonly,
))
} else {
Err(self.unexpected())
}