Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ impl AstKind<'_> {
Self::TSNamespaceExportDeclaration(_) => "TSNamespaceExportDeclaration".into(),
Self::TSImportEqualsDeclaration(_) => "TSImportEqualsDeclaration".into(),
Self::TSCallSignatureDeclaration(_) => "TSCallSignatureDeclaration".into(),
Self::TSTypeName(n) => format!("TSTypeName({n})").into(),
Self::TSExternalModuleReference(_) => "TSExternalModuleReference".into(),
Self::TSQualifiedName(n) => format!("TSQualifiedName({n})").into(),
Self::TSInterfaceDeclaration(_) => "TSInterfaceDeclaration".into(),
Expand Down
85 changes: 38 additions & 47 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,45 +166,44 @@ pub enum AstType {
TSObjectKeyword = 149,
TSBigIntKeyword = 150,
TSTypeReference = 151,
TSTypeName = 152,
TSQualifiedName = 153,
TSTypeParameterInstantiation = 154,
TSTypeParameter = 155,
TSTypeParameterDeclaration = 156,
TSTypeAliasDeclaration = 157,
TSClassImplements = 158,
TSInterfaceDeclaration = 159,
TSInterfaceBody = 160,
TSPropertySignature = 161,
TSIndexSignature = 162,
TSCallSignatureDeclaration = 163,
TSMethodSignature = 164,
TSConstructSignatureDeclaration = 165,
TSIndexSignatureName = 166,
TSInterfaceHeritage = 167,
TSTypePredicate = 168,
TSModuleDeclaration = 169,
TSModuleBlock = 170,
TSTypeLiteral = 171,
TSInferType = 172,
TSTypeQuery = 173,
TSImportType = 174,
TSConstructorType = 175,
TSMappedType = 176,
TSTemplateLiteralType = 177,
TSAsExpression = 178,
TSSatisfiesExpression = 179,
TSTypeAssertion = 180,
TSImportEqualsDeclaration = 181,
TSExternalModuleReference = 182,
TSNonNullExpression = 183,
Decorator = 184,
TSExportAssignment = 185,
TSNamespaceExportDeclaration = 186,
TSInstantiationExpression = 187,
JSDocNullableType = 188,
JSDocNonNullableType = 189,
JSDocUnknownType = 190,
TSQualifiedName = 152,
TSTypeParameterInstantiation = 153,
TSTypeParameter = 154,
TSTypeParameterDeclaration = 155,
TSTypeAliasDeclaration = 156,
TSClassImplements = 157,
TSInterfaceDeclaration = 158,
TSInterfaceBody = 159,
TSPropertySignature = 160,
TSIndexSignature = 161,
TSCallSignatureDeclaration = 162,
TSMethodSignature = 163,
TSConstructSignatureDeclaration = 164,
TSIndexSignatureName = 165,
TSInterfaceHeritage = 166,
TSTypePredicate = 167,
TSModuleDeclaration = 168,
TSModuleBlock = 169,
TSTypeLiteral = 170,
TSInferType = 171,
TSTypeQuery = 172,
TSImportType = 173,
TSConstructorType = 174,
TSMappedType = 175,
TSTemplateLiteralType = 176,
TSAsExpression = 177,
TSSatisfiesExpression = 178,
TSTypeAssertion = 179,
TSImportEqualsDeclaration = 180,
TSExternalModuleReference = 181,
TSNonNullExpression = 182,
Decorator = 183,
TSExportAssignment = 184,
TSNamespaceExportDeclaration = 185,
TSInstantiationExpression = 186,
JSDocNullableType = 187,
JSDocNonNullableType = 188,
JSDocUnknownType = 189,
}

