From f3ddefbf6c7e92deb8a3e348cc1ac7040a98ac0a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 16 Apr 2025 19:35:15 +0000 Subject: [PATCH] fix(ast/estree): add missing fields to `AssignmentTargetRest` in TS-ESTree AST (#10456) Part of #9705. --- crates/oxc_ast/src/ast/js.rs | 5 +++- crates/oxc_ast/src/generated/derive_estree.rs | 4 +++ napi/parser/deserialize-ts.js | 4 +++ npm/oxc-types/types.d.ts | 4 +++ .../coverage/snapshots/estree_typescript.snap | 25 +------------------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 789539eb6cfa3..d91a2aa1a5020 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -896,7 +896,10 @@ pub struct ObjectAssignmentTarget<'a> { #[ast(visit)] #[derive(Debug)] #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)] -#[estree(rename = "RestElement")] +#[estree( + rename = "RestElement", + add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull, value = TsNull), +)] pub struct AssignmentTargetRest<'a> { pub span: Span, #[estree(rename = "argument")] diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index 5a1540b04a7b5..afd3cbb3370e2 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -667,6 +667,10 @@ impl ESTree for AssignmentTargetRest<'_> { state.serialize_field("start", &self.span.start); state.serialize_field("end", &self.span.end); state.serialize_field("argument", &self.target); + 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.serialize_ts_field("value", &crate::serialize::TsNull(self)); state.end(); } } diff --git a/napi/parser/deserialize-ts.js b/napi/parser/deserialize-ts.js index cefaeb100d8c6..448cc4e1b4ade 100644 --- a/napi/parser/deserialize-ts.js +++ b/napi/parser/deserialize-ts.js @@ -392,6 +392,10 @@ function deserializeAssignmentTargetRest(pos) { start: deserializeU32(pos), end: deserializeU32(pos + 4), argument: deserializeAssignmentTarget(pos + 8), + decorators: [], + optional: false, + typeAnnotation: null, + value: null, }; } diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 67fe306fc97b4..760cd1a561047 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -274,6 +274,10 @@ export interface ObjectAssignmentTarget extends Span { export interface AssignmentTargetRest extends Span { type: 'RestElement'; argument: AssignmentTarget; + decorators?: []; + optional?: false; + typeAnnotation?: null; + value?: null; } export type AssignmentTargetMaybeDefault = AssignmentTargetWithDefault | AssignmentTarget; diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index 7707006a9ba1d..56307901a7078 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: 9013/10725 (84.04%) +Positive Passed: 9036/10725 (84.25%) Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts A class member cannot have the 'const' keyword. Mismatch: tasks/coverage/typescript/tests/cases/compiler/accessOverriddenBaseClassMember1.ts @@ -52,7 +52,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/assignmentCompatability Mismatch: tasks/coverage/typescript/tests/cases/compiler/assignmentCompatability42.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/assignmentCompatability8.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/assignmentCompatability9.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/assignmentRestElementWithErrorSourceType.ts Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/assignmentToInstantiationExpression.ts The left-hand side of an assignment expression must be a variable or a property access. Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/assignmentToParenthesizedExpression1.ts @@ -250,8 +249,6 @@ serde_json::from_str(oxc_json) error: number out of range at line 28 column 25 Mismatch: tasks/coverage/typescript/tests/cases/compiler/destructuringAssignmentWithDefault.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/destructuringAssignmentWithDefault2.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/destructuringAssignmentWithStrictNullChecks.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/destructuringTuple.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/destructuringUnspreadableIntoRest.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/doNotEmitDetachedComments.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts @@ -738,7 +735,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/multivar.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/narrowTypeByInstanceof.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/narrowingOrderIndependent.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/narrowingUnionToUnion.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/nestedObjectRest.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/newNamesInGlobalAugmentations1.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/noCrashOnThisTypeUsage.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.ts @@ -897,13 +893,10 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationClas Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationClasses.ts Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDecorators.ts Unexpected token -Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPattern2.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForOfArrayBindingPattern2.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues2.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts @@ -1091,7 +1084,6 @@ Unexpected token Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts Unexpected token Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/mixinClassesAnnotated.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/mixinClassesAnonymous.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationES2022.ts @@ -1274,7 +1266,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/de Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringObjectAssignmentPatternWithNestedSpread.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment5.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts @@ -1301,14 +1292,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/es6/destructu Missing initializer in destructuring declaration Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts Missing initializer in destructuring declaration -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/iterableArrayPattern24.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/iterableArrayPattern4.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/iterableArrayPattern6.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/iterableArrayPattern8.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/nonIterableRestElement1.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/nonIterableRestElement2.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/nonIterableRestElement3.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/objectBindingPatternKeywordIdentifiers05.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/objectBindingPatternKeywordIdentifiers06.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts @@ -1319,7 +1303,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/re Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern2.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern5.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithInitializer1.ts Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts Cannot assign to this expression @@ -1738,7 +1721,6 @@ A rest parameter must be last in a parameter list Mismatch: tasks/coverage/typescript/tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/functions/strictBindCallApply1.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/generators/generatorAssignability.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/internalModules/DeclarationMerging/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.ts @@ -2326,7 +2308,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc 'public' modifier cannot be used here. Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts The left-hand side of a `for...of` statement may not be `async` -Mismatch: tasks/coverage/typescript/tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts tasks/coverage/typescript/tests/cases/conformance/salsa/chainedPrototypeAssignment.ts Unexpected estree file content error: 1 != 3 @@ -2462,9 +2443,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/objectT A rest parameter must be last in a parameter list Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/objectTypeLiteral/callSignatures/restParametersWithArrayTypeAnnotations.ts A rest parameter must be last in a parameter list -Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/rest/objectRest.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/rest/objectRestAssignment.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/rest/objectRestForOf.ts Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/rest/objectRestNegative.ts A rest element must be last in a destructuring pattern Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts @@ -2474,7 +2452,6 @@ A rest element must be last in a destructuring pattern Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryOnClass.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThisWithImplicitThis.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts