Skip to content

Commit b6ef7ca

Browse files
committed
refactor: update
1 parent b632c04 commit b6ef7ca

File tree

19 files changed

+963
-154
lines changed

19 files changed

+963
-154
lines changed

crates/oxc_ast/src/ast/ts.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ pub use match_ts_type;
230230
///
231231
/// <https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#handbook-content>
232232
#[visited_node]
233-
#[derive(Debug, Hash)]
233+
#[scope]
234+
#[derive(Debug)]
234235
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
235236
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
236237
pub struct TSConditionalType<'a> {
@@ -240,6 +241,7 @@ pub struct TSConditionalType<'a> {
240241
pub extends_type: TSType<'a>,
241242
pub true_type: TSType<'a>,
242243
pub false_type: TSType<'a>,
244+
pub scope_id: Cell<Option<ScopeId>>,
243245
}
244246

245247
/// string | string[] | (() => string) | { s: string }
@@ -579,8 +581,7 @@ pub struct TSTypeParameterInstantiation<'a> {
579581
}
580582

581583
#[visited_node]
582-
#[scope]
583-
#[derive(Debug)]
584+
#[derive(Debug, Hash)]
584585
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
585586
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
586587
pub struct TSTypeParameter<'a> {
@@ -592,7 +593,6 @@ pub struct TSTypeParameter<'a> {
592593
pub r#in: bool,
593594
pub out: bool,
594595
pub r#const: bool,
595-
pub scope_id: Cell<Option<ScopeId>>,
596596
}
597597

598598
#[visited_node]
@@ -606,16 +606,19 @@ pub struct TSTypeParameterDeclaration<'a> {
606606
}
607607

608608
#[visited_node]
609-
#[derive(Debug, Hash)]
609+
#[scope]
610+
#[derive(Debug)]
610611
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
611612
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
612613
pub struct TSTypeAliasDeclaration<'a> {
613614
#[cfg_attr(feature = "serialize", serde(flatten))]
614615
pub span: Span,
615616
pub id: BindingIdentifier<'a>,
617+
#[scope(enter_before)]
616618
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
617619
pub type_annotation: TSType<'a>,
618620
pub declare: bool,
621+
pub scope_id: Cell<Option<ScopeId>>,
619622
}
620623

621624
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -642,17 +645,20 @@ pub struct TSClassImplements<'a> {
642645
///
643646
/// interface `BindingIdentifier` `TypeParameters_opt` `InterfaceExtendsClause_opt` `ObjectType`
644647
#[visited_node]
645-
#[derive(Debug, Hash)]
648+
#[scope]
649+
#[derive(Debug)]
646650
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
647651
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
648652
pub struct TSInterfaceDeclaration<'a> {
649653
#[cfg_attr(feature = "serialize", serde(flatten))]
650654
pub span: Span,
651655
pub id: BindingIdentifier<'a>,
656+
#[scope(enter_before)]
652657
pub extends: Option<Vec<'a, TSInterfaceHeritage<'a>>>,
653658
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
654659
pub body: Box<'a, TSInterfaceBody<'a>>,
655660
pub declare: bool,
661+
pub scope_id: Cell<Option<ScopeId>>,
656662
}
657663

658664
#[visited_node]
@@ -726,7 +732,8 @@ pub enum TSMethodSignatureKind {
726732
}
727733

728734
#[visited_node]
729-
#[derive(Debug, Hash)]
735+
#[scope]
736+
#[derive(Debug)]
730737
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
731738
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
732739
pub struct TSMethodSignature<'a> {
@@ -740,10 +747,12 @@ pub struct TSMethodSignature<'a> {
740747
pub params: Box<'a, FormalParameters<'a>>,
741748
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
742749
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
750+
pub scope_id: Cell<Option<ScopeId>>,
743751
}
744752

