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
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5201,7 +5201,7 @@ function deserializeTSConstructorType(pos) {
node = parent = {
__proto__: NodeProto,
type: 'TSConstructorType',
abstract: deserializeBool(pos + 32),
abstract: deserializeBool(pos + 36),
typeParameters: null,
params: null,
returnType: null,
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ pub struct TSFunctionType<'a> {
}

#[ast(visit)]
#[scope]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct TSConstructorType<'a> {
Expand All @@ -1454,6 +1455,7 @@ pub struct TSConstructorType<'a> {
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
pub params: Box<'a, FormalParameters<'a>>,
pub return_type: Box<'a, TSTypeAnnotation<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}

/// TypeScript Mapped Type
Expand Down
10 changes: 6 additions & 4 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,14 +1468,15 @@ const _: () = {
assert!(offset_of!(TSFunctionType, return_type) == 32);
assert!(offset_of!(TSFunctionType, scope_id) == 40);

// Padding: 7 bytes
// Padding: 3 bytes
assert!(size_of::<TSConstructorType>() == 40);
assert!(align_of::<TSConstructorType>() == 8);
assert!(offset_of!(TSConstructorType, span) == 0);
assert!(offset_of!(TSConstructorType, r#abstract) == 32);
assert!(offset_of!(TSConstructorType, r#abstract) == 36);
assert!(offset_of!(TSConstructorType, type_parameters) == 8);
assert!(offset_of!(TSConstructorType, params) == 16);
assert!(offset_of!(TSConstructorType, return_type) == 24);
assert!(offset_of!(TSConstructorType, scope_id) == 32);

// Padding: 2 bytes
assert!(size_of::<TSMappedType>() == 56);
Expand Down Expand Up @@ -3075,13 +3076,14 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(offset_of!(TSFunctionType, scope_id) == 24);

// Padding: 3 bytes
assert!(size_of::<TSConstructorType>() == 24);
assert!(size_of::<TSConstructorType>() == 28);
assert!(align_of::<TSConstructorType>() == 4);
assert!(offset_of!(TSConstructorType, span) == 0);
assert!(offset_of!(TSConstructorType, r#abstract) == 20);
assert!(offset_of!(TSConstructorType, r#abstract) == 24);
assert!(offset_of!(TSConstructorType, type_parameters) == 8);
assert!(offset_of!(TSConstructorType, params) == 12);
assert!(offset_of!(TSConstructorType, return_type) == 16);
assert!(offset_of!(TSConstructorType, scope_id) == 20);

// Padding: 2 bytes
assert!(size_of::<TSMappedType>() == 36);
Expand Down
114 changes: 114 additions & 0 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10455,6 +10455,42 @@ impl<'a> AstBuilder<'a> {
))
}

/// Build a [`TSType::TSConstructorType`] with `scope_id`.
///
/// This node contains a [`TSConstructorType`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `abstract`
/// * `type_parameters`
/// * `params`
/// * `return_type`
/// * `scope_id`
#[inline]
pub fn ts_type_constructor_type_with_scope_id<T1, T2, T3>(
self,
span: Span,
r#abstract: bool,
type_parameters: T1,
params: T2,
return_type: T3,
scope_id: ScopeId,
) -> TSType<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
T3: IntoIn<'a, Box<'a, TSTypeAnnotation<'a>>>,
{
TSType::TSConstructorType(self.alloc_ts_constructor_type_with_scope_id(
span,
r#abstract,
type_parameters,
params,
return_type,
scope_id,
))
}

/// Build a [`TSType::TSFunctionType`].
///
/// This node contains a [`TSFunctionType`] that will be stored in the memory arena.
Expand Down Expand Up @@ -14174,6 +14210,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: type_parameters.into_in(self.allocator),
params: params.into_in(self.allocator),
return_type: return_type.into_in(self.allocator),
scope_id: Default::default(),
}
}

Expand Down Expand Up @@ -14208,6 +14245,83 @@ impl<'a> AstBuilder<'a> {
)
}

/// Build a [`TSConstructorType`] with `scope_id`.
///
/// If you want the built node to be allocated in the memory arena,
/// use [`AstBuilder::alloc_ts_constructor_type_with_scope_id`] instead.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `abstract`
/// * `type_parameters`
/// * `params`
/// * `return_type`
/// * `scope_id`
#[inline]
pub fn ts_constructor_type_with_scope_id<T1, T2, T3>(
self,
span: Span,
r#abstract: bool,
type_parameters: T1,
params: T2,
return_type: T3,
scope_id: ScopeId,
) -> TSConstructorType<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
T3: IntoIn<'a, Box<'a, TSTypeAnnotation<'a>>>,
{
TSConstructorType {
span,
r#abstract,
type_parameters: type_parameters.into_in(self.allocator),
params: params.into_in(self.allocator),
return_type: return_type.into_in(self.allocator),
scope_id: Cell::new(Some(scope_id)),
}
}

/// Build a [`TSConstructorType`] with `scope_id`, and store it in the memory arena.
///
/// Returns a [`Box`] containing the newly-allocated node.
/// If you want a stack-allocated node, use [`AstBuilder::ts_constructor_type_with_scope_id`] instead.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `abstract`
/// * `type_parameters`
/// * `params`
/// * `return_type`
/// * `scope_id`
#[inline]
pub fn alloc_ts_constructor_type_with_scope_id<T1, T2, T3>(
self,
span: Span,
r#abstract: bool,
type_parameters: T1,
params: T2,
return_type: T3,
scope_id: ScopeId,
) -> Box<'a, TSConstructorType<'a>>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
T3: IntoIn<'a, Box<'a, TSTypeAnnotation<'a>>>,
{
Box::new_in(
self.ts_constructor_type_with_scope_id(
span,
r#abstract,
type_parameters,
params,
return_type,
scope_id,
),
self.allocator,
)
}

/// Build a [`TSMappedType`].
///
/// If you want the built node to be allocated in the memory arena,
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7532,6 +7532,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSConstructorType<'_> {
type_parameters: CloneIn::clone_in(&self.type_parameters, allocator),
params: CloneIn::clone_in(&self.params, allocator),
return_type: CloneIn::clone_in(&self.return_type, allocator),
scope_id: Default::default(),
}
}

Expand All @@ -7542,6 +7543,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSConstructorType<'_> {
type_parameters: CloneIn::clone_in_with_semantic_ids(&self.type_parameters, allocator),
params: CloneIn::clone_in_with_semantic_ids(&self.params, allocator),
return_type: CloneIn::clone_in_with_semantic_ids(&self.return_type, allocator),
scope_id: CloneIn::clone_in_with_semantic_ids(&self.scope_id, allocator),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ impl<'a> Dummy<'a> for TSConstructorType<'a> {
type_parameters: Dummy::dummy(allocator),
params: Dummy::dummy(allocator),
return_type: Dummy::dummy(allocator),
scope_id: Dummy::dummy(allocator),
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions crates/oxc_ast/src/generated/get_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,25 @@ impl TSFunctionType<'_> {
}
}

impl TSConstructorType<'_> {
/// Get [`ScopeId`] of [`TSConstructorType`].
///
/// Only use this method on a post-semantic AST where [`ScopeId`]s are always defined.
///
/// # Panics
/// Panics if `scope_id` is [`None`].
#[inline]
pub fn scope_id(&self) -> ScopeId {
self.scope_id.get().unwrap()
}

/// Set [`ScopeId`] of [`TSConstructorType`].
#[inline]
pub fn set_scope_id(&self, scope_id: ScopeId) {
self.scope_id.set(Some(scope_id));
}
}