/// Untyped AST Node Kind
Expand Down Expand Up @@ -373,7 +372,6 @@ pub enum AstKind<'a> {
TSObjectKeyword(&'a TSObjectKeyword) = AstType::TSObjectKeyword as u8,
TSBigIntKeyword(&'a TSBigIntKeyword) = AstType::TSBigIntKeyword as u8,
TSTypeReference(&'a TSTypeReference<'a>) = AstType::TSTypeReference as u8,
TSTypeName(&'a TSTypeName<'a>) = AstType::TSTypeName as u8,
TSQualifiedName(&'a TSQualifiedName<'a>) = AstType::TSQualifiedName as u8,
TSTypeParameterInstantiation(&'a TSTypeParameterInstantiation<'a>) =
AstType::TSTypeParameterInstantiation as u8,
Expand Down Expand Up @@ -589,7 +587,6 @@ impl GetSpan for AstKind<'_> {
Self::TSObjectKeyword(it) => it.span(),
Self::TSBigIntKeyword(it) => it.span(),
Self::TSTypeReference(it) => it.span(),
Self::TSTypeName(it) => it.span(),
Self::TSQualifiedName(it) => it.span(),
Self::TSTypeParameterInstantiation(it) => it.span(),
Self::TSTypeParameter(it) => it.span(),
Expand Down Expand Up @@ -787,7 +784,6 @@ impl GetAddress for AstKind<'_> {
Self::TSObjectKeyword(it) => Address::from_ptr(it),
Self::TSBigIntKeyword(it) => Address::from_ptr(it),
Self::TSTypeReference(it) => Address::from_ptr(it),
Self::TSTypeName(it) => it.address(),
Self::TSQualifiedName(it) => Address::from_ptr(it),
Self::TSTypeParameterInstantiation(it) => Address::from_ptr(it),
Self::TSTypeParameter(it) => Address::from_ptr(it),
Expand Down Expand Up @@ -1595,11 +1591,6 @@ impl<'a> AstKind<'a> {
if let Self::TSTypeReference(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_type_name(self) -> Option<&'a TSTypeName<'a>> {
if let Self::TSTypeName(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_qualified_name(self) -> Option<&'a TSQualifiedName<'a>> {
if let Self::TSQualifiedName(v) = self { Some(v) } else { None }
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3555,13 +3555,11 @@ pub mod walk {

#[inline]
pub fn walk_ts_type_name<'a, V: Visit<'a>>(visitor: &mut V, it: &TSTypeName<'a>) {
let kind = AstKind::TSTypeName(visitor.alloc(it));
visitor.enter_node(kind);
// No `AstKind` for this type
match it {
TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it),
TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it),
}
visitor.leave_node(kind);
}

#[inline]
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3743,13 +3743,11 @@ pub mod walk_mut {

#[inline]
pub fn walk_ts_type_name<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut TSTypeName<'a>) {
let kind = AstType::TSTypeName;
visitor.enter_node(kind);
// No `AstType` for this type
match it {
TSTypeName::IdentifierReference(it) => visitor.visit_identifier_reference(it),
TSTypeName::QualifiedName(it) => visitor.visit_ts_qualified_name(it),
}
visitor.leave_node(kind);
}

#[inline]
Expand Down
37 changes: 19 additions & 18 deletions crates/oxc_formatter/src/generated/ast_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ pub enum AstNodes<'a> {
TSObjectKeyword(&'a AstNode<'a, TSObjectKeyword>),
TSBigIntKeyword(&'a AstNode<'a, TSBigIntKeyword>),
TSTypeReference(&'a AstNode<'a, TSTypeReference<'a>>),
TSTypeName(&'a AstNode<'a, TSTypeName<'a>>),
TSQualifiedName(&'a AstNode<'a, TSQualifiedName<'a>>),
TSTypeParameterInstantiation(&'a AstNode<'a, TSTypeParameterInstantiation<'a>>),
TSTypeParameter(&'a AstNode<'a, TSTypeParameter<'a>>),
Expand Down Expand Up @@ -2470,7 +2469,6 @@ impl<'a> AstNodes<'a> {
Self::TSObjectKeyword(n) => n.span(),
Self::TSBigIntKeyword(n) => n.span(),
Self::TSTypeReference(n) => n.span(),
Self::TSTypeName(n) => n.span(),
Self::TSQualifiedName(n) => n.span(),
Self::TSTypeParameterInstantiation(n) => n.span(),
Self::TSTypeParameter(n) => n.span(),
Expand Down Expand Up @@ -2667,7 +2665,6 @@ impl<'a> AstNodes<'a> {
Self::TSObjectKeyword(n) => n.parent,
Self::TSBigIntKeyword(n) => n.parent,
Self::TSTypeReference(n) => n.parent,
Self::TSTypeName(n) => n.parent,
Self::TSQualifiedName(n) => n.parent,
Self::TSTypeParameterInstantiation(n) => n.parent,
Self::TSTypeParameter(n) => n.parent,
Expand Down Expand Up @@ -2864,7 +2861,6 @@ impl<'a> AstNodes<'a> {
Self::TSObjectKeyword(n) => SiblingNode::from(n.inner),
Self::TSBigIntKeyword(n) => SiblingNode::from(n.inner),
Self::TSTypeReference(n) => SiblingNode::from(n.inner),
Self::TSTypeName(n) => n.parent.as_sibling_node(),
Self::TSQualifiedName(n) => SiblingNode::from(n.inner),
Self::TSTypeParameterInstantiation(n) => SiblingNode::from(n.inner),
Self::TSTypeParameter(n) => SiblingNode::from(n.inner),
Expand Down Expand Up @@ -3061,7 +3057,6 @@ impl<'a> AstNodes<'a> {
Self::TSObjectKeyword(_) => "TSObjectKeyword",
Self::TSBigIntKeyword(_) => "TSBigIntKeyword",
Self::TSTypeReference(_) => "TSTypeReference",
Self::TSTypeName(_) => "TSTypeName",
Self::TSQualifiedName(_) => "TSQualifiedName",
Self::TSTypeParameterInstantiation(_) => "TSTypeParameterInstantiation",
Self::TSTypeParameter(_) => "TSTypeParameter",
Expand Down Expand Up @@ -11497,7 +11492,7 @@ impl<'a> AstNode<'a, TSTypeReference<'a>> {
impl<'a> AstNode<'a, TSTypeName<'a>> {
#[inline]
pub fn as_ast_nodes(&self) -> &AstNodes<'a> {
let parent = self.allocator.alloc(AstNodes::TSTypeName(transmute_self(self)));
let parent = self.parent;
let node = match self.inner {
TSTypeName::IdentifierReference(s) => {
AstNodes::IdentifierReference(self.allocator.alloc(AstNode {
Expand Down Expand Up @@ -12829,12 +12824,15 @@ impl<'a> AstNode<'a, TSTypeQueryExprName<'a>> {
}))
}
it @ match_ts_type_name!(TSTypeQueryExprName) => {
AstNodes::TSTypeName(self.allocator.alloc(AstNode {
inner: it.to_ts_type_name(),
parent,
allocator: self.allocator,
following_node: self.following_node,
}))
return self
.allocator
.alloc(AstNode {
inner: it.to_ts_type_name(),
parent,
allocator: self.allocator,
following_node: self.following_node,
})
.as_ast_nodes();
}
};
self.allocator.alloc(node)
Expand Down Expand Up @@ -13375,12 +13373,15 @@ impl<'a> AstNode<'a, TSModuleReference<'a>> {
}))
}
it @ match_ts_type_name!(TSModuleReference) => {
AstNodes::TSTypeName(self.allocator.alloc(AstNode {
inner: it.to_ts_type_name(),
parent,
allocator: self.allocator,
following_node: self.following_node,
}))
return self
.allocator
.alloc(AstNode {
inner: it.to_ts_type_name(),
parent,
allocator: self.allocator,
following_node: self.following_node,
})
.as_ast_nodes();
}
};
self.allocator.alloc(node)
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_formatter/src/generated/format_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSTypeName<'a>> {
#[inline]
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
let allocator = self.allocator;
let parent = allocator.alloc(AstNodes::TSTypeName(transmute_self(self)));
let parent = self.parent;
match self.inner {
TSTypeName::IdentifierReference(inner) => allocator
.alloc(AstNode::<IdentifierReference> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ impl<'a> Symbol<'_, 'a> {
loop {
node = match node.kind() {
AstKind::TSTypeQuery(_) => return true,
AstKind::TSQualifiedName(_) | AstKind::TSTypeName(_) => {
AstKind::TSQualifiedName(_) | AstKind::IdentifierReference(_) => {
if let Some(parent) = self.nodes().parent_node(node.id()) {
parent
} else {
Expand Down
45 changes: 24 additions & 21 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,28 +2034,28 @@ impl<'a> SemanticBuilder<'a> {
// ^^^ avoid treat T as a value and TSTypeQuery
self.current_reference_flags -= ReferenceFlags::ValueAsType;
}
AstKind::TSTypeName(_) => {
match self.nodes.parent_kind(self.current_node_id) {
Some(
// import A = a;
// ^
AstKind::TSImportEqualsDeclaration(_),
) => {
self.current_reference_flags = ReferenceFlags::Read;
}
Some(AstKind::TSQualifiedName(_)) => {
// import A = a.b
// ^^^ Keep the current reference flag
}
_ => {
// Handled in `AstKind::PropertySignature` or `AstKind::TSTypeQuery`
if !self.current_reference_flags.is_value_as_type() {
self.current_reference_flags = ReferenceFlags::Type;
}
}
AstKind::TSClassImplements(_) | AstKind::TSTypeReference(_) => {
// type X = SomeType;
// ^^^^^^^^
//
// class A implements B {}
// ^^^^^^^^^^^^
//
// let X: import('module').Y;
// ^^^^^^^^^^^^^^^^
if !self.current_reference_flags.is_value_as_type() {
self.current_reference_flags = ReferenceFlags::Type;
}
}
AstKind::IdentifierReference(ident) => {
if let Some(AstKind::TSImportType(_)) = self.nodes.parent_kind(self.current_node_id)
{
// let X: import('module').X
// ^
// We don't want to treat this as a value reference.
self.current_reference_flags = ReferenceFlags::Type;
}

self.reference_identifier(ident);
}
AstKind::LabeledStatement(stmt) => {
Expand Down Expand Up @@ -2093,8 +2093,11 @@ impl<'a> SemanticBuilder<'a> {
AstKind::CatchParameter(_) => {
self.resolve_references_for_current_scope();
}
AstKind::TSTypeName(_) => {
self.current_reference_flags -= ReferenceFlags::Type;
AstKind::IdentifierReference(_) | AstKind::TSQualifiedName(_) => {
if matches!(self.nodes.parent_kind(self.current_node_id), Some(AstKind::TSImportType(_) | AstKind::TSTypeReference(_) | AstKind::TSClassImplements(_))) {
// Clear the type reference flags that were set in `enter_kind` for these kinds.
self.current_reference_flags -= ReferenceFlags::Type;
}
}
AstKind::TSTypeQuery(_)
// Clear the reference flags that are set in AstKind::PropertySignature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.ts
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "T",
"node_id": 12
"node_id": 11
},
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 27
"node_id": 25
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-t
"flags": "ReferenceFlags(Type)",
"id": 2,
"name": "X",
"node_id": 29
"node_id": 28
}
]
},
Expand All @@ -61,13 +61,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/interfaces/property-with-t
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "B",
"node_id": 20
"node_id": 19
},
{
"flags": "ReferenceFlags(Type)",
"id": 3,
"name": "B",
"node_id": 34
"node_id": 32
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/namespaces/value-module.ts
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "N1",
"node_id": 22
"node_id": 20
},
{
"flags": "ReferenceFlags(Read)",
"id": 1,
"name": "N1",
"node_id": 28
"node_id": 26
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 11
"node_id": 10
}
]
}
Expand Down
Loading
Loading