diff --git a/crates/oxc_ast/src/ast/macros.rs b/crates/oxc_ast/src/ast/macros.rs index ab84632be761c..b7391748b96d7 100644 --- a/crates/oxc_ast/src/ast/macros.rs +++ b/crates/oxc_ast/src/ast/macros.rs @@ -703,6 +703,8 @@ macro_rules! inherit_variants { IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0, /// Inherited from [`TSTypeName`] QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1, + /// Inherited from [`TSTypeName`] + ThisExpression(Box<'a, ThisExpression>) = 2, $($rest)* } @@ -717,7 +719,7 @@ macro_rules! inherit_variants { as_ts_type_name_mut, to_ts_type_name, to_ts_type_name_mut, - [IdentifierReference, QualifiedName] + [IdentifierReference, QualifiedName, ThisExpression] ); }; diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index cc212d8cc2416..12330a8ab6290 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -769,21 +769,22 @@ pub struct TSTypeReference<'a> { /// TSTypeName: /// IdentifierReference +/// this /// TSTypeName . IdentifierName #[ast(visit)] #[derive(Debug)] #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)] pub enum TSTypeName<'a> { - #[estree(via = TSTypeNameIdentifierReference)] IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0, QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1, + ThisExpression(Box<'a, ThisExpression>) = 2, } /// Macro for matching `TSTypeName`'s variants. #[macro_export] macro_rules! match_ts_type_name { ($ty:ident) => { - $ty::IdentifierReference(_) | $ty::QualifiedName(_) + $ty::IdentifierReference(_) | $ty::QualifiedName(_) | $ty::ThisExpression(_) }; } pub use match_ts_type_name; @@ -1335,7 +1336,7 @@ inherit_variants! { #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)] pub enum TSTypeQueryExprName<'a> { /// `type foo = typeof import('foo')` - TSImportType(Box<'a, TSImportType<'a>>) = 2, + TSImportType(Box<'a, TSImportType<'a>>) = 3, // `TSTypeName` variants added here by `inherit_variants!` macro @inherit TSTypeName } @@ -1585,7 +1586,7 @@ inherit_variants! { #[derive(Debug)] #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)] pub enum TSModuleReference<'a> { - ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 2, + ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 3, // `TSTypeName` variants added here by `inherit_variants!` macro @inherit TSTypeName } diff --git a/crates/oxc_ast/src/ast_impl/ts.rs b/crates/oxc_ast/src/ast_impl/ts.rs index 5ea0a8a188fa7..94b054db4363d 100644 --- a/crates/oxc_ast/src/ast_impl/ts.rs +++ b/crates/oxc_ast/src/ast_impl/ts.rs @@ -32,9 +32,7 @@ impl<'a> TSType<'a> { /// returned. pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> { match self { - TSType::TSTypeReference(reference) => { - Some(reference.type_name.get_identifier_reference()) - } + TSType::TSTypeReference(reference) => reference.type_name.get_identifier_reference(), TSType::TSTypeQuery(query) => match &query.expr_name { TSTypeQueryExprName::IdentifierReference(ident) => Some(ident), _ => None, @@ -86,10 +84,11 @@ impl<'a> TSTypeName<'a> { /// type Foo = Bar; // -> Bar /// type Foo = Bar.Baz; // -> Bar /// ``` - pub fn get_identifier_reference(&self) -> &IdentifierReference<'a> { + pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> { match self { - TSTypeName::IdentifierReference(ident) => ident, + TSTypeName::IdentifierReference(ident) => Some(ident), TSTypeName::QualifiedName(name) => name.left.get_identifier_reference(), + TSTypeName::ThisExpression(_) => None, } } @@ -120,6 +119,7 @@ impl fmt::Display for TSTypeName<'_> { match self { TSTypeName::IdentifierReference(ident) => ident.fmt(f), TSTypeName::QualifiedName(qualified) => qualified.fmt(f), + TSTypeName::ThisExpression(_) => "this".fmt(f), } } } diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index f83a24d6da6d2..dae8ae8021a0e 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -11748,6 +11748,17 @@ impl<'a> AstBuilder<'a> { TSTypeName::QualifiedName(self.alloc_ts_qualified_name(span, left, right)) } + /// Build a [`TSTypeName::ThisExpression`]. + /// + /// This node contains a [`ThisExpression`] that will be stored in the memory arena. + /// + /// ## Parameters + /// * `span`: The [`Span`] covering this node + #[inline] + pub fn ts_type_name_this_expression(self, span: Span) -> TSTypeName<'a> { + TSTypeName::ThisExpression(self.alloc_this_expression(span)) + } + /// Build a [`TSQualifiedName`]. /// /// If you want the built node to be allocated in the memory arena, diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index 1b0ac12c6295a..80fb364848a1d 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -6714,6 +6714,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> { TSTypeName::IdentifierReference(CloneIn::clone_in(it, allocator)) } Self::QualifiedName(it) => TSTypeName::QualifiedName(CloneIn::clone_in(it, allocator)), + Self::ThisExpression(it) => { + TSTypeName::ThisExpression(CloneIn::clone_in(it, allocator)) + } } } @@ -6725,6 +6728,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> { Self::QualifiedName(it) => { TSTypeName::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::ThisExpression(it) => { + TSTypeName::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } } } } @@ -7379,6 +7385,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> { Self::QualifiedName(it) => { TSTypeQueryExprName::QualifiedName(CloneIn::clone_in(it, allocator)) } + Self::ThisExpression(it) => { + TSTypeQueryExprName::ThisExpression(CloneIn::clone_in(it, allocator)) + } } } @@ -7393,6 +7402,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> { Self::QualifiedName(it) => TSTypeQueryExprName::QualifiedName( CloneIn::clone_in_with_semantic_ids(it, allocator), ), + Self::ThisExpression(it) => TSTypeQueryExprName::ThisExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), } } } @@ -7632,6 +7644,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> { Self::QualifiedName(it) => { TSModuleReference::QualifiedName(CloneIn::clone_in(it, allocator)) } + Self::ThisExpression(it) => { + TSModuleReference::ThisExpression(CloneIn::clone_in(it, allocator)) + } } } @@ -7646,6 +7661,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> { Self::QualifiedName(it) => { TSModuleReference::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::ThisExpression(it) => TSModuleReference::ThisExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), } } } diff --git a/crates/oxc_ast/src/generated/derive_content_eq.rs b/crates/oxc_ast/src/generated/derive_content_eq.rs index ffc014361b854..c15ac6dd1a0ea 100644 --- a/crates/oxc_ast/src/generated/derive_content_eq.rs +++ b/crates/oxc_ast/src/generated/derive_content_eq.rs @@ -2061,6 +2061,7 @@ impl ContentEq for TSTypeName<'_> { match (self, other) { (Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b), (Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b), + (Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b), _ => false, } } @@ -2306,6 +2307,7 @@ impl ContentEq for TSTypeQueryExprName<'_> { (Self::TSImportType(a), Self::TSImportType(b)) => a.content_eq(b), (Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b), (Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b), + (Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b), _ => false, } } @@ -2396,6 +2398,7 @@ impl ContentEq for TSModuleReference<'_> { (Self::ExternalModuleReference(a), Self::ExternalModuleReference(b)) => a.content_eq(b), (Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b), (Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b), + (Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b), _ => false, } } diff --git a/crates/oxc_ast/src/generated/derive_dummy.rs b/crates/oxc_ast/src/generated/derive_dummy.rs index 12b4fd502d766..03cf425afd644 100644 --- a/crates/oxc_ast/src/generated/derive_dummy.rs +++ b/crates/oxc_ast/src/generated/derive_dummy.rs @@ -2232,7 +2232,7 @@ impl<'a> Dummy<'a> for TSBigIntKeyword { impl<'a> Dummy<'a> for TSTypeReference<'a> { /// Create a dummy [`TSTypeReference`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { Self { span: Dummy::dummy(allocator), @@ -2245,16 +2245,16 @@ impl<'a> Dummy<'a> for TSTypeReference<'a> { impl<'a> Dummy<'a> for TSTypeName<'a> { /// Create a dummy [`TSTypeName`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { - Self::IdentifierReference(Dummy::dummy(allocator)) + Self::ThisExpression(Dummy::dummy(allocator)) } } impl<'a> Dummy<'a> for TSQualifiedName<'a> { /// Create a dummy [`TSQualifiedName`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { Self { span: Dummy::dummy(allocator), @@ -2328,7 +2328,7 @@ impl<'a> Dummy<'a> for TSAccessibility { impl<'a> Dummy<'a> for TSClassImplements<'a> { /// Create a dummy [`TSClassImplements`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { Self { span: Dummy::dummy(allocator), @@ -2591,7 +2591,7 @@ impl<'a> Dummy<'a> for TSInferType<'a> { impl<'a> Dummy<'a> for TSTypeQuery<'a> { /// Create a dummy [`TSTypeQuery`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { Self { span: Dummy::dummy(allocator), @@ -2604,9 +2604,9 @@ impl<'a> Dummy<'a> for TSTypeQuery<'a> { impl<'a> Dummy<'a> for TSTypeQueryExprName<'a> { /// Create a dummy [`TSTypeQueryExprName`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { - Self::IdentifierReference(Dummy::dummy(allocator)) + Self::ThisExpression(Dummy::dummy(allocator)) } } @@ -2738,7 +2738,7 @@ impl<'a> Dummy<'a> for TSTypeAssertion<'a> { impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> { /// Create a dummy [`TSImportEqualsDeclaration`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { Self { span: Dummy::dummy(allocator), @@ -2752,9 +2752,9 @@ impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> { impl<'a> Dummy<'a> for TSModuleReference<'a> { /// Create a dummy [`TSModuleReference`]. /// - /// Has cost of making 1 allocation (32 bytes). + /// Has cost of making 1 allocation (8 bytes). fn dummy(allocator: &'a Allocator) -> Self { - Self::IdentifierReference(Dummy::dummy(allocator)) + Self::ThisExpression(Dummy::dummy(allocator)) } } diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index b177abb7ca45c..a4ec629d1138b 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -2628,10 +2628,9 @@ impl ESTree for TSTypeReference<'_> { impl ESTree for TSTypeName<'_> { fn serialize(&self, serializer: S) { match self { - Self::IdentifierReference(it) => { - crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer) - } + Self::IdentifierReference(it) => it.serialize(serializer), Self::QualifiedName(it) => it.serialize(serializer), + Self::ThisExpression(it) => it.serialize(serializer), } } } @@ -2965,10 +2964,9 @@ impl ESTree for TSTypeQueryExprName<'_> { fn serialize(&self, serializer: S) { match self { Self::TSImportType(it) => it.serialize(serializer), - Self::IdentifierReference(it) => { - crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer) - } + Self::IdentifierReference(it) => it.serialize(serializer), Self::QualifiedName(it) => it.serialize(serializer), + Self::ThisExpression(it) => it.serialize(serializer), } } } @@ -3096,10 +3094,9 @@ impl ESTree for TSModuleReference<'_> { fn serialize(&self, serializer: S) { match self { Self::ExternalModuleReference(it) => it.serialize(serializer), - Self::IdentifierReference(it) => { - crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer) - } + Self::IdentifierReference(it) => it.serialize(serializer), Self::QualifiedName(it) => it.serialize(serializer), + Self::ThisExpression(it) => it.serialize(serializer), } } } diff --git a/crates/oxc_ast/src/generated/derive_get_address.rs b/crates/oxc_ast/src/generated/derive_get_address.rs index 4a9dcdd8ffa0f..25430edebd691 100644 --- a/crates/oxc_ast/src/generated/derive_get_address.rs +++ b/crates/oxc_ast/src/generated/derive_get_address.rs @@ -727,6 +727,7 @@ impl GetAddress for TSTypeName<'_> { match self { Self::IdentifierReference(it) => GetAddress::address(it), Self::QualifiedName(it) => GetAddress::address(it), + Self::ThisExpression(it) => GetAddress::address(it), } } } @@ -764,6 +765,7 @@ impl GetAddress for TSTypeQueryExprName<'_> { Self::TSImportType(it) => GetAddress::address(it), Self::IdentifierReference(it) => GetAddress::address(it), Self::QualifiedName(it) => GetAddress::address(it), + Self::ThisExpression(it) => GetAddress::address(it), } } } @@ -776,6 +778,7 @@ impl GetAddress for TSModuleReference<'_> { Self::ExternalModuleReference(it) => GetAddress::address(it), Self::IdentifierReference(it) => GetAddress::address(it), Self::QualifiedName(it) => GetAddress::address(it), + Self::ThisExpression(it) => GetAddress::address(it), } } } diff --git a/crates/oxc_ast/src/generated/derive_get_span.rs b/crates/oxc_ast/src/generated/derive_get_span.rs index d89586af5d01b..3c626d2059763 100644 --- a/crates/oxc_ast/src/generated/derive_get_span.rs +++ b/crates/oxc_ast/src/generated/derive_get_span.rs @@ -1817,6 +1817,7 @@ impl GetSpan for TSTypeName<'_> { match self { Self::IdentifierReference(it) => GetSpan::span(&**it), Self::QualifiedName(it) => GetSpan::span(&**it), + Self::ThisExpression(it) => GetSpan::span(&**it), } } } @@ -2013,6 +2014,7 @@ impl GetSpan for TSTypeQueryExprName<'_> { Self::TSImportType(it) => GetSpan::span(&**it), Self::IdentifierReference(it) => GetSpan::span(&**it), Self::QualifiedName(it) => GetSpan::span(&**it), + Self::ThisExpression(it) => GetSpan::span(&**it), } } } @@ -2086,6 +2088,7 @@ impl GetSpan for TSModuleReference<'_> { Self::ExternalModuleReference(it) => GetSpan::span(&**it), Self::IdentifierReference(it) => GetSpan::span(&**it), Self::QualifiedName(it) => GetSpan::span(&**it), + Self::ThisExpression(it) => GetSpan::span(&**it), } } } diff --git a/crates/oxc_ast/src/generated/derive_get_span_mut.rs b/crates/oxc_ast/src/generated/derive_get_span_mut.rs index 6930361f6b65d..073a374e77bc2 100644 --- a/crates/oxc_ast/src/generated/derive_get_span_mut.rs +++ b/crates/oxc_ast/src/generated/derive_get_span_mut.rs @@ -1817,6 +1817,7 @@ impl GetSpanMut for TSTypeName<'_> { match self { Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it), Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it), + Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it), } } } @@ -2013,6 +2014,7 @@ impl GetSpanMut for TSTypeQueryExprName<'_> { Self::TSImportType(it) => GetSpanMut::span_mut(&mut **it), Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it), Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it), + Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it), } } } @@ -2086,6 +2088,7 @@ impl GetSpanMut for TSModuleReference<'_> { Self::ExternalModuleReference(it) => GetSpanMut::span_mut(&mut **it), Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it), Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it), + Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it), } } } diff --git a/crates/oxc_ast/src/serialize/ts.rs b/crates/oxc_ast/src/serialize/ts.rs index 4e903349157f8..512b038d24f6a 100644 --- a/crates/oxc_ast/src/serialize/ts.rs +++ b/crates/oxc_ast/src/serialize/ts.rs @@ -259,31 +259,6 @@ impl ESTree for TSMappedTypeConstraint<'_, '_> { } } -/// Serializer for `IdentifierReference` variant of `TSTypeName`. -/// -/// Where is an identifier called `this`, TS-ESTree presents it as a `ThisExpression`. -#[ast_meta] -#[estree( - ts_type = "IdentifierReference | ThisExpression", - raw_deser = " - let id = DESER[Box](POS); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - id - " -)] -pub struct TSTypeNameIdentifierReference<'a, 'b>(pub &'b IdentifierReference<'a>); - -impl ESTree for TSTypeNameIdentifierReference<'_, '_> { - fn serialize(&self, serializer: S) { - let ident = self.0; - if ident.name == "this" { - ThisExpression { span: ident.span }.serialize(serializer); - } else { - ident.serialize(serializer); - } - } -} - /// Serializer for `expression` field of `TSClassImplements`. /// /// Our AST represents `X.Y` in `class C implements X.Y {}` as a `TSQualifiedName`. @@ -340,7 +315,7 @@ impl ESTree for TSTypeNameAsMemberExpression<'_, '_> { fn serialize(&self, serializer: S) { match self.0 { TSTypeName::IdentifierReference(ident) => { - TSTypeNameIdentifierReference(ident).serialize(serializer); + ident.serialize(serializer); } TSTypeName::QualifiedName(name) => { // Convert to `TSQualifiedName` to `MemberExpression`. @@ -354,6 +329,9 @@ impl ESTree for TSTypeNameAsMemberExpression<'_, '_> { state.serialize_span(name.span); state.end(); } + TSTypeName::ThisExpression(e) => { + e.serialize(serializer); + } } } } diff --git a/crates/oxc_ast_visit/src/generated/visit.rs b/crates/oxc_ast_visit/src/generated/visit.rs index 0ba993a370760..389a4b81df28e 100644 --- a/crates/oxc_ast_visit/src/generated/visit.rs +++ b/crates/oxc_ast_visit/src/generated/visit.rs @@ -3553,6 +3553,7 @@ pub mod walk { match it { TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it), TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it), + TSTypeName::ThisExpression(it) => visitor.visit_this_expression(it), } } diff --git a/crates/oxc_ast_visit/src/generated/visit_mut.rs b/crates/oxc_ast_visit/src/generated/visit_mut.rs index 59c9731fa5f21..78ba74dae9ca2 100644 --- a/crates/oxc_ast_visit/src/generated/visit_mut.rs +++ b/crates/oxc_ast_visit/src/generated/visit_mut.rs @@ -3741,6 +3741,7 @@ pub mod walk_mut { match it { TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it), TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it), + TSTypeName::ThisExpression(it) => visitor.visit_this_expression(it), } } diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 7f27fd3218d5a..96404e0456426 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -3240,6 +3240,9 @@ impl Gen for TSTypeName<'_> { p.print_str("."); decl.right.print(p, ctx); } + Self::ThisExpression(e) => { + e.print(p, ctx); + } } } } diff --git a/crates/oxc_formatter/src/generated/ast_nodes.rs b/crates/oxc_formatter/src/generated/ast_nodes.rs index c2df4b404cde3..35a9d32ffb3c9 100644 --- a/crates/oxc_formatter/src/generated/ast_nodes.rs +++ b/crates/oxc_formatter/src/generated/ast_nodes.rs @@ -2046,6 +2046,7 @@ impl<'a> From<&'a TSTypeName<'a>> for SiblingNode<'a> { match node { TSTypeName::IdentifierReference(inner) => SiblingNode::IdentifierReference(inner), TSTypeName::QualifiedName(inner) => SiblingNode::TSQualifiedName(inner), + TSTypeName::ThisExpression(inner) => SiblingNode::ThisExpression(inner), } } } @@ -11501,6 +11502,14 @@ impl<'a> AstNode<'a, TSTypeName<'a>> { following_node: self.following_node, })) } + TSTypeName::ThisExpression(s) => { + AstNodes::ThisExpression(self.allocator.alloc(AstNode { + inner: s.as_ref(), + parent, + allocator: self.allocator, + following_node: self.following_node, + })) + } }; self.allocator.alloc(node) } diff --git a/crates/oxc_formatter/src/generated/format_write.rs b/crates/oxc_formatter/src/generated/format_write.rs index 0c89b24e6bf7c..bfd5b785e627b 100644 --- a/crates/oxc_formatter/src/generated/format_write.rs +++ b/crates/oxc_formatter/src/generated/format_write.rs @@ -2048,6 +2048,14 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSTypeName<'a>> { following_node: self.following_node, }) .fmt(f), + TSTypeName::ThisExpression(inner) => allocator + .alloc(AstNode:: { + inner, + parent, + allocator, + following_node: self.following_node, + }) + .fmt(f), } } } diff --git a/crates/oxc_isolated_declarations/src/scope.rs b/crates/oxc_isolated_declarations/src/scope.rs index 8f71c541939ef..4314c991859d8 100644 --- a/crates/oxc_isolated_declarations/src/scope.rs +++ b/crates/oxc_isolated_declarations/src/scope.rs @@ -114,12 +114,13 @@ impl<'a> Visit<'a> for ScopeTree<'a> { // `typeof Value` or `typeof Value` fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) { if let Some(type_name) = ty.expr_name.as_ts_type_name() { - let ident = TSTypeName::get_identifier_reference(type_name); - self.add_reference(ident.name, KindFlags::Value); - // `typeof Type` - // ^^^^^^^^^^^ - if let Some(type_parameters) = &ty.type_arguments { - self.visit_ts_type_parameter_instantiation(type_parameters); + if let Some(ident) = TSTypeName::get_identifier_reference(type_name) { + self.add_reference(ident.name, KindFlags::Value); + // `typeof Type` + // ^^^^^^^^^^^ + if let Some(type_parameters) = &ty.type_arguments { + self.visit_ts_type_parameter_instantiation(type_parameters); + } } } else { walk_ts_type_query(self, ty); diff --git a/crates/oxc_linter/src/rules/import/first.rs b/crates/oxc_linter/src/rules/import/first.rs index cd9d43b6b5e5b..6e72c7a6403c8 100644 --- a/crates/oxc_linter/src/rules/import/first.rs +++ b/crates/oxc_linter/src/rules/import/first.rs @@ -128,7 +128,8 @@ impl Rule for First { } } TSModuleReference::IdentifierReference(_) - | TSModuleReference::QualifiedName(_) => {} + | TSModuleReference::QualifiedName(_) + | TSModuleReference::ThisExpression(_) => {} }, Statement::ImportDeclaration(decl) => { if matches!(self.absolute_first, AbsoluteFirst::AbsoluteFirst) { @@ -177,7 +178,7 @@ fn test() { ), // covers TSImportEqualsDeclaration (original rule support it, but with no test cases) ( - r"import { x } from './foo'; + r"import { x } from './foo'; import F3 = require('mod'); export { x, y }", None, diff --git a/crates/oxc_linter/src/rules/typescript/array_type.rs b/crates/oxc_linter/src/rules/typescript/array_type.rs index 6303473aadb1e..3c11c7ce2df24 100644 --- a/crates/oxc_linter/src/rules/typescript/array_type.rs +++ b/crates/oxc_linter/src/rules/typescript/array_type.rs @@ -477,24 +477,25 @@ fn is_simple_type(ts_type: &TSType) -> bool { | TSType::TSUndefinedKeyword(_) | TSType::TSThisType(_) => true, TSType::TSTypeReference(node) => { - let type_name = TSTypeName::get_identifier_reference(&node.type_name); - if type_name.name.as_str() == "Array" { - if node.type_arguments.is_none() { - return true; - } - if node.type_arguments.as_ref().unwrap().params.len() == 1 { - return is_simple_type( - node.type_arguments.as_ref().unwrap().params.first().unwrap(), - ); - } - } else { - if node.type_arguments.is_some() { + if let Some(type_name) = TSTypeName::get_identifier_reference(&node.type_name) { + if type_name.name.as_str() == "Array" { + if node.type_arguments.is_none() { + return true; + } + if node.type_arguments.as_ref().unwrap().params.len() == 1 { + return is_simple_type( + node.type_arguments.as_ref().unwrap().params.first().unwrap(), + ); + } + } else { + if node.type_arguments.is_some() { + return false; + } + if let TSTypeName::IdentifierReference(_) = &node.type_name { + return true; + } return false; } - if let TSTypeName::IdentifierReference(_) = &node.type_name { - return true; - } - return false; } false } diff --git a/crates/oxc_linter/src/rules/typescript/ban_types.rs b/crates/oxc_linter/src/rules/typescript/ban_types.rs index 85813803de149..ea22c950f5228 100644 --- a/crates/oxc_linter/src/rules/typescript/ban_types.rs +++ b/crates/oxc_linter/src/rules/typescript/ban_types.rs @@ -73,7 +73,7 @@ impl Rule for BanTypes { AstKind::TSTypeReference(ty) => { let name = match &ty.type_name { TSTypeName::IdentifierReference(v) => &v.name, - TSTypeName::QualifiedName(_) => return, + TSTypeName::QualifiedName(_) | TSTypeName::ThisExpression(_) => return, }; match name.as_str() { diff --git a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs index c8bd7db0804d5..c7e2a31930f5a 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs @@ -127,7 +127,7 @@ impl Rule for ConsistentIndexedObjectStyle { )); } } - TSTypeName::QualifiedName(_) => { + TSTypeName::QualifiedName(_) | TSTypeName::ThisExpression(_) => { ctx.diagnostic(consistent_indexed_object_style_diagnostic( "record", "index signature", @@ -193,7 +193,7 @@ impl Rule for ConsistentIndexedObjectStyle { )); } } - TSTypeName::QualifiedName(_) => { + TSTypeName::QualifiedName(_) | TSTypeName::ThisExpression(_) => { ctx.diagnostic(consistent_indexed_object_style_diagnostic( "record", "index signature", diff --git a/crates/oxc_linter/src/rules/typescript/no_require_imports.rs b/crates/oxc_linter/src/rules/typescript/no_require_imports.rs index 119283ed9a12b..5bc2b6d754805 100644 --- a/crates/oxc_linter/src/rules/typescript/no_require_imports.rs +++ b/crates/oxc_linter/src/rules/typescript/no_require_imports.rs @@ -208,8 +208,9 @@ impl Rule for NoRequireImports { ctx.diagnostic(no_require_imports_diagnostic(decl.span)); } - TSModuleReference::IdentifierReference(_) | TSModuleReference::QualifiedName(_) => { - } + TSModuleReference::IdentifierReference(_) + | TSModuleReference::QualifiedName(_) + | TSModuleReference::ThisExpression(_) => {} }, _ => {} } diff --git a/crates/oxc_linter/src/rules/typescript/triple_slash_reference.rs b/crates/oxc_linter/src/rules/typescript/triple_slash_reference.rs index fbbaa1769c6ab..d690330bf3415 100644 --- a/crates/oxc_linter/src/rules/typescript/triple_slash_reference.rs +++ b/crates/oxc_linter/src/rules/typescript/triple_slash_reference.rs @@ -143,7 +143,8 @@ impl Rule for TripleSlashReference { } } TSModuleReference::IdentifierReference(_) - | TSModuleReference::QualifiedName(_) => {} + | TSModuleReference::QualifiedName(_) + | TSModuleReference::ThisExpression(_) => {} }, Statement::ImportDeclaration(decl) => { if let Some(v) = refs_for_import.get(decl.source.value.as_str()) { diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 4813ead2ac97b..9e1f25d51c9a1 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -786,14 +786,16 @@ impl<'a> ParserImpl<'a> { pub(crate) fn parse_ts_type_name(&mut self) -> TSTypeName<'a> { let span = self.start_span(); - let ident = self.parse_identifier_name(); - let ident = self.ast.alloc_identifier_reference(ident.span, ident.name); - let left_name = TSTypeName::IdentifierReference(ident); - if self.at(Kind::Dot) { - self.parse_ts_qualified_type_name(span, left_name) + let left = if self.at(Kind::This) { + self.bump_any(); + let this_expr = self.ast.alloc_this_expression(self.end_span(span)); + TSTypeName::ThisExpression(this_expr) } else { - left_name - } + let ident = self.parse_identifier_name(); + let ident = self.ast.alloc_identifier_reference(ident.span, ident.name); + TSTypeName::IdentifierReference(ident) + }; + if self.at(Kind::Dot) { self.parse_ts_qualified_type_name(span, left) } else { left } } pub(crate) fn parse_ts_qualified_type_name( diff --git a/crates/oxc_transformer/src/decorator/legacy/metadata.rs b/crates/oxc_transformer/src/decorator/legacy/metadata.rs index 3bde8c383838f..26c9a55648e6c 100644 --- a/crates/oxc_transformer/src/decorator/legacy/metadata.rs +++ b/crates/oxc_transformer/src/decorator/legacy/metadata.rs @@ -419,6 +419,7 @@ impl<'a> LegacyDecoratorMetadata<'a, '_> { Some(ctx.ast.expression_logical(SPAN, left, LogicalOperator::And, member)) } } + TSTypeName::ThisExpression(_) => None, } } diff --git a/crates/oxc_transformer/src/typescript/module.rs b/crates/oxc_transformer/src/typescript/module.rs index 612439e5a0168..78aedfa526f97 100644 --- a/crates/oxc_transformer/src/typescript/module.rs +++ b/crates/oxc_transformer/src/typescript/module.rs @@ -106,15 +106,18 @@ impl<'a> TypeScriptModule<'a, '_> { // No value reference, we will remove this declaration in `TypeScriptAnnotations` match &mut decl.module_reference { module_reference @ match_ts_type_name!(TSModuleReference) => { - let ident = module_reference.to_ts_type_name().get_identifier_reference(); - let reference = ctx.scoping_mut().get_reference_mut(ident.reference_id()); - // The binding of TSImportEqualsDeclaration has treated as a type reference, - // so an identifier reference that it referenced also should be treated as a type reference. - // `import TypeBinding = X.Y.Z` - // ^ `X` should be treated as a type reference. - let flags = reference.flags_mut(); - debug_assert_eq!(*flags, ReferenceFlags::Read); - *flags = ReferenceFlags::Type; + if let Some(ident) = + module_reference.to_ts_type_name().get_identifier_reference() + { + let reference = ctx.scoping_mut().get_reference_mut(ident.reference_id()); + // The binding of TSImportEqualsDeclaration has treated as a type reference, + // so an identifier reference that it referenced also should be treated as a type reference. + // `import TypeBinding = X.Y.Z` + // ^ `X` should be treated as a type reference. + let flags = reference.flags_mut(); + debug_assert_eq!(*flags, ReferenceFlags::Read); + *flags = ReferenceFlags::Type; + } } TSModuleReference::ExternalModuleReference(_) => {} } @@ -191,6 +194,7 @@ impl<'a> TypeScriptModule<'a, '_> { false, ) .into(), + TSTypeName::ThisExpression(e) => ctx.ast.expression_this(e.span), } } } diff --git a/crates/oxc_traverse/src/generated/scopes_collector.rs b/crates/oxc_traverse/src/generated/scopes_collector.rs index c06793912fe74..91f5b25a71881 100644 --- a/crates/oxc_traverse/src/generated/scopes_collector.rs +++ b/crates/oxc_traverse/src/generated/scopes_collector.rs @@ -1890,6 +1890,7 @@ impl<'a> Visit<'a> for ChildScopeCollector { // Remaining variants do not contain scopes: // `IdentifierReference` // `QualifiedName` + // `ThisExpression` } } } diff --git a/crates/oxc_traverse/src/generated/walk.rs b/crates/oxc_traverse/src/generated/walk.rs index 870e42b84fc52..39eb371f02dce 100644 --- a/crates/oxc_traverse/src/generated/walk.rs +++ b/crates/oxc_traverse/src/generated/walk.rs @@ -4439,6 +4439,9 @@ unsafe fn walk_ts_type_name<'a, State, Tr: Traverse<'a, State>>( TSTypeName::QualifiedName(node) => { walk_ts_qualified_name(traverser, (&mut **node) as *mut _, ctx) } + TSTypeName::ThisExpression(node) => { + walk_this_expression(traverser, (&mut **node) as *mut _, ctx) + } } traverser.exit_ts_type_name(&mut *node, ctx); } @@ -5128,7 +5131,9 @@ unsafe fn walk_ts_type_query_expr_name<'a, State, Tr: Traverse<'a, State>>( TSTypeQueryExprName::TSImportType(node) => { walk_ts_import_type(traverser, (&mut **node) as *mut _, ctx) } - TSTypeQueryExprName::IdentifierReference(_) | TSTypeQueryExprName::QualifiedName(_) => { + TSTypeQueryExprName::IdentifierReference(_) + | TSTypeQueryExprName::QualifiedName(_) + | TSTypeQueryExprName::ThisExpression(_) => { walk_ts_type_name(traverser, node as *mut _, ctx) } } @@ -5424,9 +5429,9 @@ unsafe fn walk_ts_module_reference<'a, State, Tr: Traverse<'a, State>>( TSModuleReference::ExternalModuleReference(node) => { walk_ts_external_module_reference(traverser, (&mut **node) as *mut _, ctx) } - TSModuleReference::IdentifierReference(_) | TSModuleReference::QualifiedName(_) => { - walk_ts_type_name(traverser, node as *mut _, ctx) - } + TSModuleReference::IdentifierReference(_) + | TSModuleReference::QualifiedName(_) + | TSModuleReference::ThisExpression(_) => walk_ts_type_name(traverser, node as *mut _, ctx), } traverser.exit_ts_module_reference(&mut *node, ctx); } diff --git a/napi/parser/generated/deserialize/js.js b/napi/parser/generated/deserialize/js.js index 074720acae566..da3e93fd93bf3 100644 --- a/napi/parser/generated/deserialize/js.js +++ b/napi/parser/generated/deserialize/js.js @@ -3639,11 +3639,11 @@ function deserializeTSTupleElement(pos) { function deserializeTSTypeName(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); + case 2: + return deserializeBoxThisExpression(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`); } @@ -3741,12 +3741,12 @@ function deserializeTSModuleDeclarationBody(pos) { function deserializeTSTypeQueryExprName(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); case 2: + return deserializeBoxThisExpression(pos + 8); + case 3: return deserializeBoxTSImportType(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`); @@ -3769,12 +3769,12 @@ function deserializeTSMappedTypeModifierOperator(pos) { function deserializeTSModuleReference(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); case 2: + return deserializeBoxThisExpression(pos + 8); + case 3: return deserializeBoxTSExternalModuleReference(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`); @@ -5224,7 +5224,7 @@ function deserializeOptionBoxObjectExpression(pos) { } function deserializeOptionTSTypeName(pos) { - if (uint8[pos] === 2) return null; + if (uint8[pos] === 3) return null; return deserializeTSTypeName(pos); } diff --git a/napi/parser/generated/deserialize/ts.js b/napi/parser/generated/deserialize/ts.js index de1ee4151e4a4..f7006757c22a9 100644 --- a/napi/parser/generated/deserialize/ts.js +++ b/napi/parser/generated/deserialize/ts.js @@ -3770,11 +3770,11 @@ function deserializeTSTupleElement(pos) { function deserializeTSTypeName(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); + case 2: + return deserializeBoxThisExpression(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeName`); } @@ -3872,12 +3872,12 @@ function deserializeTSModuleDeclarationBody(pos) { function deserializeTSTypeQueryExprName(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); case 2: + return deserializeBoxThisExpression(pos + 8); + case 3: return deserializeBoxTSImportType(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSTypeQueryExprName`); @@ -3900,12 +3900,12 @@ function deserializeTSMappedTypeModifierOperator(pos) { function deserializeTSModuleReference(pos) { switch (uint8[pos]) { case 0: - let id = deserializeBoxIdentifierReference(pos + 8); - if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end }; - return id; + return deserializeBoxIdentifierReference(pos + 8); case 1: return deserializeBoxTSQualifiedName(pos + 8); case 2: + return deserializeBoxThisExpression(pos + 8); + case 3: return deserializeBoxTSExternalModuleReference(pos + 8); default: throw new Error(`Unexpected discriminant ${uint8[pos]} for TSModuleReference`); @@ -5355,7 +5355,7 @@ function deserializeOptionBoxObjectExpression(pos) { } function deserializeOptionTSTypeName(pos) { - if (uint8[pos] === 2) return null; + if (uint8[pos] === 3) return null; return deserializeTSTypeName(pos); } diff --git a/napi/parser/generated/lazy/constructors.js b/napi/parser/generated/lazy/constructors.js index c61dca5e576fd..5b1719b2c80c6 100644 --- a/napi/parser/generated/lazy/constructors.js +++ b/napi/parser/generated/lazy/constructors.js @@ -9286,6 +9286,8 @@ function constructTSTypeName(pos, ast) { return constructBoxIdentifierReference(pos + 8, ast); case 1: return constructBoxTSQualifiedName(pos + 8, ast); + case 2: + return constructBoxThisExpression(pos + 8, ast); default: throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeName`); } @@ -10603,6 +10605,8 @@ function constructTSTypeQueryExprName(pos, ast) { case 1: return constructBoxTSQualifiedName(pos + 8, ast); case 2: + return constructBoxThisExpression(pos + 8, ast); + case 3: return constructBoxTSImportType(pos + 8, ast); default: throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeQueryExprName`); @@ -11149,6 +11153,8 @@ function constructTSModuleReference(pos, ast) { case 1: return constructBoxTSQualifiedName(pos + 8, ast); case 2: + return constructBoxThisExpression(pos + 8, ast); + case 3: return constructBoxTSExternalModuleReference(pos + 8, ast); default: throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleReference`); @@ -13729,7 +13735,7 @@ function constructOptionBoxObjectExpression(pos, ast) { } function constructOptionTSTypeName(pos, ast) { - if (ast.buffer[pos] === 2) return null; + if (ast.buffer[pos] === 3) return null; return constructTSTypeName(pos, ast); } diff --git a/napi/parser/generated/lazy/walk.js b/napi/parser/generated/lazy/walk.js index 79d287d1815f4..010ffa21dcca5 100644 --- a/napi/parser/generated/lazy/walk.js +++ b/napi/parser/generated/lazy/walk.js @@ -3707,6 +3707,9 @@ function walkTSTypeName(pos, ast, visitors) { case 1: walkBoxTSQualifiedName(pos + 8, ast, visitors); return; + case 2: + walkBoxThisExpression(pos + 8, ast, visitors); + return; default: throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSTypeName`); } @@ -4098,6 +4101,9 @@ function walkTSTypeQueryExprName(pos, ast, visitors) { walkBoxTSQualifiedName(pos + 8, ast, visitors); return; case 2: + walkBoxThisExpression(pos + 8, ast, visitors); + return; + case 3: walkBoxTSImportType(pos + 8, ast, visitors); return; default: @@ -4253,6 +4259,9 @@ function walkTSModuleReference(pos, ast, visitors) { walkBoxTSQualifiedName(pos + 8, ast, visitors); return; case 2: + walkBoxThisExpression(pos + 8, ast, visitors); + return; + case 3: walkBoxTSExternalModuleReference(pos + 8, ast, visitors); return; default: @@ -5449,7 +5458,7 @@ function walkOptionBoxObjectExpression(pos, ast, visitors) { } function walkOptionTSTypeName(pos, ast, visitors) { - if (!(ast.buffer[pos] === 2)) walkTSTypeName(pos, ast, visitors); + if (!(ast.buffer[pos] === 3)) walkTSTypeName(pos, ast, visitors); } function walkBoxTSExternalModuleReference(pos, ast, visitors) { diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 10a5103dde610..1745724aadca4 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -1175,7 +1175,7 @@ export interface TSTypeReference extends Span { typeArguments: TSTypeParameterInstantiation | null; } -export type TSTypeName = IdentifierReference | ThisExpression | TSQualifiedName; +export type TSTypeName = IdentifierReference | TSQualifiedName | ThisExpression; export interface TSQualifiedName extends Span { type: 'TSQualifiedName'; diff --git a/tasks/coverage/snapshots/semantic_babel.snap b/tasks/coverage/snapshots/semantic_babel.snap index 8f8b3a9e349a9..4610904653fc1 100644 --- a/tasks/coverage/snapshots/semantic_babel.snap +++ b/tasks/coverage/snapshots/semantic_babel.snap @@ -2,7 +2,7 @@ commit: 1d4546bc semantic_babel Summary: AST Parsed : 2362/2362 (100.00%) -Positive Passed: 1949/2362 (82.51%) +Positive Passed: 1953/2362 (82.68%) semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/decorators/decorators-after-export/input.js Symbol span mismatch for "C": after transform: SymbolId(0): Span { start: 65, end: 66 } @@ -179,16 +179,6 @@ Unresolved references mismatch: after transform: ["foo"] rebuilt : [] -semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/import-dot-this/input.js -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - -semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/import-dot-this-babel-7/input.js -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/import-with-options/input.js Symbol reference IDs mismatch for "Y": after transform: SymbolId(1): [ReferenceId(0)] @@ -1409,9 +1399,6 @@ semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescr Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] rebuilt : ScopeId(0): [] -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type-2-babel-7/input.ts Scope children mismatch: @@ -1425,9 +1412,6 @@ semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescr Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] rebuilt : ScopeId(0): [] -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/regression/nested-extends-in-arrow-type-param/input.ts Expected `,` but found `extends` @@ -2906,16 +2890,6 @@ Unresolved references mismatch: after transform: ["y"] rebuilt : [] -semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/typeof-this/input.ts -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - -semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/typeof-this-babel-7/input.ts -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/typeof-type-asi-false-parameters/input.ts Scope children mismatch: after transform: ScopeId(0): [ScopeId(1)] diff --git a/tasks/coverage/snapshots/semantic_typescript.snap b/tasks/coverage/snapshots/semantic_typescript.snap index 0536e3ac02b9c..e1888765b3dae 100644 --- a/tasks/coverage/snapshots/semantic_typescript.snap +++ b/tasks/coverage/snapshots/semantic_typescript.snap @@ -2,7 +2,7 @@ commit: 81c95189 semantic_typescript Summary: AST Parsed : 6537/6537 (100.00%) -Positive Passed: 2848/6537 (43.57%) +Positive Passed: 2851/6537 (43.61%) semantic Error: tasks/coverage/typescript/tests/cases/compiler/2dArrays.ts Symbol reference IDs mismatch for "Cell": after transform: SymbolId(0): [ReferenceId(1)] @@ -1900,9 +1900,6 @@ rebuilt : ScopeId(0): [] Scope children mismatch: after transform: ScopeId(0): [ScopeId(1)] rebuilt : ScopeId(0): [] -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] semantic Error: tasks/coverage/typescript/tests/cases/compiler/circularInstantiationExpression.ts Bindings mismatch: @@ -8321,11 +8318,6 @@ Symbol reference IDs mismatch for "a": after transform: SymbolId(1): [ReferenceId(0)] rebuilt : SymbolId(1): [] -semantic Error: tasks/coverage/typescript/tests/cases/compiler/declarationEmitTypeofThisInClass.ts -Unresolved references mismatch: -after transform: ["require", "this"] -rebuilt : ["require"] - semantic Error: tasks/coverage/typescript/tests/cases/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.ts Symbol reference IDs mismatch for "minimist": after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)] @@ -30118,9 +30110,6 @@ rebuilt : ScopeId(5): [] Scope children mismatch: after transform: ScopeId(8): [ScopeId(9)] rebuilt : ScopeId(8): [] -Unresolved references mismatch: -after transform: ["Error", "require", "this"] -rebuilt : ["Error", "require"] semantic Error: tasks/coverage/typescript/tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts Bindings mismatch: @@ -31483,11 +31472,6 @@ Unresolved references mismatch: after transform: [] rebuilt : ["Collection"] -semantic Error: tasks/coverage/typescript/tests/cases/compiler/typeofThisInMethodSignature.ts -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - semantic Error: tasks/coverage/typescript/tests/cases/compiler/typeofUndefined.ts Unresolved references mismatch: after transform: ["undefined"] @@ -51107,11 +51091,6 @@ Symbol reference IDs mismatch for "M": after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2)] rebuilt : SymbolId(1): [ReferenceId(2), ReferenceId(3)] -semantic Error: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThisWithImplicitThis.ts -Unresolved references mismatch: -after transform: ["this"] -rebuilt : [] - semantic Error: tasks/coverage/typescript/tests/cases/conformance/types/spread/objectSpread.ts Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7), ScopeId(8), ScopeId(10), ScopeId(11), ScopeId(12), ScopeId(13), ScopeId(14)] @@ -51567,7 +51546,7 @@ Reference symbol mismatch for "callsCallback": after transform: SymbolId(4) "callsCallback" rebuilt : Unresolved references mismatch: -after transform: ["this"] +after transform: [] rebuilt : ["callsCallback", "isCorrect"] semantic Error: tasks/coverage/typescript/tests/cases/conformance/types/thisType/thisTypeInInterfaces.ts diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 5f236c1eb2432..5ce5fa4c76254 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: 1d4546bc -Passed: 178/295 +Passed: 178/296 # All Passed: * babel-plugin-transform-class-static-block @@ -494,7 +494,7 @@ after transform: SymbolId(4): ScopeId(1) rebuilt : SymbolId(5): ScopeId(4) -# legacy-decorators (6/78) +# legacy-decorators (6/79) * oxc/metadata/abstract-class/input.ts Symbol reference IDs mismatch for "Dependency": after transform: SymbolId(1): [ReferenceId(1), ReferenceId(2), ReferenceId(3)] @@ -540,6 +540,14 @@ Unresolved references mismatch: after transform: ["Object", "PropertyDescriptor", "babelHelpers", "console"] rebuilt : ["Object", "babelHelpers", "console", "dec"] +* oxc/metadata/this/input.ts +Symbol span mismatch for "Example": +after transform: SymbolId(0): Span { start: 6, end: 13 } +rebuilt : SymbolId(0): Span { start: 0, end: 0 } +Symbol span mismatch for "Example": +after transform: SymbolId(2): Span { start: 0, end: 0 } +rebuilt : SymbolId(1): Span { start: 6, end: 13 } + * oxc/metadata/typescript-syntax/input.ts x TS(1249): A decorator can only decorate a method implementation, not an diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/input.ts b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/input.ts new file mode 100644 index 0000000000000..0fdd1e97feb1d --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/input.ts @@ -0,0 +1,4 @@ +class Example { + constructor(@dce a: this) {} +} + diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/output.js b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/output.js new file mode 100644 index 0000000000000..e6e05de0da7ba --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/metadata/this/output.js @@ -0,0 +1,4 @@ +let Example = class Example { + constructor(a) {} +}; +Example = babelHelpers.decorate([babelHelpers.decorateMetadata("design:paramtypes", [Object]), babelHelpers.decorateParam(0, dce)], Example);