impl TSMappedType<'_> {
/// Get [`ScopeId`] of [`TSMappedType`].
///
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_macros/src/generated/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub static STRUCTS: phf::Map<&'static str, StructDetails> = ::phf::Map {
("DoWhileStatement", StructDetails { field_order: None }),
("ReturnStatement", StructDetails { field_order: None }),
("TSImportType", StructDetails { field_order: None }),
("TSConstructorType", StructDetails { field_order: Some(&[0, 4, 1, 2, 3]) }),
("TSConstructorType", StructDetails { field_order: Some(&[0, 5, 1, 2, 3, 4]) }),
("TSImportEqualsDeclaration", StructDetails { field_order: None }),
("RegExpLiteral", StructDetails { field_order: None }),
("LogicalExpression", StructDetails { field_order: Some(&[0, 1, 3, 2]) }),
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3998,12 +3998,14 @@ pub mod walk {
pub fn walk_ts_constructor_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSConstructorType<'a>) {
let kind = AstKind::TSConstructorType(visitor.alloc(it));
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
visitor.visit_span(&it.span);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
visitor.visit_formal_parameters(&it.params);
visitor.visit_ts_type_annotation(&it.return_type);
visitor.leave_scope();
visitor.leave_node(kind);
}

Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4213,12 +4213,14 @@ pub mod walk_mut {
) {
let kind = AstType::TSConstructorType;
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
visitor.visit_span(&mut it.span);
if let Some(type_parameters) = &mut it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
visitor.visit_formal_parameters(&mut it.params);
visitor.visit_ts_type_annotation(&mut it.return_type);
visitor.leave_scope();
visitor.leave_node(kind);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"symbols": []
},
{
"children": [],
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructorType",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAliasDeclaration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"symbols": []
},
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAliasDeclaration",
"symbols": [
"children": [
{
"flags": "SymbolFlags(TypeParameter)",
"id": 2,
"name": "U",
"node": "TSTypeParameter(U)",
"references": [
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructorType",
"symbols": [
{
"flags": "ReferenceFlags(Type)",
"id": 0,
"flags": "SymbolFlags(TypeParameter)",
"id": 2,
"name": "U",
"node_id": 16
"node": "TSTypeParameter(U)",
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "U",
"node_id": 16
}
]
}
]
}
]
],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAliasDeclaration",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode | Top)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"symbols": []
},
{
"children": [],
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructorType",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSTypeAliasDeclaration",
Expand Down
Loading
Loading