Skip to content

Commit 9b14fbc

Browse files
committed
1 parent d0f8b88 commit 9b14fbc

File tree

39 files changed

+224
-181
lines changed

39 files changed

+224
-181
lines changed

crates/oxc_ast/src/ast/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ macro_rules! inherit_variants {
703703
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
704704
/// Inherited from [`TSTypeName`]
705705
QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1,
706+
/// Inherited from [`TSTypeName`]
707+
ThisExpression(Box<'a, ThisExpression>) = 2,
706708

707709
$($rest)*
708710
}
@@ -717,7 +719,7 @@ macro_rules! inherit_variants {
717719
as_ts_type_name_mut,
718720
to_ts_type_name,
719721
to_ts_type_name_mut,
720-
[IdentifierReference, QualifiedName]
722+
[IdentifierReference, QualifiedName, ThisExpression]
721723
);
722724
};
723725

crates/oxc_ast/src/ast/ts.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,22 @@ pub struct TSTypeReference<'a> {
769769

770770
/// TSTypeName:
771771
/// IdentifierReference
772+
/// this
772773
/// TSTypeName . IdentifierName
773774
#[ast(visit)]
774775
#[derive(Debug)]
775776
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
776777
pub enum TSTypeName<'a> {
777-
#[estree(via = TSTypeNameIdentifierReference)]
778778
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
779779
QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1,
780+
ThisExpression(Box<'a, ThisExpression>) = 2,
780781
}
781782

782783
/// Macro for matching `TSTypeName`'s variants.
783784
#[macro_export]
784785
macro_rules! match_ts_type_name {
785786
($ty:ident) => {
786-
$ty::IdentifierReference(_) | $ty::QualifiedName(_)
787+
$ty::IdentifierReference(_) | $ty::QualifiedName(_) | $ty::ThisExpression(_)
787788
};
788789
}
789790
pub use match_ts_type_name;
@@ -1335,7 +1336,7 @@ inherit_variants! {
13351336
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
13361337
pub enum TSTypeQueryExprName<'a> {
13371338
/// `type foo = typeof import('foo')`
1338-
TSImportType(Box<'a, TSImportType<'a>>) = 2,
1339+
TSImportType(Box<'a, TSImportType<'a>>) = 3,
13391340
// `TSTypeName` variants added here by `inherit_variants!` macro
13401341
@inherit TSTypeName
13411342
}
@@ -1585,7 +1586,7 @@ inherit_variants! {
15851586
#[derive(Debug)]
15861587
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
15871588
pub enum TSModuleReference<'a> {
1588-
ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 2,
1589+
ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 3,
15891590
// `TSTypeName` variants added here by `inherit_variants!` macro
15901591
@inherit TSTypeName
15911592
}

crates/oxc_ast/src/ast_impl/ts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ impl<'a> TSType<'a> {
3232
/// returned.
3333
pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> {
3434
match self {
35-
TSType::TSTypeReference(reference) => {
36-
Some(reference.type_name.get_identifier_reference())
37-
}
35+
TSType::TSTypeReference(reference) => reference.type_name.get_identifier_reference(),
3836
TSType::TSTypeQuery(query) => match &query.expr_name {
3937
TSTypeQueryExprName::IdentifierReference(ident) => Some(ident),
4038
_ => None,
@@ -86,10 +84,11 @@ impl<'a> TSTypeName<'a> {
8684
/// type Foo = Bar; // -> Bar
8785
/// type Foo = Bar.Baz; // -> Bar
8886
/// ```
89-
pub fn get_identifier_reference(&self) -> &IdentifierReference<'a> {
87+
pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> {
9088
match self {
91-
TSTypeName::IdentifierReference(ident) => ident,
89+
TSTypeName::IdentifierReference(ident) => Some(ident),
9290
TSTypeName::QualifiedName(name) => name.left.get_identifier_reference(),
91+
TSTypeName::ThisExpression(_) => None,
9392
}
9493
}
9594

@@ -120,6 +119,7 @@ impl fmt::Display for TSTypeName<'_> {
120119
match self {
121120
TSTypeName::IdentifierReference(ident) => ident.fmt(f),
122121
TSTypeName::QualifiedName(qualified) => qualified.fmt(f),
122+
TSTypeName::ThisExpression(_) => "this".fmt(f),
123123
}
124124
}
125125
}

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11748,6 +11748,17 @@ impl<'a> AstBuilder<'a> {
1174811748
TSTypeName::QualifiedName(self.alloc_ts_qualified_name(span, left, right))
1174911749
}
1175011750

11751+
/// Build a [`TSTypeName::ThisExpression`].
11752+
///
11753+
/// This node contains a [`ThisExpression`] that will be stored in the memory arena.
11754+
///
11755+
/// ## Parameters
11756+
/// * `span`: The [`Span`] covering this node
11757+
#[inline]
11758+
pub fn ts_type_name_this_expression(self, span: Span) -> TSTypeName<'a> {
11759+
TSTypeName::ThisExpression(self.alloc_this_expression(span))
11760+
}
11761+
1175111762
/// Build a [`TSQualifiedName`].
1175211763
///
1175311764
/// If you want the built node to be allocated in the memory arena,

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,6 +6714,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> {
67146714
TSTypeName::IdentifierReference(CloneIn::clone_in(it, allocator))
67156715
}
67166716
Self::QualifiedName(it) => TSTypeName::QualifiedName(CloneIn::clone_in(it, allocator)),
6717+
Self::ThisExpression(it) => {
6718+
TSTypeName::ThisExpression(CloneIn::clone_in(it, allocator))
6719+
}
67176720
}
67186721
}
67196722

