From 8b8f78f1d25ce3642be3785e46a096a3841efab7 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 12 May 2025 11:10:30 +0000 Subject: [PATCH] fix(ast/estree): fix field order and type def for `RestElement` in `FormalParameters` (#10961) Change field order for a `RestElement` in `FormalParameters` to contain `decorators`, `optional`, `typeAnnotation` in that order - to match `RestElement` in other positions. Fix TS type def for `FormalParameterRest` to include all fields. --- crates/oxc_ast/src/ast/js.rs | 6 ++++-- crates/oxc_ast/src/serialize.rs | 8 ++++---- napi/parser/generated/deserialize/ts.js | 4 ++-- npm/oxc-types/types.d.ts | 6 ++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 23876a7ae2a29..8de2906a7c180 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1774,8 +1774,10 @@ pub enum FunctionType { interface FormalParameterRest extends Span { type: 'RestElement'; argument: BindingPatternKind; - typeAnnotation: TSTypeAnnotation | null; - optional: boolean; + decorators?: [], + optional?: boolean; + typeAnnotation?: TSTypeAnnotation | null; + value?: null; } " )] diff --git a/crates/oxc_ast/src/serialize.rs b/crates/oxc_ast/src/serialize.rs index fb0777c0ea526..92cf680a78d2a 100644 --- a/crates/oxc_ast/src/serialize.rs +++ b/crates/oxc_ast/src/serialize.rs @@ -610,11 +610,11 @@ impl ESTree for ElisionConverter<'_> { end: DESER[u32]( POS_OFFSET.span.end ), argument: DESER[BindingPatternKind]( POS_OFFSET.argument.kind ), /* IF_TS */ + decorators: [], + optional: DESER[bool]( POS_OFFSET.argument.optional ), typeAnnotation: DESER[Option>]( POS_OFFSET.argument.type_annotation ), - optional: DESER[bool]( POS_OFFSET.argument.optional ), - decorators: [], value: null, /* END_IF_TS */ }); @@ -649,9 +649,9 @@ impl ESTree for FormalParametersRest<'_, '_> { state.serialize_field("start", &rest.span.start); state.serialize_field("end", &rest.span.end); state.serialize_field("argument", &rest.argument.kind); - state.serialize_ts_field("typeAnnotation", &rest.argument.type_annotation); - state.serialize_ts_field("optional", &rest.argument.optional); state.serialize_ts_field("decorators", &EmptyArray(())); + state.serialize_ts_field("optional", &rest.argument.optional); + state.serialize_ts_field("typeAnnotation", &rest.argument.type_annotation); state.serialize_ts_field("value", &Null(())); state.end(); } diff --git a/napi/parser/generated/deserialize/ts.js b/napi/parser/generated/deserialize/ts.js index 0715a7cdf78b4..9746930d199c6 100644 --- a/napi/parser/generated/deserialize/ts.js +++ b/napi/parser/generated/deserialize/ts.js @@ -858,11 +858,11 @@ function deserializeFormalParameters(pos) { start: deserializeU32(pos), end: deserializeU32(pos + 4), argument: deserializeBindingPatternKind(pos + 8), + decorators: [], + optional: deserializeBool(pos + 32), typeAnnotation: deserializeOptionBoxTSTypeAnnotation( pos + 24, ), - optional: deserializeBool(pos + 32), - decorators: [], value: null, }); } diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 540fe10e28391..5fcdd2578fbcd 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -600,8 +600,10 @@ export type FunctionType = export interface FormalParameterRest extends Span { type: 'RestElement'; argument: BindingPatternKind; - typeAnnotation: TSTypeAnnotation | null; - optional: boolean; + decorators?: []; + optional?: boolean; + typeAnnotation?: TSTypeAnnotation | null; + value?: null; } export type FormalParameter =