Skip to content

Commit d587d45

Browse files
committed
fix(ast/estree): fix TS type def for TSThisParameter
1 parent 8228b74 commit d587d45

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

crates/oxc_ast/src/ast/ts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use super::{inherit_variants, js::*, literal::*};
3333
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
3434
#[estree(
3535
rename = "Identifier",
36-
add_fields(decorators = TsEmptyArray, optional = TsFalse, name = This)
36+
add_fields(name = This, decorators = EmptyArray, optional = False),
37+
field_order(span, name, type_annotation, decorators, optional),
3738
)]
3839
pub struct TSThisParameter<'a> {
3940
pub span: Span,

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,10 +2280,10 @@ impl ESTree for TSThisParameter<'_> {
22802280
state.serialize_field("type", &JsonSafeString("Identifier"));
22812281
state.serialize_field("start", &self.span.start);
22822282
state.serialize_field("end", &self.span.end);
2283-
state.serialize_field("typeAnnotation", &self.type_annotation);
22842283
state.serialize_field("name", &crate::serialize::This(self));
2285-
state.serialize_ts_field("decorators", &crate::serialize::TsEmptyArray(self));
2286-
state.serialize_ts_field("optional", &crate::serialize::TsFalse(self));
2284+
state.serialize_field("typeAnnotation", &self.type_annotation);
2285+
state.serialize_field("decorators", &crate::serialize::EmptyArray(self));
2286+
state.serialize_field("optional", &crate::serialize::False(self));
22872287
state.end();
22882288
}
22892289
}

crates/oxc_ast/src/serialize.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ impl<T> ESTree for This<'_, T> {
161161
}
162162
}
163163

164+
/// Serialized as `[]`.
165+
#[ast_meta]
166+
#[estree(ts_type = "[]", raw_deser = "[]")]
167+
pub struct EmptyArray<'b, T>(#[expect(dead_code)] pub &'b T);
168+
169+
impl<T> ESTree for EmptyArray<'_, T> {
170+
fn serialize<S: Serializer>(&self, serializer: S) {
171+
[(); 0].serialize(serializer);
172+
}
173+
}
174+
164175
#[ast_meta]
165176
#[estree(ts_type = "[]", raw_deser = "[]")]
166177
#[ts]

napi/parser/deserialize-js.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,10 @@ function deserializeTSThisParameter(pos) {
12661266
type: 'Identifier',
12671267
start: deserializeU32(pos),
12681268
end: deserializeU32(pos + 4),
1269-
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
12701269
name: 'this',
1270+
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
1271+
decorators: [],
1272+
optional: false,
12711273
};
12721274
}
12731275

napi/parser/deserialize-ts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,8 @@ function deserializeTSThisParameter(pos) {
13331333
type: 'Identifier',
13341334
start: deserializeU32(pos),
13351335
end: deserializeU32(pos + 4),
1336-
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
13371336
name: 'this',
1337+
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
13381338
decorators: [],
13391339
optional: false,
13401340
};

npm/oxc-types/types.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,10 @@ export interface JSXText extends Span {
918918

919919
export interface TSThisParameter extends Span {
920920
type: 'Identifier';
921-
typeAnnotation: TSTypeAnnotation | null;
922921
name: 'this';
923-
decorators?: [];
924-
optional?: false;
922+
typeAnnotation: TSTypeAnnotation | null;
923+
decorators: [];
924+
optional: false;
925925
}
926926

927927
export interface TSEnumDeclaration extends Span {

0 commit comments

Comments
 (0)