From 78f30bc2db1459e87eb331c8de29c68553e9f536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sun, 3 Mar 2024 07:38:45 +0100 Subject: [PATCH] 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](https://astexplorer.net/#/gist/626dd346956a02c221d4e128450652af/9fc767f3a5265865693571f25c82d65695ab31e1) - [astexplorer Babel parser](https://astexplorer.net/#/gist/ece6c59a642c58f726e6876d54dc18b5/9a4b02fae125c08e2f5e681d40b339c5ed938ef4) --------- Co-authored-by: Boshen --- crates/oxc_ast/src/ast/ts.rs | 2 +- crates/oxc_ast/src/ast_builder.rs | 2 +- crates/oxc_ast/src/visit.rs | 2 +- crates/oxc_ast/src/visit_mut.rs | 2 +- crates/oxc_parser/src/ts/types.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index 87978d359..3738334f1 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -836,7 +836,7 @@ pub struct TSMappedType<'a> { pub span: Span, pub type_parameter: Box<'a, TSTypeParameter<'a>>, pub name_type: Option>, - pub type_annotation: Option>>, + pub type_annotation: Option>, pub optional: TSMappedTypeModifierOperator, pub readonly: TSMappedTypeModifierOperator, } diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index 648ca6c5a..ea4ac4866 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -1667,7 +1667,7 @@ impl<'a> AstBuilder<'a> { span: Span, type_parameter: Box<'a, TSTypeParameter<'a>>, name_type: Option>, - type_annotation: Option>>, + type_annotation: Option>, optional: TSMappedTypeModifierOperator, readonly: TSMappedTypeModifierOperator, ) -> TSType<'a> { diff --git a/crates/oxc_ast/src/visit.rs b/crates/oxc_ast/src/visit.rs index 9e3ead8fc..ccfae6845 100644 --- a/crates/oxc_ast/src/visit.rs +++ b/crates/oxc_ast/src/visit.rs @@ -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); } } diff --git a/crates/oxc_ast/src/visit_mut.rs b/crates/oxc_ast/src/visit_mut.rs index af5555171..c1abda805 100644 --- a/crates/oxc_ast/src/visit_mut.rs +++ b/crates/oxc_ast/src/visit_mut.rs @@ -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); } } diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index ad2bfd6fc..11866f08c 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -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)?;