745753
#[visited_node]
746-
#[derive(Debug, Hash)]
754+
#[scope]
755+
#[derive(Debug)]
747756
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
748757
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
749758
pub struct TSConstructSignatureDeclaration<'a> {
@@ -752,6 +761,7 @@ pub struct TSConstructSignatureDeclaration<'a> {
752761
pub params: Box<'a, FormalParameters<'a>>,
753762
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
754763
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
764+
pub scope_id: Cell<Option<ScopeId>>,
755765
}
756766

757767
#[visited_node]
@@ -994,7 +1004,8 @@ pub struct TSConstructorType<'a> {
9941004
}
9951005

9961006
#[visited_node]
997-
#[derive(Debug, Hash)]
1007+
#[scope]
1008+
#[derive(Debug)]
9981009
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
9991010
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
10001011
pub struct TSMappedType<'a> {
@@ -1005,6 +1016,7 @@ pub struct TSMappedType<'a> {
10051016
pub type_annotation: Option<TSType<'a>>,
10061017
pub optional: TSMappedTypeModifierOperator,
10071018
pub readonly: TSMappedTypeModifierOperator,
1019+
pub scope_id: Cell<Option<ScopeId>>,
10081020
}
10091021

10101022
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

crates/oxc_ast/src/ast_impl/ts.rs

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,6 @@ impl<'a> TSTypeName<'a> {
103103
}
104104
}
105105

106-
impl<'a> TSTypeParameter<'a> {
107-
pub fn new(
108-
span: Span,
109-
name: BindingIdentifier<'a>,
110-
constraint: Option<TSType<'a>>,
111-
default: Option<TSType<'a>>,
112-
r#in: bool,
113-
out: bool,
114-
r#const: bool,
115-
) -> Self {
116-
Self { span, name, constraint, default, r#in, out, r#const, scope_id: Cell::default() }
117-
}
118-
}
119-
120-
impl<'a> Hash for TSTypeParameter<'a> {
121-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
122-
self.name.hash(state);
123-
self.constraint.hash(state);
124-
self.default.hash(state);
125-
self.r#in.hash(state);
126-
self.out.hash(state);
127-
self.r#const.hash(state);
128-
}
129-
}
130-
131106
impl<'a> TSType<'a> {
132107
/// Remove nested parentheses from this type.
133108
pub fn without_parenthesized(&self) -> &Self {
@@ -233,3 +208,68 @@ impl ImportOrExportKind {
233208
matches!(self, Self::Type)
234209
}
235210
}
211+
212+
impl<'a> Hash for TSMappedType<'a> {
213+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
214+
self.span.hash(state);
215+
self.type_parameter.hash(state);
216+
self.name_type.hash(state);
217+
self.type_annotation.hash(state);
218+
self.optional.hash(state);
219+
self.readonly.hash(state);
220+
}
221+
}
222+
223+
impl<'a> Hash for TSConditionalType<'a> {
224+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
225+
self.span.hash(state);
226+
self.check_type.hash(state);
227+
self.extends_type.hash(state);
228+
self.true_type.hash(state);
229+
self.false_type.hash(state);
230+
}
231+
}
232+
233+
impl<'a> Hash for TSInterfaceDeclaration<'a> {
234+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
235+
self.span.hash(state);
236+
self.id.hash(state);
237+
self.type_parameters.hash(state);
238+
self.extends.hash(state);
239+
self.body.hash(state);
240+
self.declare.hash(state);
241+
}
242+
}
243+
244+
impl<'a> Hash for TSTypeAliasDeclaration<'a> {
245+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
246+
self.span.hash(state);
247+
self.id.hash(state);
248+
self.type_parameters.hash(state);
249+
self.type_annotation.hash(state);
250+
self.declare.hash(state);
251+
}
252+
}
253+
254+
impl<'a> Hash for TSMethodSignature<'a> {
255+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
256+
self.span.hash(state);
257+
self.key.hash(state);
258+
self.computed.hash(state);
259+
self.optional.hash(state);
260+
self.kind.hash(state);
261+
self.this_param.hash(state);
262+
self.params.hash(state);
263+
self.return_type.hash(state);
264+
self.type_parameters.hash(state);
265+
}
266+
}
267+
268+
impl<'a> Hash for TSConstructSignatureDeclaration<'a> {
269+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
270+
self.span.hash(state);
271+
self.params.hash(state);
272+
self.return_type.hash(state);
273+
self.type_parameters.hash(state);
274+
}
275+
}

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ impl<'a> AstKind<'a> {
345345
Self::TSNamedTupleMember(_) => "TSNamedTupleMember".into(),
346346

347347
Self::TSPropertySignature(_) => "TSPropertySignature".into(),
348+
Self::TSConditionalType(_) => "TSConditionalType".into(),
349+
Self::TSMappedType(_) => "TSMappedType".into(),
350+
Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(),
348351
}
349352
}
350353
}

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6062,7 +6062,14 @@ impl<'a> AstBuilder<'a> {
60626062
true_type: TSType<'a>,
60636063
false_type: TSType<'a>,
60646064
) -> TSConditionalType<'a> {
6065-
TSConditionalType { span, check_type, extends_type, true_type, false_type }
6065+
TSConditionalType {
6066+
span,
6067+
check_type,
6068+
extends_type,
6069+
true_type,
6070+
false_type,
6071+
scope_id: Default::default(),
6072+
}
60666073
}
60676074

