From 66e384cfd35a5b7566b2e6b91f973d5812a11ec0 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:11:25 +0000 Subject: [PATCH] fix(ast/estree): add missing fields to `ObjectPattern` in TS-ESTree AST (#10570) Part of #9705. --- crates/oxc_ast/src/ast/js.rs | 2 +- crates/oxc_ast/src/generated/derive_estree.rs | 2 ++ napi/parser/deserialize-ts.js | 2 ++ npm/oxc-types/types.d.ts | 2 ++ tasks/coverage/snapshots/estree_typescript.snap | 3 +-- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index c7049601b1755..6b108946a05dd 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1576,7 +1576,7 @@ pub struct AssignmentPattern<'a> { #[ast(visit)] #[derive(Debug)] #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)] -#[estree(add_fields(decorators = TsEmptyArray))] +#[estree(add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull))] pub struct ObjectPattern<'a> { pub span: Span, pub properties: Vec<'a, BindingProperty<'a>>, diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index 9871cc4b3eeec..7dc173b27853b 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -1300,6 +1300,8 @@ impl ESTree for ObjectPattern<'_> { &AppendTo { array: &self.properties, after: &self.rest }, ); state.serialize_ts_field("decorators", &crate::serialize::TsEmptyArray(self)); + state.serialize_ts_field("optional", &crate::serialize::TsFalse(self)); + state.serialize_ts_field("typeAnnotation", &crate::serialize::TsNull(self)); state.end(); } } diff --git a/napi/parser/deserialize-ts.js b/napi/parser/deserialize-ts.js index 982b10ad4eb8c..7436db25b9b08 100644 --- a/napi/parser/deserialize-ts.js +++ b/napi/parser/deserialize-ts.js @@ -781,6 +781,8 @@ function deserializeObjectPattern(pos) { end: deserializeU32(pos + 4), properties, decorators: [], + optional: false, + typeAnnotation: null, }; } diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index aee4625fc8301..e5ec022add230 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -544,6 +544,8 @@ export interface ObjectPattern extends Span { type: 'ObjectPattern'; properties: Array; decorators?: []; + optional?: false; + typeAnnotation?: null; } export interface BindingProperty extends Span { diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index 2f92924da0ddd..6fd623e68c5b7 100644 --- a/tasks/coverage/snapshots/estree_typescript.snap +++ b/tasks/coverage/snapshots/estree_typescript.snap @@ -2,7 +2,7 @@ commit: 15392346 estree_typescript Summary: AST Parsed : 10619/10725 (99.01%) -Positive Passed: 9326/10725 (86.96%) +Positive Passed: 9327/10725 (86.97%) Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts A class member cannot have the 'const' keyword. Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/accessorBodyInTypeContext.ts @@ -750,7 +750,6 @@ Unexpected token Mismatch: tasks/coverage/typescript/tests/cases/compiler/restParameterAssignmentCompatibility.ts Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/restParameterNotLast.ts A rest parameter must be last in a parameter list -Mismatch: tasks/coverage/typescript/tests/cases/compiler/restParameterWithBindingPattern1.ts Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/restParameterWithBindingPattern3.ts A rest element cannot have an initializer. tasks/coverage/typescript/tests/cases/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.ts