Skip to content

Commit c125ad6

Browse files
committed
feat(semantic): add scope to TSCallSignatureDeclaration
1 parent 12a9934 commit c125ad6

File tree

11 files changed

+195
-13
lines changed

11 files changed

+195
-13
lines changed

crates/oxc_ast/src/ast/ts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ pub struct TSIndexSignature<'a> {
10271027
}
10281028

10291029
#[ast(visit)]
1030+
#[scope]
10301031
#[derive(Debug)]
10311032
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
10321033
pub struct TSCallSignatureDeclaration<'a> {
@@ -1037,6 +1038,7 @@ pub struct TSCallSignatureDeclaration<'a> {
10371038
#[estree(via = TSCallSignatureDeclarationParams)]
10381039
pub params: Box<'a, FormalParameters<'a>>,
10391040
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
1041+
pub scope_id: Cell<Option<ScopeId>>,
10401042
}
10411043

10421044
#[ast]

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,14 +1329,15 @@ const _: () = {
13291329
assert!(offset_of!(TSIndexSignature, readonly) == 40);
13301330
assert!(offset_of!(TSIndexSignature, r#static) == 41);
13311331

1332-
// Padding: 0 bytes
1333-
assert!(size_of::<TSCallSignatureDeclaration>() == 40);
1332+
// Padding: 4 bytes
1333+
assert!(size_of::<TSCallSignatureDeclaration>() == 48);
13341334
assert!(align_of::<TSCallSignatureDeclaration>() == 8);
13351335
assert!(offset_of!(TSCallSignatureDeclaration, span) == 0);
13361336
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 8);
13371337
assert!(offset_of!(TSCallSignatureDeclaration, this_param) == 16);
13381338
assert!(offset_of!(TSCallSignatureDeclaration, params) == 24);
13391339
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 32);
1340+
assert!(offset_of!(TSCallSignatureDeclaration, scope_id) == 40);
13401341

13411342
assert!(size_of::<TSMethodSignatureKind>() == 1);
13421343
assert!(align_of::<TSMethodSignatureKind>() == 1);
@@ -2934,13 +2935,14 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
29342935
assert!(offset_of!(TSIndexSignature, r#static) == 29);
29352936

29362937
// Padding: 0 bytes
2937-
assert!(size_of::<TSCallSignatureDeclaration>() == 24);
2938+
assert!(size_of::<TSCallSignatureDeclaration>() == 28);
29382939
assert!(align_of::<TSCallSignatureDeclaration>() == 4);
29392940
assert!(offset_of!(TSCallSignatureDeclaration, span) == 0);
29402941
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 8);
29412942
assert!(offset_of!(TSCallSignatureDeclaration, this_param) == 12);
29422943
assert!(offset_of!(TSCallSignatureDeclaration, params) == 16);
29432944
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 20);
2945+
assert!(offset_of!(TSCallSignatureDeclaration, scope_id) == 24);
29442946

29452947
assert!(size_of::<TSMethodSignatureKind>() == 1);
29462948
assert!(align_of::<TSMethodSignatureKind>() == 1);

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12485,6 +12485,45 @@ impl<'a> AstBuilder<'a> {
1248512485
))
1248612486
}
1248712487

12488+
/// Build a [`TSSignature::TSCallSignatureDeclaration`] with `scope_id`.
12489+
///
12490+
/// This node contains a [`TSCallSignatureDeclaration`] that will be stored in the memory arena.
12491+
///
12492+
/// ## Parameters
12493+
/// * `span`: The [`Span`] covering this node
12494+
/// * `type_parameters`
12495+
/// * `this_param`
12496+
/// * `params`
12497+
/// * `return_type`
12498+
/// * `scope_id`
12499+
#[inline]
12500+
pub fn ts_signature_call_signature_declaration_with_scope_id<T1, T2, T3, T4>(
12501+
self,
12502+
span: Span,
12503+
type_parameters: T1,
12504+
this_param: T2,
12505+
params: T3,
12506+
return_type: T4,
12507+
scope_id: ScopeId,
12508+
) -> TSSignature<'a>
12509+
where
12510+
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
12511+
T2: IntoIn<'a, Option<Box<'a, TSThisParameter<'a>>>>,
12512+
T3: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
12513+
T4: IntoIn<'a, Option<Box<'a, TSTypeAnnotation<'a>>>>,
12514+
{
12515+
TSSignature::TSCallSignatureDeclaration(
12516+
self.alloc_ts_call_signature_declaration_with_scope_id(
12517+
span,
12518+
type_parameters,
12519+
this_param,
12520+
params,
12521+
return_type,
12522+
scope_id,
12523+
),
12524+
)
12525+
}
12526+
1248812527
/// Build a [`TSSignature::TSConstructSignatureDeclaration`].
1248912528
///
1249012529
/// This node contains a [`TSConstructSignatureDeclaration`] that will be stored in the memory arena.
@@ -12738,6 +12777,7 @@ impl<'a> AstBuilder<'a> {
1273812777
this_param: this_param.into_in(self.allocator),
1273912778
params: params.into_in(self.allocator),
1274012779
return_type: return_type.into_in(self.allocator),
12780+
scope_id: Default::default(),
1274112781
}
1274212782
}
1274312783