@@ -6725,6 +6728,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> {
67256728
Self::QualifiedName(it) => {
67266729
TSTypeName::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator))
67276730
}
6731+
Self::ThisExpression(it) => {
6732+
TSTypeName::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator))
6733+
}
67286734
}
67296735
}
67306736
}
@@ -7379,6 +7385,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> {
73797385
Self::QualifiedName(it) => {
73807386
TSTypeQueryExprName::QualifiedName(CloneIn::clone_in(it, allocator))
73817387
}
7388+
Self::ThisExpression(it) => {
7389+
TSTypeQueryExprName::ThisExpression(CloneIn::clone_in(it, allocator))
7390+
}
73827391
}
73837392
}
73847393

@@ -7393,6 +7402,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> {
73937402
Self::QualifiedName(it) => TSTypeQueryExprName::QualifiedName(
73947403
CloneIn::clone_in_with_semantic_ids(it, allocator),
73957404
),
7405+
Self::ThisExpression(it) => TSTypeQueryExprName::ThisExpression(
7406+
CloneIn::clone_in_with_semantic_ids(it, allocator),
7407+
),
73967408
}
73977409
}
73987410
}
@@ -7632,6 +7644,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> {
76327644
Self::QualifiedName(it) => {
76337645
TSModuleReference::QualifiedName(CloneIn::clone_in(it, allocator))
76347646
}
7647+
Self::ThisExpression(it) => {
7648+
TSModuleReference::ThisExpression(CloneIn::clone_in(it, allocator))
7649+
}
76357650
}
76367651
}
76377652

@@ -7646,6 +7661,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> {
76467661
Self::QualifiedName(it) => {
76477662
TSModuleReference::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator))
76487663
}
7664+
Self::ThisExpression(it) => TSModuleReference::ThisExpression(
7665+
CloneIn::clone_in_with_semantic_ids(it, allocator),
7666+
),
76497667
}
76507668
}
76517669
}

crates/oxc_ast/src/generated/derive_content_eq.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ impl ContentEq for TSTypeName<'_> {
20612061
match (self, other) {
20622062
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
20632063
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
2064+
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
20642065
_ => false,
20652066
}
20662067
}
@@ -2306,6 +2307,7 @@ impl ContentEq for TSTypeQueryExprName<'_> {
23062307
(Self::TSImportType(a), Self::TSImportType(b)) => a.content_eq(b),
23072308
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
23082309
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
2310+
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
23092311
_ => false,
23102312
}
23112313
}
@@ -2396,6 +2398,7 @@ impl ContentEq for TSModuleReference<'_> {
23962398
(Self::ExternalModuleReference(a), Self::ExternalModuleReference(b)) => a.content_eq(b),
23972399
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
23982400
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
2401+
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
23992402
_ => false,
24002403
}
24012404
}