60686075
#[inline]
@@ -6542,16 +6549,7 @@ impl<'a> AstBuilder<'a> {
65426549
out: bool,
65436550
r#const: bool,
65446551
) -> TSTypeParameter<'a> {
6545-
TSTypeParameter {
6546-
span,
6547-
name,
6548-
constraint,
6549-
default,
6550-
r#in,
6551-
out,
6552-
r#const,
6553-
scope_id: Default::default(),
6554-
}
6552+
TSTypeParameter { span, name, constraint, default, r#in, out, r#const }
65556553
}
65566554

65576555
#[inline]
@@ -6605,6 +6603,7 @@ impl<'a> AstBuilder<'a> {
66056603
type_parameters: type_parameters.into_in(self.allocator),
66066604
type_annotation,
66076605
declare,
6606+
scope_id: Default::default(),
66086607
}
66096608
}
66106609

@@ -6675,6 +6674,7 @@ impl<'a> AstBuilder<'a> {
66756674
type_parameters: type_parameters.into_in(self.allocator),
66766675
body: body.into_in(self.allocator),
66776676
declare,
6677+
scope_id: Default::default(),
66786678
}
66796679
}
66806680

@@ -7013,6 +7013,7 @@ impl<'a> AstBuilder<'a> {
70137013
params: params.into_in(self.allocator),
70147014
return_type: return_type.into_in(self.allocator),
70157015
type_parameters: type_parameters.into_in(self.allocator),
7016+
scope_id: Default::default(),
70167017
}
70177018
}
70187019

@@ -7066,6 +7067,7 @@ impl<'a> AstBuilder<'a> {
70667067
params: params.into_in(self.allocator),
70677068
return_type: return_type.into_in(self.allocator),
70687069
type_parameters: type_parameters.into_in(self.allocator),
7070+
scope_id: Default::default(),
70697071
}
70707072
}
70717073