@@ -12779,6 +12819,85 @@ impl<'a> AstBuilder<'a> {
1277912819
)
1278012820
}
1278112821

12822+
/// Build a [`TSCallSignatureDeclaration`] with `scope_id`.
12823+
///
12824+
/// If you want the built node to be allocated in the memory arena,
12825+
/// use [`AstBuilder::alloc_ts_call_signature_declaration_with_scope_id`] instead.
12826+
///
12827+
/// ## Parameters
12828+
/// * `span`: The [`Span`] covering this node
12829+
/// * `type_parameters`
12830+
/// * `this_param`
12831+
/// * `params`
12832+
/// * `return_type`
12833+
/// * `scope_id`
12834+
#[inline]
12835+
pub fn ts_call_signature_declaration_with_scope_id<T1, T2, T3, T4>(
12836+
self,
12837+
span: Span,
12838+
type_parameters: T1,
12839+
this_param: T2,
12840+
params: T3,
12841+
return_type: T4,
12842+
scope_id: ScopeId,
12843+
) -> TSCallSignatureDeclaration<'a>
12844+
where
12845+
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
12846+
T2: IntoIn<'a, Option<Box<'a, TSThisParameter<'a>>>>,
12847+
T3: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
12848+
T4: IntoIn<'a, Option<Box<'a, TSTypeAnnotation<'a>>>>,
12849+
{
12850+
TSCallSignatureDeclaration {
12851+
span,
12852+
type_parameters: type_parameters.into_in(self.allocator),
12853+
this_param: this_param.into_in(self.allocator),
12854+
params: params.into_in(self.allocator),
12855+
return_type: return_type.into_in(self.allocator),
12856+
scope_id: Cell::new(Some(scope_id)),
12857+
}
12858+
}
12859+
12860+
/// Build a [`TSCallSignatureDeclaration`] with `scope_id`, and store it in the memory arena.
12861+
///
12862+
/// Returns a [`Box`] containing the newly-allocated node.
12863+
/// If you want a stack-allocated node, use [`AstBuilder::ts_call_signature_declaration_with_scope_id`] instead.
12864+
///
12865+
/// ## Parameters
12866+
/// * `span`: The [`Span`] covering this node
12867+
/// * `type_parameters`
12868+
/// * `this_param`
12869+
/// * `params`
12870+
/// * `return_type`
12871+
/// * `scope_id`
12872+
#[inline]
12873+
pub fn alloc_ts_call_signature_declaration_with_scope_id<T1, T2, T3, T4>(
12874+
self,
12875+
span: Span,
12876+
type_parameters: T1,
12877+
this_param: T2,
12878+
params: T3,
12879+
return_type: T4,
12880+
scope_id: ScopeId,
12881+
) -> Box<'a, TSCallSignatureDeclaration<'a>>
12882+
where
12883+
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
12884+
T2: IntoIn<'a, Option<Box<'a, TSThisParameter<'a>>>>,
12885+
T3: IntoIn<'a, Box<'a, FormalParameters<'a>>>,
12886+
T4: IntoIn<'a, Option<Box<'a, TSTypeAnnotation<'a>>>>,
12887+
{
12888+
Box::new_in(
12889+
self.ts_call_signature_declaration_with_scope_id(
12890+
span,
12891+
type_parameters,
12892+
this_param,
12893+
params,
12894+
return_type,
12895+
scope_id,
12896+
),
12897+
self.allocator,
12898+
)
12899+
}
12900+
1278212901
/// Build a [`TSMethodSignature`].
1278312902
///
1278412903
/// If you want the built node to be allocated in the memory arena,

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7044,6 +7044,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSCallSignatureDeclaration<'_> {
70447044
this_param: CloneIn::clone_in(&self.this_param, allocator),
70457045
params: CloneIn::clone_in(&self.params, allocator),
70467046
return_type: CloneIn::clone_in(&self.return_type, allocator),
7047+
scope_id: Default::default(),
70477048
}
70487049
}
70497050