crates/oxc_ast/src/generated/derive_dummy.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ impl<'a> Dummy<'a> for TSBigIntKeyword {
22322232
impl<'a> Dummy<'a> for TSTypeReference<'a> {
22332233
/// Create a dummy [`TSTypeReference`].
22342234
///
2235-
/// Has cost of making 1 allocation (32 bytes).
2235+
/// Has cost of making 1 allocation (8 bytes).
22362236
fn dummy(allocator: &'a Allocator) -> Self {
22372237
Self {
22382238
span: Dummy::dummy(allocator),
@@ -2245,16 +2245,16 @@ impl<'a> Dummy<'a> for TSTypeReference<'a> {
22452245
impl<'a> Dummy<'a> for TSTypeName<'a> {
22462246
/// Create a dummy [`TSTypeName`].
22472247
///
2248-
/// Has cost of making 1 allocation (32 bytes).
2248+
/// Has cost of making 1 allocation (8 bytes).
22492249
fn dummy(allocator: &'a Allocator) -> Self {
2250-
Self::IdentifierReference(Dummy::dummy(allocator))
2250+
Self::ThisExpression(Dummy::dummy(allocator))
22512251
}
22522252
}
22532253

22542254
impl<'a> Dummy<'a> for TSQualifiedName<'a> {
22552255
/// Create a dummy [`TSQualifiedName`].
22562256
///
2257-
/// Has cost of making 1 allocation (32 bytes).
2257+
/// Has cost of making 1 allocation (8 bytes).
22582258
fn dummy(allocator: &'a Allocator) -> Self {
22592259
Self {
22602260
span: Dummy::dummy(allocator),
@@ -2328,7 +2328,7 @@ impl<'a> Dummy<'a> for TSAccessibility {
23282328
impl<'a> Dummy<'a> for TSClassImplements<'a> {
23292329
/// Create a dummy [`TSClassImplements`].
23302330
///
2331-
/// Has cost of making 1 allocation (32 bytes).
2331+
/// Has cost of making 1 allocation (8 bytes).
23322332
fn dummy(allocator: &'a Allocator) -> Self {
23332333
Self {
23342334
span: Dummy::dummy(allocator),
@@ -2591,7 +2591,7 @@ impl<'a> Dummy<'a> for TSInferType<'a> {
25912591
impl<'a> Dummy<'a> for TSTypeQuery<'a> {
25922592
/// Create a dummy [`TSTypeQuery`].
25932593
///
2594-
/// Has cost of making 1 allocation (32 bytes).
2594+
/// Has cost of making 1 allocation (8 bytes).
25952595
fn dummy(allocator: &'a Allocator) -> Self {
25962596
Self {
25972597
span: Dummy::dummy(allocator),
@@ -2604,9 +2604,9 @@ impl<'a> Dummy<'a> for TSTypeQuery<'a> {
26042604
impl<'a> Dummy<'a> for TSTypeQueryExprName<'a> {
26052605
/// Create a dummy [`TSTypeQueryExprName`].
26062606
///
2607-
/// Has cost of making 1 allocation (32 bytes).
2607+
/// Has cost of making 1 allocation (8 bytes).
26082608
fn dummy(allocator: &'a Allocator) -> Self {
2609-
Self::IdentifierReference(Dummy::dummy(allocator))
2609+
Self::ThisExpression(Dummy::dummy(allocator))
26102610
}
26112611
}
26122612

@@ -2738,7 +2738,7 @@ impl<'a> Dummy<'a> for TSTypeAssertion<'a> {
27382738
impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> {
27392739
/// Create a dummy [`TSImportEqualsDeclaration`].
27402740
///
2741-
/// Has cost of making 1 allocation (32 bytes).
2741+
/// Has cost of making 1 allocation (8 bytes).
27422742
fn dummy(allocator: &'a Allocator) -> Self {
27432743
Self {
27442744
span: Dummy::dummy(allocator),
@@ -2752,9 +2752,9 @@ impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> {
27522752
impl<'a> Dummy<'a> for TSModuleReference<'a> {
27532753
/// Create a dummy [`TSModuleReference`].
27542754
///
2755-
/// Has cost of making 1 allocation (32 bytes).
2755+
/// Has cost of making 1 allocation (8 bytes).
27562756
fn dummy(allocator: &'a Allocator) -> Self {
2757-
Self::IdentifierReference(Dummy::dummy(allocator))
2757+
Self::ThisExpression(Dummy::dummy(allocator))
27582758
}
27592759
}
27602760

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,10 +2628,9 @@ impl ESTree for TSTypeReference<'_> {
26282628
impl ESTree for TSTypeName<'_> {
26292629
fn serialize<S: Serializer>(&self, serializer: S) {
26302630
match self {
2631-
Self::IdentifierReference(it) => {
2632-
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
2633-
}
2631+
Self::IdentifierReference(it) => it.serialize(serializer),
26342632
Self::QualifiedName(it) => it.serialize(serializer),
2633+
Self::ThisExpression(it) => it.serialize(serializer),
26352634
}
26362635
}
26372636
}
@@ -2965,10 +2964,9 @@ impl ESTree for TSTypeQueryExprName<'_> {
29652964
fn serialize<S: Serializer>(&self, serializer: S) {
29662965
match self {
29672966
Self::TSImportType(it) => it.serialize(serializer),
2968-
Self::IdentifierReference(it) => {
2969-
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
2970-
}
2967+
Self::IdentifierReference(it) => it.serialize(serializer),
29712968
Self::QualifiedName(it) => it.serialize(serializer),
2969+
Self::ThisExpression(it) => it.serialize(serializer),
29722970
}
29732971
}
29742972
}
@@ -3096,10 +3094,9 @@ impl ESTree for TSModuleReference<'_> {
30963094
fn serialize<S: Serializer>(&self, serializer: S) {
30973095
match self {
30983096
Self::ExternalModuleReference(it) => it.serialize(serializer),
3099-
Self::IdentifierReference(it) => {
3100-
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
3101-
}
3097+
Self::IdentifierReference(it) => it.serialize(serializer),
31023098
Self::QualifiedName(it) => it.serialize(serializer),
3099+
Self::ThisExpression(it) => it.serialize(serializer),
31033100
}
31043101
}
31053102
}

crates/oxc_ast/src/generated/derive_get_address.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ impl GetAddress for TSTypeName<'_> {
727727
match self {
728728
Self::IdentifierReference(it) => GetAddress::address(it),
729729
Self::QualifiedName(it) => GetAddress::address(it),
730+
Self::ThisExpression(it) => GetAddress::address(it),
730731
}
731732
}
732733
}
@@ -764,6 +765,7 @@ impl GetAddress for TSTypeQueryExprName<'_> {
764765
Self::TSImportType(it) => GetAddress::address(it),
765766
Self::IdentifierReference(it) => GetAddress::address(it),
766767
Self::QualifiedName(it) => GetAddress::address(it),
768+
Self::ThisExpression(it) => GetAddress::address(it),
767769
}
768770
}
769771
}
@@ -776,6 +778,7 @@ impl GetAddress for TSModuleReference<'_> {
776778
Self::ExternalModuleReference(it) => GetAddress::address(it),
777779
Self::IdentifierReference(it) => GetAddress::address(it),
778780
Self::QualifiedName(it) => GetAddress::address(it),
781+
Self::ThisExpression(it) => GetAddress::address(it),
779782
}
780783
}
781784
}

