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
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use super::{inherit_variants, js::*, literal::*};
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(
rename = "Identifier",
add_fields(decorators = TsEmptyArray, optional = TsFalse, name = This)
add_fields(name = This, decorators = EmptyArray, optional = False),
field_order(span, name, type_annotation, decorators, optional),
)]
pub struct TSThisParameter<'a> {
pub span: Span,
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,10 +2280,10 @@ impl ESTree for TSThisParameter<'_> {
state.serialize_field("type", &JsonSafeString("Identifier"));
state.serialize_field("start", &self.span.start);
state.serialize_field("end", &self.span.end);
state.serialize_field("typeAnnotation", &self.type_annotation);
state.serialize_field("name", &crate::serialize::This(self));
state.serialize_ts_field("decorators", &crate::serialize::TsEmptyArray(self));
state.serialize_ts_field("optional", &crate::serialize::TsFalse(self));
state.serialize_field("typeAnnotation", &self.type_annotation);
state.serialize_field("decorators", &crate::serialize::EmptyArray(self));
state.serialize_field("optional", &crate::serialize::False(self));
state.end();
}
}
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ impl<T> ESTree for This<'_, T> {
}
}

/// Serialized as `[]`.
#[ast_meta]
#[estree(ts_type = "[]", raw_deser = "[]")]
pub struct EmptyArray<'b, T>(#[expect(dead_code)] pub &'b T);

impl<T> ESTree for EmptyArray<'_, T> {
fn serialize<S: Serializer>(&self, serializer: S) {
[(); 0].serialize(serializer);
}
}

#[ast_meta]
#[estree(ts_type = "[]", raw_deser = "[]")]
#[ts]
Expand Down
4 changes: 3 additions & 1 deletion napi/parser/deserialize-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,10 @@ function deserializeTSThisParameter(pos) {
type: 'Identifier',
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
name: 'this',
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
decorators: [],
optional: false,
};
}

Expand Down
2 changes: 1 addition & 1 deletion napi/parser/deserialize-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,8 @@ function deserializeTSThisParameter(pos) {
type: 'Identifier',
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
name: 'this',
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
decorators: [],
optional: false,
};
Expand Down
6 changes: 3 additions & 3 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,10 @@ export interface JSXText extends Span {

export interface TSThisParameter extends Span {
type: 'Identifier';
typeAnnotation: TSTypeAnnotation | null;
name: 'this';
decorators?: [];
optional?: false;
typeAnnotation: TSTypeAnnotation | null;
decorators: [];
optional: false;
}

export interface TSEnumDeclaration extends Span {
Expand Down