@@ -7054,6 +7055,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSCallSignatureDeclaration<'_> {
70547055
this_param: CloneIn::clone_in_with_semantic_ids(&self.this_param, allocator),
70557056
params: CloneIn::clone_in_with_semantic_ids(&self.params, allocator),
70567057
return_type: CloneIn::clone_in_with_semantic_ids(&self.return_type, allocator),
7058+
scope_id: CloneIn::clone_in_with_semantic_ids(&self.scope_id, allocator),
70577059
}
70587060
}
70597061
}

crates/oxc_ast/src/generated/derive_dummy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ impl<'a> Dummy<'a> for TSCallSignatureDeclaration<'a> {
24232423
this_param: Dummy::dummy(allocator),
24242424
params: Dummy::dummy(allocator),
24252425
return_type: Dummy::dummy(allocator),
2426+
scope_id: Dummy::dummy(allocator),
24262427
}
24272428
}
24282429
}

crates/oxc_ast/src/generated/get_id.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,25 @@ impl TSInterfaceDeclaration<'_> {
328328
}
329329
}
330330

331+
impl TSCallSignatureDeclaration<'_> {
332+
/// Get [`ScopeId`] of [`TSCallSignatureDeclaration`].
333+
///
334+
/// Only use this method on a post-semantic AST where [`ScopeId`]s are always defined.
335+
///
336+
/// # Panics
337+
/// Panics if `scope_id` is [`None`].
338+
#[inline]
339+
pub fn scope_id(&self) -> ScopeId {
340+
self.scope_id.get().unwrap()
341+
}
342+
343+
/// Set [`ScopeId`] of [`TSCallSignatureDeclaration`].
344+
#[inline]
345+
pub fn set_scope_id(&self, scope_id: ScopeId) {
346+
self.scope_id.set(Some(scope_id));
347+
}
348+
}
349+
331350
impl TSMethodSignature<'_> {
332351
/// Get [`ScopeId`] of [`TSMethodSignature`].
333352
///