@@ -7678,6 +7680,7 @@ impl<'a> AstBuilder<'a> {
76787680
type_annotation,
76797681
optional,
76807682
readonly,
7683+
scope_id: Default::default(),
76817684
}
76827685
}
76837686

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub enum AstType {
107107
TSEnumMember,
108108
TSTypeAnnotation,
109109
TSLiteralType,
110+
TSConditionalType,
110111
TSUnionType,
111112
TSIntersectionType,
112113
TSParenthesizedType,
@@ -137,13 +138,15 @@ pub enum AstType {
137138
TSInterfaceDeclaration,
138139
TSPropertySignature,
139140
TSMethodSignature,
141+
TSConstructSignatureDeclaration,
140142
TSInterfaceHeritage,
141143
TSModuleDeclaration,
142144
TSModuleBlock,
143145
TSTypeLiteral,
144146
TSInferType,
145147
TSTypeQuery,
146148
TSImportType,
149+
TSMappedType,
147150
TSTemplateLiteralType,
148151
TSAsExpression,
149152
TSSatisfiesExpression,
@@ -273,6 +276,7 @@ pub enum AstKind<'a> {
273276
TSEnumMember(&'a TSEnumMember<'a>),
274277
TSTypeAnnotation(&'a TSTypeAnnotation<'a>),
275278
TSLiteralType(&'a TSLiteralType<'a>),
279+
TSConditionalType(&'a TSConditionalType<'a>),
276280
TSUnionType(&'a TSUnionType<'a>),
277281
TSIntersectionType(&'a TSIntersectionType<'a>),
278282
TSParenthesizedType(&'a TSParenthesizedType<'a>),
@@ -303,13 +307,15 @@ pub enum AstKind<'a> {
303307
TSInterfaceDeclaration(&'a TSInterfaceDeclaration<'a>),
304308
TSPropertySignature(&'a TSPropertySignature<'a>),
305309
TSMethodSignature(&'a TSMethodSignature<'a>),
310+
TSConstructSignatureDeclaration(&'a TSConstructSignatureDeclaration<'a>),
306311
TSInterfaceHeritage(&'a TSInterfaceHeritage<'a>),
307312
TSModuleDeclaration(&'a TSModuleDeclaration<'a>),
308313
TSModuleBlock(&'a TSModuleBlock<'a>),
309314
TSTypeLiteral(&'a TSTypeLiteral<'a>),
310315
TSInferType(&'a TSInferType<'a>),
311316
TSTypeQuery(&'a TSTypeQuery<'a>),
312317
TSImportType(&'a TSImportType<'a>),
318+
TSMappedType(&'a TSMappedType<'a>),
313319
TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>),
314320
TSAsExpression(&'a TSAsExpression<'a>),
315321
TSSatisfiesExpression(&'a TSSatisfiesExpression<'a>),
@@ -440,6 +446,7 @@ impl<'a> GetSpan for AstKind<'a> {
440446
Self::TSEnumMember(it) => it.span(),
441447
Self::TSTypeAnnotation(it) => it.span(),
442448
Self::TSLiteralType(it) => it.span(),
449+
Self::TSConditionalType(it) => it.span(),
443450
Self::TSUnionType(it) => it.span(),
444451
Self::TSIntersectionType(it) => it.span(),
445452
Self::TSParenthesizedType(it) => it.span(),
@@ -470,13 +477,15 @@ impl<'a> GetSpan for AstKind<'a> {
470477
Self::TSInterfaceDeclaration(it) => it.span(),
471478
Self::TSPropertySignature(it) => it.span(),
472479
Self::TSMethodSignature(it) => it.span(),
480+
Self::TSConstructSignatureDeclaration(it) => it.span(),
473481
Self::TSInterfaceHeritage(it) => it.span(),
474482
Self::TSModuleDeclaration(it) => it.span(),
475483
Self::TSModuleBlock(it) => it.span(),
476484
Self::TSTypeLiteral(it) => it.span(),
477485
Self::TSInferType(it) => it.span(),
478486
Self::TSTypeQuery(it) => it.span(),
479487
Self::TSImportType(it) => it.span(),
488+
Self::TSMappedType(it) => it.span(),
480489
Self::TSTemplateLiteralType(it) => it.span(),
481490
Self::TSAsExpression(it) => it.span(),
482491
Self::TSSatisfiesExpression(it) => it.span(),

0 commit comments

Comments
 (0)