fix(ast): change TSMappedType.type_annotation from TSTypeAnnotation to TSType (#2571)

Is ESTree, in that special case, there is no TSTypeAnnotation wrapper:

(See `type X` in each)

- [oxc
playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAIAWgICAgICAgICyHorESipoToAAwTlix58geR2%2Beeu9rZHQZOqK%2B%2BX85ZQ9ldchOoVw2oAm2qi9okF3bJ9o4l78ENP3f%2Bc%2B8cIK6Itp%2B3SIInU72Vk0%2FSqawy1VNV5zTgBr7gOpGtUZsvkc12Yp8MC2shel9fbpgDySpYsWdgDhf3jVlIA%3D)
- [astexplorer TSESLint
parser](9fc767f3a5)
- [astexplorer Babel
parser](9a4b02fae1)

---------

Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
Arnaud Barré 2024-03-03 07:38:45 +01:00 committed by GitHub
parent 32028eb1c5
commit 78f30bc2db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 5 additions and 5 deletions

View file

@ -836,7 +836,7 @@ pub struct TSMappedType<'a> {
pub span: Span,
pub type_parameter: Box<'a, TSTypeParameter<'a>>,
pub name_type: Option<TSType<'a>>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub type_annotation: Option<TSType<'a>>,
pub optional: TSMappedTypeModifierOperator,
pub readonly: TSMappedTypeModifierOperator,
}

View file

@ -1667,7 +1667,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
type_parameter: Box<'a, TSTypeParameter<'a>>,
name_type: Option<TSType<'a>>,
type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
type_annotation: Option<TSType<'a>>,
optional: TSMappedTypeModifierOperator,
readonly: TSMappedTypeModifierOperator,
) -> TSType<'a> {

View file

@ -1668,7 +1668,7 @@ pub trait Visit<'a>: Sized {
self.visit_ts_type(name);
}
if let Some(type_annotation) = &ty.type_annotation {
self.visit_ts_type_annotation(type_annotation);
self.visit_ts_type(type_annotation);
}
}

View file

@ -1667,7 +1667,7 @@ pub trait VisitMut<'a>: Sized {
self.visit_ts_type(name);
}
if let Some(type_annotation) = &mut ty.type_annotation {
self.visit_ts_type_annotation(type_annotation);
self.visit_ts_type(type_annotation);
}
}

View file

@ -662,7 +662,7 @@ impl<'a> ParserImpl<'a> {
_ => TSMappedTypeModifierOperator::None,
};
let type_annotation = self.parse_ts_type_annotation()?;
let type_annotation = self.eat(Kind::Colon).then(|| self.parse_ts_type()).transpose()?;
self.bump(Kind::Semicolon);
self.expect(Kind::RCurly)?;