crates/oxc_ast_visit/src/generated/visit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,6 +3716,7 @@ pub mod walk {
37163716
) {
37173717
let kind = AstKind::TSCallSignatureDeclaration(visitor.alloc(it));
37183718
visitor.enter_node(kind);
3719+
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
37193720
visitor.visit_span(&it.span);
37203721
if let Some(type_parameters) = &it.type_parameters {
37213722
visitor.visit_ts_type_parameter_declaration(type_parameters);
@@ -3727,6 +3728,7 @@ pub mod walk {
37273728
if let Some(return_type) = &it.return_type {
37283729
visitor.visit_ts_type_annotation(return_type);
37293730
}
3731+
visitor.leave_scope();
37303732
visitor.leave_node(kind);
37313733
}
37323734

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,6 +3919,7 @@ pub mod walk_mut {
39193919
) {
39203920
let kind = AstType::TSCallSignatureDeclaration;
39213921
visitor.enter_node(kind);
3922+
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
39223923
visitor.visit_span(&mut it.span);
39233924
if let Some(type_parameters) = &mut it.type_parameters {
39243925
visitor.visit_ts_type_parameter_declaration(type_parameters);
@@ -3930,6 +3931,7 @@ pub mod walk_mut {
39303931
if let Some(return_type) = &mut it.return_type {
39313932
visitor.visit_ts_type_annotation(return_type);
39323933
}
3934+
visitor.leave_scope();
39333935
visitor.leave_node(kind);
39343936
}
39353937

crates/oxc_traverse/src/generated/ancestor.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12986,6 +12986,8 @@ pub(crate) const OFFSET_TS_CALL_SIGNATURE_DECLARATION_PARAMS: usize =
1298612986
offset_of!(TSCallSignatureDeclaration, params);
1298712987
pub(crate) const OFFSET_TS_CALL_SIGNATURE_DECLARATION_RETURN_TYPE: usize =
1298812988
offset_of!(TSCallSignatureDeclaration, return_type);
12989+
pub(crate) const OFFSET_TS_CALL_SIGNATURE_DECLARATION_SCOPE_ID: usize =
12990+
offset_of!(TSCallSignatureDeclaration, scope_id);
1298912991

1299012992
#[repr(transparent)]
1299112993
#[derive(Clone, Copy, Debug)]
@@ -13025,6 +13027,14 @@ impl<'a, 't> TSCallSignatureDeclarationWithoutTypeParameters<'a, 't> {
1302513027
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
1302613028
}
1302713029
}
13030+
13031+
#[inline]
13032+
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
13033+
unsafe {
13034+
&*((self.0 as *const u8).add(OFFSET_TS_CALL_SIGNATURE_DECLARATION_SCOPE_ID)
13035+
as *const Cell<Option<ScopeId>>)
13036+
}
13037+
}
1302813038
}
1302913039

1303013040
impl<'a, 't> GetAddress for TSCallSignatureDeclarationWithoutTypeParameters<'a, 't> {
@@ -13072,6 +13082,14 @@ impl<'a, 't> TSCallSignatureDeclarationWithoutThisParam<'a, 't> {
1307213082
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
1307313083
}
1307413084
}
13085+
13086+
#[inline]
13087+
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
13088+
unsafe {
13089+
&*((self.0 as *const u8).add(OFFSET_TS_CALL_SIGNATURE_DECLARATION_SCOPE_ID)
13090+
as *const Cell<Option<ScopeId>>)
13091+
}
13092+
}
1307513093
}
1307613094

1307713095
impl<'a, 't> GetAddress for TSCallSignatureDeclarationWithoutThisParam<'a, 't> {
@@ -13119,6 +13137,14 @@ impl<'a, 't> TSCallSignatureDeclarationWithoutParams<'a, 't> {
1311913137
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
1312013138
}
1312113139
}
13140+
13141+
#[inline]
13142+
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
13143+
unsafe {
13144+
&*((self.0 as *const u8).add(OFFSET_TS_CALL_SIGNATURE_DECLARATION_SCOPE_ID)
13145+
as *const Cell<Option<ScopeId>>)
13146+
}
13147+
}
1312213148
}
1312313149

1312413150
impl<'a, 't> GetAddress for TSCallSignatureDeclarationWithoutParams<'a, 't> {
@@ -13166,6 +13192,14 @@ impl<'a, 't> TSCallSignatureDeclarationWithoutReturnType<'a, 't> {
1316613192
as *const Box<'a, FormalParameters<'a>>)
1316713193
}
1316813194
}
13195+
13196+
#[inline]
13197+
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
13198+
unsafe {
13199+
&*((self.0 as *const u8).add(OFFSET_TS_CALL_SIGNATURE_DECLARATION_SCOPE_ID)
13200+
as *const Cell<Option<ScopeId>>)
13201+
}
13202+
}
1316913203
}
1317013204

1317113205
impl<'a, 't> GetAddress for TSCallSignatureDeclarationWithoutReturnType<'a, 't> {

crates/oxc_traverse/src/generated/scopes_collector.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,16 +1799,7 @@ impl<'a> Visit<'a> for ChildScopeCollector {
17991799

18001800
#[inline]
18011801
fn visit_ts_call_signature_declaration(&mut self, it: &TSCallSignatureDeclaration<'a>) {
1802-
if let Some(type_parameters) = &it.type_parameters {
1803-
self.visit_ts_type_parameter_declaration(type_parameters);
1804-
}
1805-
if let Some(this_param) = &it.this_param {
1806-
self.visit_ts_this_parameter(this_param);
1807-
}
1808-
self.visit_formal_parameters(&it.params);
1809-
if let Some(return_type) = &it.return_type {
1810-
self.visit_ts_type_annotation(return_type);
1811-
}
1802+
self.add_scope(&it.scope_id);
18121803
}
18131804

18141805
#[inline]

0 commit comments

Comments
 (0)