crates/oxc_ast/src/generated/derive_get_span.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ impl GetSpan for TSTypeName<'_> {
18171817
match self {
18181818
Self::IdentifierReference(it) => GetSpan::span(&**it),
18191819
Self::QualifiedName(it) => GetSpan::span(&**it),
1820+
Self::ThisExpression(it) => GetSpan::span(&**it),
18201821
}
18211822
}
18221823
}
@@ -2013,6 +2014,7 @@ impl GetSpan for TSTypeQueryExprName<'_> {
20132014
Self::TSImportType(it) => GetSpan::span(&**it),
20142015
Self::IdentifierReference(it) => GetSpan::span(&**it),
20152016
Self::QualifiedName(it) => GetSpan::span(&**it),
2017+
Self::ThisExpression(it) => GetSpan::span(&**it),
20162018
}
20172019
}
20182020
}
@@ -2086,6 +2088,7 @@ impl GetSpan for TSModuleReference<'_> {
20862088
Self::ExternalModuleReference(it) => GetSpan::span(&**it),
20872089
Self::IdentifierReference(it) => GetSpan::span(&**it),
20882090
Self::QualifiedName(it) => GetSpan::span(&**it),
2091+
Self::ThisExpression(it) => GetSpan::span(&**it),
20892092
}
20902093
}
20912094
}

0 commit comments

Comments
 (0)