From c8de6fe9cf9cd38bbdeb0087bd1436de3d2d8434 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sun, 5 Oct 2025 00:32:09 +0000 Subject: [PATCH] feat(linter/plugins): add `parent` field to AST nodes (#14345) Use the new raw transfer deserializer added in #14344 to add `parent` field to all AST node in Oxlint JS plugins. --- .github/generated/ast_changes_watch_list.yml | 2 +- apps/oxlint/scripts/build.js | 2 +- apps/oxlint/src-js/plugins/source_code.ts | 2 +- apps/oxlint/test/e2e.test.ts | 4 + .../test/fixtures/parent/.oxlintrc.json | 9 + .../test/fixtures/parent/files/index.js | 1 + .../test/fixtures/parent/output.snap.md | 86 ++ apps/oxlint/test/fixtures/parent/plugin.ts | 41 + ...parens.js => ts_range_parent_no_parens.js} | 920 ++++++++++++++---- .../ast_tools/src/generators/raw_transfer.rs | 2 +- 10 files changed, 872 insertions(+), 197 deletions(-) create mode 100644 apps/oxlint/test/fixtures/parent/.oxlintrc.json create mode 100644 apps/oxlint/test/fixtures/parent/files/index.js create mode 100644 apps/oxlint/test/fixtures/parent/output.snap.md create mode 100644 apps/oxlint/test/fixtures/parent/plugin.ts rename napi/parser/generated/deserialize/{ts_range_no_parens.js => ts_range_parent_no_parens.js} (91%) diff --git a/.github/generated/ast_changes_watch_list.yml b/.github/generated/ast_changes_watch_list.yml index ac9dab68f3c33..6cc198e8acf0c 100644 --- a/.github/generated/ast_changes_watch_list.yml +++ b/.github/generated/ast_changes_watch_list.yml @@ -74,8 +74,8 @@ src: - 'napi/parser/generated/deserialize/ts.js' - 'napi/parser/generated/deserialize/ts_parent.js' - 'napi/parser/generated/deserialize/ts_range.js' - - 'napi/parser/generated/deserialize/ts_range_no_parens.js' - 'napi/parser/generated/deserialize/ts_range_parent.js' + - 'napi/parser/generated/deserialize/ts_range_parent_no_parens.js' - 'napi/parser/generated/lazy/constructors.js' - 'napi/parser/generated/lazy/types.js' - 'napi/parser/generated/lazy/walk.js' diff --git a/apps/oxlint/scripts/build.js b/apps/oxlint/scripts/build.js index 38fe233b4731a..619156eb1095f 100755 --- a/apps/oxlint/scripts/build.js +++ b/apps/oxlint/scripts/build.js @@ -32,7 +32,7 @@ const parserFilePaths = [ 'generated/lazy/types.js', 'generated/lazy/walk.js', */ - 'generated/deserialize/ts_range_no_parens.js', + 'generated/deserialize/ts_range_parent_no_parens.js', 'generated/visit/keys.js', 'generated/visit/types.js', 'generated/visit/visitor.d.ts', diff --git a/apps/oxlint/src-js/plugins/source_code.ts b/apps/oxlint/src-js/plugins/source_code.ts index 054f725fee005..eb4a806868702 100644 --- a/apps/oxlint/src-js/plugins/source_code.ts +++ b/apps/oxlint/src-js/plugins/source_code.ts @@ -7,7 +7,7 @@ import { } from '../generated/constants.js'; // @ts-expect-error we need to generate `.d.ts` file for this module // We use the deserializer which removes `ParenthesizedExpression`s from AST to match ESLint -import { deserializeProgramOnly } from '../../dist/generated/deserialize/ts_range_no_parens.js'; +import { deserializeProgramOnly } from '../../dist/generated/deserialize/ts_range_parent_no_parens.js'; import type { Program } from '@oxc-project/types'; import type { Scope, ScopeManager, Variable } from './scope.ts'; diff --git a/apps/oxlint/test/e2e.test.ts b/apps/oxlint/test/e2e.test.ts index f90cc04bd3c05..95878a0650684 100644 --- a/apps/oxlint/test/e2e.test.ts +++ b/apps/oxlint/test/e2e.test.ts @@ -123,6 +123,10 @@ describe('oxlint CLI', () => { await testFixture('estree'); }); + it('should receive AST with all nodes having `parent` property', async () => { + await testFixture('parent'); + }); + it('should receive data via `context`', async () => { await testFixture('context_properties'); }); diff --git a/apps/oxlint/test/fixtures/parent/.oxlintrc.json b/apps/oxlint/test/fixtures/parent/.oxlintrc.json new file mode 100644 index 0000000000000..11a1a1ed47496 --- /dev/null +++ b/apps/oxlint/test/fixtures/parent/.oxlintrc.json @@ -0,0 +1,9 @@ +{ + "jsPlugins": ["./plugin.ts"], + "categories": { + "correctness": "off" + }, + "rules": { + "parents/check": "error" + } +} diff --git a/apps/oxlint/test/fixtures/parent/files/index.js b/apps/oxlint/test/fixtures/parent/files/index.js new file mode 100644 index 0000000000000..46bfd952d0de3 --- /dev/null +++ b/apps/oxlint/test/fixtures/parent/files/index.js @@ -0,0 +1 @@ +const obj = { a: [b, c], ...d }; diff --git a/apps/oxlint/test/fixtures/parent/output.snap.md b/apps/oxlint/test/fixtures/parent/output.snap.md new file mode 100644 index 0000000000000..636bca91acd1c --- /dev/null +++ b/apps/oxlint/test/fixtures/parent/output.snap.md @@ -0,0 +1,86 @@ +# Exit code +1 + +# stdout +``` + x parents(check): VariableDeclaration -> Program + ,-[files/index.js:1:1] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x parents(check): Program -> null + ,-[files/index.js:1:1] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x parents(check): Identifier -> VariableDeclarator + ,-[files/index.js:1:7] + 1 | const obj = { a: [b, c], ...d }; + : ^^^ + `---- + + x parents(check): VariableDeclarator -> VariableDeclaration + ,-[files/index.js:1:7] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x parents(check): ObjectExpression -> VariableDeclarator + ,-[files/index.js:1:13] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^^^^^^^^^^^^^^ + `---- + + x parents(check): Identifier -> Property + ,-[files/index.js:1:15] + 1 | const obj = { a: [b, c], ...d }; + : ^ + `---- + + x parents(check): Property -> ObjectExpression + ,-[files/index.js:1:15] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^^^^ + `---- + + x parents(check): ArrayExpression -> Property + ,-[files/index.js:1:18] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^^^ + `---- + + x parents(check): Identifier -> ArrayExpression + ,-[files/index.js:1:19] + 1 | const obj = { a: [b, c], ...d }; + : ^ + `---- + + x parents(check): Identifier -> ArrayExpression + ,-[files/index.js:1:22] + 1 | const obj = { a: [b, c], ...d }; + : ^ + `---- + + x parents(check): SpreadElement -> ObjectExpression + ,-[files/index.js:1:26] + 1 | const obj = { a: [b, c], ...d }; + : ^^^^ + `---- + + x parents(check): Identifier -> SpreadElement + ,-[files/index.js:1:29] + 1 | const obj = { a: [b, c], ...d }; + : ^ + `---- + +Found 0 warnings and 12 errors. +Finished in Xms on 1 file using X threads. +``` + +# stderr +``` +WARNING: JS plugins are experimental and not subject to semver. +Breaking changes are possible while JS plugins support is under development. +``` diff --git a/apps/oxlint/test/fixtures/parent/plugin.ts b/apps/oxlint/test/fixtures/parent/plugin.ts new file mode 100644 index 0000000000000..341f17d540aa6 --- /dev/null +++ b/apps/oxlint/test/fixtures/parent/plugin.ts @@ -0,0 +1,41 @@ +import type { Plugin } from '../../../dist/index.js'; + +const plugin: Plugin = { + meta: { + name: 'parents', + }, + rules: { + check: { + create(context) { + return { + Program(node) { + context.report({ message: `${node.type} -> ${node.parent}`, node }); + }, + VariableDeclaration(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + VariableDeclarator(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + Identifier(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + ObjectExpression(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + Property(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + ArrayExpression(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + SpreadElement(node) { + context.report({ message: `${node.type} -> ${node.parent.type}`, node }); + }, + }; + }, + }, + }, +}; + +export default plugin; diff --git a/napi/parser/generated/deserialize/ts_range_no_parens.js b/napi/parser/generated/deserialize/ts_range_parent_no_parens.js similarity index 91% rename from napi/parser/generated/deserialize/ts_range_no_parens.js rename to napi/parser/generated/deserialize/ts_range_parent_no_parens.js index 910d249a95797..fc1c85b00f3d1 100644 --- a/napi/parser/generated/deserialize/ts_range_no_parens.js +++ b/napi/parser/generated/deserialize/ts_range_parent_no_parens.js @@ -5,6 +5,7 @@ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen; const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), decodeStr = textDecoder.decode.bind(textDecoder), { fromCodePoint } = String; +let parent = null; export function deserialize(buffer, sourceText, sourceByteLen) { return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); @@ -32,7 +33,7 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserializ function deserializeProgram(pos) { let end = deserializeU32(pos + 4), - program = { + program = parent = { type: 'Program', body: null, sourceType: deserializeModuleKind(pos + 125), @@ -40,6 +41,7 @@ function deserializeProgram(pos) { start: 0, end, range: [0, end], + parent: null, }; program.hashbang = deserializeOptionHashbang(pos + 48); let body = program.body = deserializeVecDirective(pos + 72); @@ -59,6 +61,7 @@ function deserializeProgram(pos) { } else start = end; program.start = program.range[0] = start; } + parent = null; return program; } @@ -158,7 +161,8 @@ function deserializeExpression(pos) { function deserializeIdentifierName(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: deserializeStr(pos + 8), @@ -167,17 +171,20 @@ function deserializeIdentifierName(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeIdentifierReference(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: deserializeStr(pos + 8), @@ -186,17 +193,20 @@ function deserializeIdentifierReference(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeBindingIdentifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: deserializeStr(pos + 8), @@ -205,17 +215,20 @@ function deserializeBindingIdentifier(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeLabelIdentifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: deserializeStr(pos + 8), @@ -224,10 +237,12 @@ function deserializeLabelIdentifier(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } @@ -238,20 +253,24 @@ function deserializeThisExpression(pos) { start, end, range: [start, end], + parent, }; } function deserializeArrayExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ArrayExpression', elements: null, start, end, range: [start, end], + parent, }; node.elements = deserializeVecArrayExpressionElement(pos + 8); + parent = previousParent; return node; } @@ -359,14 +378,17 @@ function deserializeElision(pos) { function deserializeObjectExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ObjectExpression', properties: null, start, end, range: [start, end], + parent, }; node.properties = deserializeVecObjectPropertyKind(pos + 8); + parent = previousParent; return node; } @@ -384,7 +406,8 @@ function deserializeObjectPropertyKind(pos) { function deserializeObjectProperty(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Property', kind: deserializePropertyKind(pos + 40), key: null, @@ -396,10 +419,12 @@ function deserializeObjectProperty(pos) { start, end, range: [start, end], + parent, }; node.key = deserializePropertyKey(pos + 8); node.value = deserializeExpression(pos + 24); node.optional = false; + parent = previousParent; return node; } @@ -516,23 +541,27 @@ function deserializePropertyKind(pos) { function deserializeTemplateLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TemplateLiteral', quasis: null, expressions: null, start, end, range: [start, end], + parent, }; node.quasis = deserializeVecTemplateElement(pos + 8); node.expressions = deserializeVecExpression(pos + 32); + parent = previousParent; return node; } function deserializeTaggedTemplateExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TaggedTemplateExpression', tag: null, typeArguments: null, @@ -540,10 +569,12 @@ function deserializeTaggedTemplateExpression(pos) { start, end, range: [start, end], + parent, }; node.tag = deserializeExpression(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); node.quasi = deserializeTemplateLiteral(pos + 32); + parent = previousParent; return node; } @@ -561,6 +592,7 @@ function deserializeTemplateElement(pos) { start, end, range: [start, end], + parent, }; } @@ -574,7 +606,8 @@ function deserializeTemplateElementValue(pos) { function deserializeComputedMemberExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'MemberExpression', object: null, property: null, @@ -583,17 +616,20 @@ function deserializeComputedMemberExpression(pos) { start, end, range: [start, end], + parent, }; node.object = deserializeExpression(pos + 8); node.property = deserializeExpression(pos + 24); node.computed = true; + parent = previousParent; return node; } function deserializeStaticMemberExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'MemberExpression', object: null, property: null, @@ -602,17 +638,20 @@ function deserializeStaticMemberExpression(pos) { start, end, range: [start, end], + parent, }; node.object = deserializeExpression(pos + 8); node.property = deserializeIdentifierName(pos + 24); node.computed = false; + parent = previousParent; return node; } function deserializePrivateFieldExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'MemberExpression', object: null, property: null, @@ -621,17 +660,20 @@ function deserializePrivateFieldExpression(pos) { start, end, range: [start, end], + parent, }; node.object = deserializeExpression(pos + 8); node.property = deserializePrivateIdentifier(pos + 24); node.computed = false; + parent = previousParent; return node; } function deserializeCallExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'CallExpression', callee: null, typeArguments: null, @@ -640,17 +682,20 @@ function deserializeCallExpression(pos) { start, end, range: [start, end], + parent, }; node.callee = deserializeExpression(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); node.arguments = deserializeVecArgument(pos + 32); + parent = previousParent; return node; } function deserializeNewExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'NewExpression', callee: null, typeArguments: null, @@ -658,40 +703,48 @@ function deserializeNewExpression(pos) { start, end, range: [start, end], + parent, }; node.callee = deserializeExpression(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); node.arguments = deserializeVecArgument(pos + 32); + parent = previousParent; return node; } function deserializeMetaProperty(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'MetaProperty', meta: null, property: null, start, end, range: [start, end], + parent, }; node.meta = deserializeIdentifierName(pos + 8); node.property = deserializeIdentifierName(pos + 32); + parent = previousParent; return node; } function deserializeSpreadElement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'SpreadElement', argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeExpression(pos + 8); + parent = previousParent; return node; } @@ -793,7 +846,8 @@ function deserializeArgument(pos) { function deserializeUpdateExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'UpdateExpression', operator: deserializeUpdateOperator(pos + 24), prefix: deserializeBool(pos + 25), @@ -801,15 +855,18 @@ function deserializeUpdateExpression(pos) { start, end, range: [start, end], + parent, }; node.argument = deserializeSimpleAssignmentTarget(pos + 8); + parent = previousParent; return node; } function deserializeUnaryExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'UnaryExpression', operator: deserializeUnaryOperator(pos + 24), argument: null, @@ -817,16 +874,19 @@ function deserializeUnaryExpression(pos) { start, end, range: [start, end], + parent, }; node.argument = deserializeExpression(pos + 8); node.prefix = true; + parent = previousParent; return node; } function deserializeBinaryExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'BinaryExpression', left: null, operator: deserializeBinaryOperator(pos + 40), @@ -834,16 +894,19 @@ function deserializeBinaryExpression(pos) { start, end, range: [start, end], + parent, }; node.left = deserializeExpression(pos + 8); node.right = deserializeExpression(pos + 24); + parent = previousParent; return node; } function deserializePrivateInExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'BinaryExpression', left: null, operator: null, @@ -851,17 +914,20 @@ function deserializePrivateInExpression(pos) { start, end, range: [start, end], + parent, }; node.left = deserializePrivateIdentifier(pos + 8); node.operator = 'in'; node.right = deserializeExpression(pos + 32); + parent = previousParent; return node; } function deserializeLogicalExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'LogicalExpression', left: null, operator: deserializeLogicalOperator(pos + 40), @@ -869,16 +935,19 @@ function deserializeLogicalExpression(pos) { start, end, range: [start, end], + parent, }; node.left = deserializeExpression(pos + 8); node.right = deserializeExpression(pos + 24); + parent = previousParent; return node; } function deserializeConditionalExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ConditionalExpression', test: null, consequent: null, @@ -886,17 +955,20 @@ function deserializeConditionalExpression(pos) { start, end, range: [start, end], + parent, }; node.test = deserializeExpression(pos + 8); node.consequent = deserializeExpression(pos + 24); node.alternate = deserializeExpression(pos + 40); + parent = previousParent; return node; } function deserializeAssignmentExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'AssignmentExpression', operator: deserializeAssignmentOperator(pos + 40), left: null, @@ -904,9 +976,11 @@ function deserializeAssignmentExpression(pos) { start, end, range: [start, end], + parent, }; node.left = deserializeAssignmentTarget(pos + 8); node.right = deserializeExpression(pos + 24); + parent = previousParent; return node; } @@ -963,7 +1037,8 @@ function deserializeSimpleAssignmentTarget(pos) { function deserializeArrayAssignmentTarget(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ArrayPattern', decorators: null, elements: null, @@ -972,6 +1047,7 @@ function deserializeArrayAssignmentTarget(pos) { start, end, range: [start, end], + parent, }, elements = deserializeVecOptionAssignmentTargetMaybeDefault(pos + 8), rest = deserializeOptionBoxAssignmentTargetRest(pos + 32); @@ -980,13 +1056,15 @@ function deserializeArrayAssignmentTarget(pos) { node.elements = elements; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeObjectAssignmentTarget(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ObjectPattern', decorators: null, properties: null, @@ -995,6 +1073,7 @@ function deserializeObjectAssignmentTarget(pos) { start, end, range: [start, end], + parent, }, properties = deserializeVecAssignmentTargetProperty(pos + 8), rest = deserializeOptionBoxAssignmentTargetRest(pos + 32); @@ -1003,13 +1082,15 @@ function deserializeObjectAssignmentTarget(pos) { node.properties = properties; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeAssignmentTargetRest(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'RestElement', decorators: null, argument: null, @@ -1019,12 +1100,14 @@ function deserializeAssignmentTargetRest(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.argument = deserializeAssignmentTarget(pos + 8); node.optional = false; node.typeAnnotation = null; node.value = null; + parent = previousParent; return node; } @@ -1060,7 +1143,8 @@ function deserializeAssignmentTargetMaybeDefault(pos) { function deserializeAssignmentTargetWithDefault(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'AssignmentPattern', decorators: null, left: null, @@ -1070,12 +1154,14 @@ function deserializeAssignmentTargetWithDefault(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.left = deserializeAssignmentTarget(pos + 8); node.right = deserializeExpression(pos + 24); node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } @@ -1093,7 +1179,8 @@ function deserializeAssignmentTargetProperty(pos) { function deserializeAssignmentTargetPropertyIdentifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Property', kind: null, key: null, @@ -1105,21 +1192,29 @@ function deserializeAssignmentTargetPropertyIdentifier(pos) { start, end, range: [start, end], + parent, }, key = deserializeIdentifierReference(pos + 8), init = deserializeOptionExpression(pos + 40), value = { ...key }; - init !== null && (value = { - type: 'AssignmentPattern', - decorators: [], - left: value, - right: init, - optional: false, - typeAnnotation: null, - start, - end, - range: [start, end], - }); + if (init !== null) { + let left = value, previousParent = parent; + value = parent = { + type: 'AssignmentPattern', + decorators: [], + left, + right: init, + optional: false, + typeAnnotation: null, + start, + end, + range: [start, end], + parent, + }; + left.parent = value; + init.parent = value; + parent = previousParent; + } node.kind = 'init'; node.key = key; node.value = value; @@ -1127,13 +1222,15 @@ function deserializeAssignmentTargetPropertyIdentifier(pos) { node.shorthand = true; node.computed = false; node.optional = false; + parent = previousParent; return node; } function deserializeAssignmentTargetPropertyProperty(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Property', kind: null, key: null, @@ -1145,6 +1242,7 @@ function deserializeAssignmentTargetPropertyProperty(pos) { start, end, range: [start, end], + parent, }; node.kind = 'init'; node.key = deserializePropertyKey(pos + 8); @@ -1152,20 +1250,24 @@ function deserializeAssignmentTargetPropertyProperty(pos) { node.method = false; node.shorthand = false; node.optional = false; + parent = previousParent; return node; } function deserializeSequenceExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'SequenceExpression', expressions: null, start, end, range: [start, end], + parent, }; node.expressions = deserializeVecExpression(pos + 8); + parent = previousParent; return node; } @@ -1176,34 +1278,41 @@ function deserializeSuper(pos) { start, end, range: [start, end], + parent, }; } function deserializeAwaitExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'AwaitExpression', argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeExpression(pos + 8); + parent = previousParent; return node; } function deserializeChainExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ChainExpression', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeChainElement(pos + 8); + parent = previousParent; return node; } @@ -1304,15 +1413,18 @@ function deserializeStatement(pos) { function deserializeDirective(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExpressionStatement', expression: null, directive: deserializeStr(pos + 56), start, end, range: [start, end], + parent, }; node.expression = deserializeStringLiteral(pos + 8); + parent = previousParent; return node; } @@ -1324,20 +1436,24 @@ function deserializeHashbang(pos) { start, end, range: [start, end], + parent, }; } function deserializeBlockStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'BlockStatement', body: null, start, end, range: [start, end], + parent, }; node.body = deserializeVecStatement(pos + 8); + parent = previousParent; return node; } @@ -1367,7 +1483,8 @@ function deserializeDeclaration(pos) { function deserializeVariableDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'VariableDeclaration', kind: deserializeVariableDeclarationKind(pos + 32), declarations: null, @@ -1375,8 +1492,10 @@ function deserializeVariableDeclaration(pos) { start, end, range: [start, end], + parent, }; node.declarations = deserializeVecVariableDeclarator(pos + 8); + parent = previousParent; return node; } @@ -1400,7 +1519,8 @@ function deserializeVariableDeclarationKind(pos) { function deserializeVariableDeclarator(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'VariableDeclarator', id: null, init: null, @@ -1408,9 +1528,11 @@ function deserializeVariableDeclarator(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeBindingPattern(pos + 8); node.init = deserializeOptionExpression(pos + 40); + parent = previousParent; return node; } @@ -1421,29 +1543,34 @@ function deserializeEmptyStatement(pos) { start, end, range: [start, end], + parent, }; } function deserializeExpressionStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExpressionStatement', expression: null, directive: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); node.directive = null; + parent = previousParent; return node; } function deserializeIfStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'IfStatement', test: null, consequent: null, @@ -1451,49 +1578,58 @@ function deserializeIfStatement(pos) { start, end, range: [start, end], + parent, }; node.test = deserializeExpression(pos + 8); node.consequent = deserializeStatement(pos + 24); node.alternate = deserializeOptionStatement(pos + 40); + parent = previousParent; return node; } function deserializeDoWhileStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'DoWhileStatement', body: null, test: null, start, end, range: [start, end], + parent, }; node.body = deserializeStatement(pos + 8); node.test = deserializeExpression(pos + 24); + parent = previousParent; return node; } function deserializeWhileStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'WhileStatement', test: null, body: null, start, end, range: [start, end], + parent, }; node.test = deserializeExpression(pos + 8); node.body = deserializeStatement(pos + 24); + parent = previousParent; return node; } function deserializeForStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ForStatement', init: null, test: null, @@ -1502,11 +1638,13 @@ function deserializeForStatement(pos) { start, end, range: [start, end], + parent, }; node.init = deserializeOptionForStatementInit(pos + 8); node.test = deserializeOptionExpression(pos + 24); node.update = deserializeOptionExpression(pos + 40); node.body = deserializeStatement(pos + 56); + parent = previousParent; return node; } @@ -1608,7 +1746,8 @@ function deserializeForStatementInit(pos) { function deserializeForInStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ForInStatement', left: null, right: null, @@ -1616,10 +1755,12 @@ function deserializeForInStatement(pos) { start, end, range: [start, end], + parent, }; node.left = deserializeForStatementLeft(pos + 8); node.right = deserializeExpression(pos + 24); node.body = deserializeStatement(pos + 40); + parent = previousParent; return node; } @@ -1655,7 +1796,8 @@ function deserializeForStatementLeft(pos) { function deserializeForOfStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ForOfStatement', await: deserializeBool(pos + 60), left: null, @@ -1664,137 +1806,164 @@ function deserializeForOfStatement(pos) { start, end, range: [start, end], + parent, }; node.left = deserializeForStatementLeft(pos + 8); node.right = deserializeExpression(pos + 24); node.body = deserializeStatement(pos + 40); + parent = previousParent; return node; } function deserializeContinueStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ContinueStatement', label: null, start, end, range: [start, end], + parent, }; node.label = deserializeOptionLabelIdentifier(pos + 8); + parent = previousParent; return node; } function deserializeBreakStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'BreakStatement', label: null, start, end, range: [start, end], + parent, }; node.label = deserializeOptionLabelIdentifier(pos + 8); + parent = previousParent; return node; } function deserializeReturnStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ReturnStatement', argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeOptionExpression(pos + 8); + parent = previousParent; return node; } function deserializeWithStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'WithStatement', object: null, body: null, start, end, range: [start, end], + parent, }; node.object = deserializeExpression(pos + 8); node.body = deserializeStatement(pos + 24); + parent = previousParent; return node; } function deserializeSwitchStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'SwitchStatement', discriminant: null, cases: null, start, end, range: [start, end], + parent, }; node.discriminant = deserializeExpression(pos + 8); node.cases = deserializeVecSwitchCase(pos + 24); + parent = previousParent; return node; } function deserializeSwitchCase(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'SwitchCase', test: null, consequent: null, start, end, range: [start, end], + parent, }; node.test = deserializeOptionExpression(pos + 8); node.consequent = deserializeVecStatement(pos + 24); + parent = previousParent; return node; } function deserializeLabeledStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'LabeledStatement', label: null, body: null, start, end, range: [start, end], + parent, }; node.label = deserializeLabelIdentifier(pos + 8); node.body = deserializeStatement(pos + 32); + parent = previousParent; return node; } function deserializeThrowStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ThrowStatement', argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeExpression(pos + 8); + parent = previousParent; return node; } function deserializeTryStatement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TryStatement', block: null, handler: null, @@ -1802,26 +1971,31 @@ function deserializeTryStatement(pos) { start, end, range: [start, end], + parent, }; node.block = deserializeBoxBlockStatement(pos + 8); node.handler = deserializeOptionBoxCatchClause(pos + 16); node.finalizer = deserializeOptionBoxBlockStatement(pos + 24); + parent = previousParent; return node; } function deserializeCatchClause(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'CatchClause', param: null, body: null, start, end, range: [start, end], + parent, }; node.param = deserializeOptionCatchParameter(pos + 8); node.body = deserializeBoxBlockStatement(pos + 48); + parent = previousParent; return node; } @@ -1836,13 +2010,19 @@ function deserializeDebuggerStatement(pos) { start, end, range: [start, end], + parent, }; } function deserializeBindingPattern(pos) { let pattern = deserializeBindingPatternKind(pos); - pattern.optional = deserializeBool(pos + 24); - pattern.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 16); + { + let previousParent = parent; + parent = pattern; + pattern.optional = deserializeBool(pos + 24); + pattern.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 16); + parent = previousParent; + } return pattern; } @@ -1864,7 +2044,8 @@ function deserializeBindingPatternKind(pos) { function deserializeAssignmentPattern(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'AssignmentPattern', decorators: null, left: null, @@ -1874,19 +2055,22 @@ function deserializeAssignmentPattern(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.left = deserializeBindingPattern(pos + 8); node.right = deserializeExpression(pos + 40); node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeObjectPattern(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ObjectPattern', decorators: null, properties: null, @@ -1895,6 +2079,7 @@ function deserializeObjectPattern(pos) { start, end, range: [start, end], + parent, }, properties = deserializeVecBindingProperty(pos + 8), rest = deserializeOptionBoxBindingRestElement(pos + 32); @@ -1903,13 +2088,15 @@ function deserializeObjectPattern(pos) { node.properties = properties; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeBindingProperty(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Property', kind: null, key: null, @@ -1921,19 +2108,22 @@ function deserializeBindingProperty(pos) { start, end, range: [start, end], + parent, }; node.kind = 'init'; node.key = deserializePropertyKey(pos + 8); node.value = deserializeBindingPattern(pos + 24); node.method = false; node.optional = false; + parent = previousParent; return node; } function deserializeArrayPattern(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ArrayPattern', decorators: null, elements: null, @@ -1942,6 +2132,7 @@ function deserializeArrayPattern(pos) { start, end, range: [start, end], + parent, }, elements = deserializeVecOptionBindingPattern(pos + 8), rest = deserializeOptionBoxBindingRestElement(pos + 32); @@ -1950,13 +2141,15 @@ function deserializeArrayPattern(pos) { node.elements = elements; node.optional = false; node.typeAnnotation = null; + parent = previousParent; return node; } function deserializeBindingRestElement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'RestElement', decorators: null, argument: null, @@ -1966,19 +2159,22 @@ function deserializeBindingRestElement(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.argument = deserializeBindingPattern(pos + 8); node.optional = false; node.typeAnnotation = null; node.value = null; + parent = previousParent; return node; } function deserializeFunction(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: deserializeFunctionType(pos + 84), id: null, generator: deserializeBool(pos + 85), @@ -1992,6 +2188,7 @@ function deserializeFunction(pos) { start, end, range: [start, end], + parent, }, params = deserializeBoxFormalParameters(pos + 56); { @@ -2004,6 +2201,7 @@ function deserializeFunction(pos) { node.returnType = deserializeOptionBoxTSTypeAnnotation(pos + 64); node.body = deserializeOptionBoxFunctionBody(pos + 72); node.expression = false; + parent = previousParent; return node; } @@ -2028,7 +2226,8 @@ function deserializeFormalParameters(pos) { pos = uint32[pos + 32 >> 2]; let start, end, - rest = { + previousParent = parent, + rest = parent = { type: 'RestElement', decorators: [], argument: null, @@ -2038,10 +2237,12 @@ function deserializeFormalParameters(pos) { start: start = deserializeU32(pos), end: end = deserializeU32(pos + 4), range: [start, end], + parent, }; rest.argument = deserializeBindingPatternKind(pos + 8); rest.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 24); params.push(rest); + parent = previousParent; } return params; } @@ -2051,15 +2252,16 @@ function deserializeFormalParameter(pos) { { let accessibility = deserializeOptionTSAccessibility(pos + 64), readonly = deserializeBool(pos + 65), - override = deserializeBool(pos + 66); + override = deserializeBool(pos + 66), + previousParent = parent; if (accessibility === null && !readonly && !override) { - param = deserializeBindingPatternKind(pos + 32); + param = parent = deserializeBindingPatternKind(pos + 32); param.decorators = deserializeVecDecorator(pos + 8); param.optional = deserializeBool(pos + 56); param.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 48); } else { let start, end; - param = { + param = parent = { type: 'TSParameterProperty', accessibility, decorators: null, @@ -2070,10 +2272,12 @@ function deserializeFormalParameter(pos) { start: start = deserializeU32(pos), end: end = deserializeU32(pos + 4), range: [start, end], + parent, }; param.decorators = deserializeVecDecorator(pos + 8); param.parameter = deserializeBindingPattern(pos + 32); } + parent = previousParent; } return param; } @@ -2081,16 +2285,19 @@ function deserializeFormalParameter(pos) { function deserializeFunctionBody(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'BlockStatement', body: null, start, end, range: [start, end], + parent, }, body = deserializeVecDirective(pos + 8); body.push(...deserializeVecStatement(pos + 32)); node.body = body; + parent = previousParent; return node; } @@ -2098,7 +2305,8 @@ function deserializeArrowFunctionExpression(pos) { let expression = deserializeBool(pos + 44), start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ArrowFunctionExpression', expression, async: deserializeBool(pos + 45), @@ -2111,37 +2319,46 @@ function deserializeArrowFunctionExpression(pos) { start, end, range: [start, end], + parent, }, body = deserializeBoxFunctionBody(pos + 32); - expression === true && (body = body.body[0].expression); + if (expression === true) { + body = body.body[0].expression; + body.parent = parent; + } node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); node.params = deserializeBoxFormalParameters(pos + 16); node.returnType = deserializeOptionBoxTSTypeAnnotation(pos + 24); node.body = body; node.id = null; node.generator = false; + parent = previousParent; return node; } function deserializeYieldExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'YieldExpression', delegate: deserializeBool(pos + 24), argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeOptionExpression(pos + 8); + parent = previousParent; return node; } function deserializeClass(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: deserializeClassType(pos + 132), decorators: null, id: null, @@ -2155,6 +2372,7 @@ function deserializeClass(pos) { start, end, range: [start, end], + parent, }; node.decorators = deserializeVecDecorator(pos + 8); node.id = deserializeOptionBindingIdentifier(pos + 32); @@ -2163,6 +2381,7 @@ function deserializeClass(pos) { node.superTypeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 88); node.implements = deserializeVecTSClassImplements(pos + 96); node.body = deserializeBoxClassBody(pos + 120); + parent = previousParent; return node; } @@ -2180,14 +2399,17 @@ function deserializeClassType(pos) { function deserializeClassBody(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ClassBody', body: null, start, end, range: [start, end], + parent, }; node.body = deserializeVecClassElement(pos + 8); + parent = previousParent; return node; } @@ -2211,7 +2433,8 @@ function deserializeClassElement(pos) { function deserializeMethodDefinition(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: deserializeMethodDefinitionType(pos + 56), decorators: null, key: null, @@ -2225,10 +2448,12 @@ function deserializeMethodDefinition(pos) { start, end, range: [start, end], + parent, }; node.decorators = deserializeVecDecorator(pos + 8); node.key = deserializePropertyKey(pos + 32); node.value = deserializeBoxFunction(pos + 48); + parent = previousParent; return node; } @@ -2246,7 +2471,8 @@ function deserializeMethodDefinitionType(pos) { function deserializePropertyDefinition(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: deserializePropertyDefinitionType(pos + 72), decorators: null, key: null, @@ -2263,11 +2489,13 @@ function deserializePropertyDefinition(pos) { start, end, range: [start, end], + parent, }; node.decorators = deserializeVecDecorator(pos + 8); node.key = deserializePropertyKey(pos + 32); node.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 48); node.value = deserializeOptionExpression(pos + 56); + parent = previousParent; return node; } @@ -2305,20 +2533,24 @@ function deserializePrivateIdentifier(pos) { start, end, range: [start, end], + parent, }; } function deserializeStaticBlock(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'StaticBlock', body: null, start, end, range: [start, end], + parent, }; node.body = deserializeVecStatement(pos + 8); + parent = previousParent; return node; } @@ -2336,7 +2568,8 @@ function deserializeAccessorPropertyType(pos) { function deserializeAccessorProperty(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: deserializeAccessorPropertyType(pos + 72), decorators: null, key: null, @@ -2353,6 +2586,7 @@ function deserializeAccessorProperty(pos) { start, end, range: [start, end], + parent, }; node.decorators = deserializeVecDecorator(pos + 8); node.key = deserializePropertyKey(pos + 32); @@ -2361,13 +2595,15 @@ function deserializeAccessorProperty(pos) { node.declare = false; node.optional = false; node.readonly = false; + parent = previousParent; return node; } function deserializeImportExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportExpression', source: null, options: null, @@ -2375,16 +2611,19 @@ function deserializeImportExpression(pos) { start, end, range: [start, end], + parent, }; node.source = deserializeExpression(pos + 8); node.options = deserializeOptionExpression(pos + 24); + parent = previousParent; return node; } function deserializeImportDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportDeclaration', specifiers: null, source: null, @@ -2394,6 +2633,7 @@ function deserializeImportDeclaration(pos) { start, end, range: [start, end], + parent, }, specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8); specifiers === null && (specifiers = []); @@ -2401,6 +2641,7 @@ function deserializeImportDeclaration(pos) { node.specifiers = specifiers; node.source = deserializeStringLiteral(pos + 32); node.attributes = withClause === null ? [] : withClause.attributes; + parent = previousParent; return node; } @@ -2431,7 +2672,8 @@ function deserializeImportDeclarationSpecifier(pos) { function deserializeImportSpecifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportSpecifier', imported: null, local: null, @@ -2439,37 +2681,45 @@ function deserializeImportSpecifier(pos) { start, end, range: [start, end], + parent, }; node.imported = deserializeModuleExportName(pos + 8); node.local = deserializeBindingIdentifier(pos + 64); + parent = previousParent; return node; } function deserializeImportDefaultSpecifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportDefaultSpecifier', local: null, start, end, range: [start, end], + parent, }; node.local = deserializeBindingIdentifier(pos + 8); + parent = previousParent; return node; } function deserializeImportNamespaceSpecifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportNamespaceSpecifier', local: null, start, end, range: [start, end], + parent, }; node.local = deserializeBindingIdentifier(pos + 8); + parent = previousParent; return node; } @@ -2480,16 +2730,19 @@ function deserializeWithClause(pos) { function deserializeImportAttribute(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ImportAttribute', key: null, value: null, start, end, range: [start, end], + parent, }; node.key = deserializeImportAttributeKey(pos + 8); node.value = deserializeStringLiteral(pos + 64); + parent = previousParent; return node; } @@ -2507,7 +2760,8 @@ function deserializeImportAttributeKey(pos) { function deserializeExportNamedDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExportNamedDeclaration', declaration: null, specifiers: null, @@ -2517,35 +2771,41 @@ function deserializeExportNamedDeclaration(pos) { start, end, range: [start, end], + parent, }, withClause = deserializeOptionBoxWithClause(pos + 96); node.declaration = deserializeOptionDeclaration(pos + 8); node.specifiers = deserializeVecExportSpecifier(pos + 24); node.source = deserializeOptionStringLiteral(pos + 48); node.attributes = withClause === null ? [] : withClause.attributes; + parent = previousParent; return node; } function deserializeExportDefaultDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExportDefaultDeclaration', declaration: null, exportKind: null, start, end, range: [start, end], + parent, }; node.declaration = deserializeExportDefaultDeclarationKind(pos + 8); node.exportKind = 'value'; + parent = previousParent; return node; } function deserializeExportAllDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExportAllDeclaration', exported: null, source: null, @@ -2554,18 +2814,21 @@ function deserializeExportAllDeclaration(pos) { start, end, range: [start, end], + parent, }, withClause = deserializeOptionBoxWithClause(pos + 112); node.exported = deserializeOptionModuleExportName(pos + 8); node.source = deserializeStringLiteral(pos + 64); node.attributes = withClause === null ? [] : withClause.attributes; + parent = previousParent; return node; } function deserializeExportSpecifier(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'ExportSpecifier', local: null, exported: null, @@ -2573,9 +2836,11 @@ function deserializeExportSpecifier(pos) { start, end, range: [start, end], + parent, }; node.local = deserializeModuleExportName(pos + 8); node.exported = deserializeModuleExportName(pos + 64); + parent = previousParent; return node; } @@ -2694,16 +2959,19 @@ function deserializeModuleExportName(pos) { function deserializeV8IntrinsicExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'V8IntrinsicExpression', name: null, arguments: null, start, end, range: [start, end], + parent, }; node.name = deserializeIdentifierName(pos + 8); node.arguments = deserializeVecArgument(pos + 32); + parent = previousParent; return node; } @@ -2711,31 +2979,37 @@ function deserializeBooleanLiteral(pos) { let value = deserializeBool(pos + 8), start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Literal', value, raw: null, start, end, range: [start, end], + parent, }; node.raw = start === 0 && end === 0 ? null : value + ''; + parent = previousParent; return node; } function deserializeNullLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Literal', value: null, raw: null, start, end, range: [start, end], + parent, }; node.value = null; node.raw = start === 0 && end === 0 ? null : 'null'; + parent = previousParent; return node; } @@ -2748,31 +3022,36 @@ function deserializeNumericLiteral(pos) { start, end, range: [start, end], + parent, }; } function deserializeStringLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Literal', value: null, raw: deserializeOptionStr(pos + 24), start, end, range: [start, end], + parent, }, value = deserializeStr(pos + 8); deserializeBool(pos + 40) && (value = value.replace(/\uFFFD(.{4})/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))); node.value = value; + parent = previousParent; return node; } function deserializeBigIntLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Literal', value: null, raw: deserializeOptionStr(pos + 24), @@ -2780,17 +3059,20 @@ function deserializeBigIntLiteral(pos) { start, end, range: [start, end], + parent, }, bigint = deserializeStr(pos + 8); node.value = BigInt(bigint); node.bigint = bigint; + parent = previousParent; return node; } function deserializeRegExpLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Literal', value: null, raw: deserializeOptionStr(pos + 40), @@ -2798,6 +3080,7 @@ function deserializeRegExpLiteral(pos) { start, end, range: [start, end], + parent, }, regex = deserializeRegExp(pos + 8), value = null; @@ -2806,6 +3089,7 @@ function deserializeRegExpLiteral(pos) { } catch {} node.value = value; node.regex = regex; + parent = previousParent; return node; } @@ -2833,7 +3117,8 @@ function deserializeRegExpFlags(pos) { function deserializeJSXElement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXElement', openingElement: null, children: null, @@ -2841,6 +3126,7 @@ function deserializeJSXElement(pos) { start, end, range: [start, end], + parent, }, closingElement = deserializeOptionBoxJSXClosingElement(pos + 40), openingElement = deserializeBoxJSXOpeningElement(pos + 8); @@ -2848,13 +3134,15 @@ function deserializeJSXElement(pos) { node.openingElement = openingElement; node.children = deserializeVecJSXChild(pos + 16); node.closingElement = closingElement; + parent = previousParent; return node; } function deserializeJSXOpeningElement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXOpeningElement', name: null, typeArguments: null, @@ -2863,32 +3151,38 @@ function deserializeJSXOpeningElement(pos) { start, end, range: [start, end], + parent, }; node.name = deserializeJSXElementName(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); node.attributes = deserializeVecJSXAttributeItem(pos + 32); node.selfClosing = false; + parent = previousParent; return node; } function deserializeJSXClosingElement(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXClosingElement', name: null, start, end, range: [start, end], + parent, }; node.name = deserializeJSXElementName(pos + 8); + parent = previousParent; return node; } function deserializeJSXFragment(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXFragment', openingFragment: null, children: null, @@ -2896,21 +3190,28 @@ function deserializeJSXFragment(pos) { start, end, range: [start, end], + parent, }; node.openingFragment = deserializeJSXOpeningFragment(pos + 8); node.children = deserializeVecJSXChild(pos + 16); node.closingFragment = deserializeJSXClosingFragment(pos + 40); + parent = previousParent; return node; } function deserializeJSXOpeningFragment(pos) { - let start = deserializeU32(pos), end = deserializeU32(pos + 4); - return { - type: 'JSXOpeningFragment', - start, - end, - range: [start, end], - }; + let start = deserializeU32(pos), + end = deserializeU32(pos + 4), + previousParent = parent, + node = parent = { + type: 'JSXOpeningFragment', + start, + end, + range: [start, end], + parent, + }; + parent = previousParent; + return node; } function deserializeJSXClosingFragment(pos) { @@ -2920,6 +3221,7 @@ function deserializeJSXClosingFragment(pos) { start, end, range: [start, end], + parent, }; } @@ -2935,6 +3237,7 @@ function deserializeJSXElementName(pos) { start: ident.start, end: ident.end, range: ident.range, + parent, }; case 2: return deserializeBoxJSXNamespacedName(pos + 8); @@ -2948,6 +3251,7 @@ function deserializeJSXElementName(pos) { start: thisExpr.start, end: thisExpr.end, range: thisExpr.range, + parent, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for JSXElementName`); @@ -2957,32 +3261,38 @@ function deserializeJSXElementName(pos) { function deserializeJSXNamespacedName(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXNamespacedName', namespace: null, name: null, start, end, range: [start, end], + parent, }; node.namespace = deserializeJSXIdentifier(pos + 8); node.name = deserializeJSXIdentifier(pos + 32); + parent = previousParent; return node; } function deserializeJSXMemberExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXMemberExpression', object: null, property: null, start, end, range: [start, end], + parent, }; node.object = deserializeJSXMemberExpressionObject(pos + 8); node.property = deserializeJSXIdentifier(pos + 24); + parent = previousParent; return node; } @@ -2996,6 +3306,7 @@ function deserializeJSXMemberExpressionObject(pos) { start: ident.start, end: ident.end, range: ident.range, + parent, }; case 1: return deserializeBoxJSXMemberExpression(pos + 8); @@ -3007,6 +3318,7 @@ function deserializeJSXMemberExpressionObject(pos) { start: thisExpr.start, end: thisExpr.end, range: thisExpr.range, + parent, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for JSXMemberExpressionObject`); @@ -3016,14 +3328,17 @@ function deserializeJSXMemberExpressionObject(pos) { function deserializeJSXExpressionContainer(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXExpressionContainer', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeJSXExpression(pos + 8); + parent = previousParent; return node; } @@ -3129,6 +3444,7 @@ function deserializeJSXEmptyExpression(pos) { start, end, range: [start, end], + parent, }; } @@ -3146,30 +3462,36 @@ function deserializeJSXAttributeItem(pos) { function deserializeJSXAttribute(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXAttribute', name: null, value: null, start, end, range: [start, end], + parent, }; node.name = deserializeJSXAttributeName(pos + 8); node.value = deserializeOptionJSXAttributeValue(pos + 24); + parent = previousParent; return node; } function deserializeJSXSpreadAttribute(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXSpreadAttribute', argument: null, start, end, range: [start, end], + parent, }; node.argument = deserializeExpression(pos + 8); + parent = previousParent; return node; } @@ -3207,6 +3529,7 @@ function deserializeJSXIdentifier(pos) { start, end, range: [start, end], + parent, }; } @@ -3230,14 +3553,17 @@ function deserializeJSXChild(pos) { function deserializeJSXSpreadChild(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'JSXSpreadChild', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); + parent = previousParent; return node; } @@ -3250,13 +3576,15 @@ function deserializeJSXText(pos) { start, end, range: [start, end], + parent, }; } function deserializeTSThisParameter(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: null, @@ -3265,18 +3593,21 @@ function deserializeTSThisParameter(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.name = 'this'; node.optional = false; node.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 16); + parent = previousParent; return node; } function deserializeTSEnumDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSEnumDeclaration', id: null, body: null, @@ -3285,30 +3616,36 @@ function deserializeTSEnumDeclaration(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeBindingIdentifier(pos + 8); node.body = deserializeTSEnumBody(pos + 40); + parent = previousParent; return node; } function deserializeTSEnumBody(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSEnumBody', members: null, start, end, range: [start, end], + parent, }; node.members = deserializeVecTSEnumMember(pos + 8); + parent = previousParent; return node; } function deserializeTSEnumMember(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSEnumMember', id: null, initializer: null, @@ -3316,10 +3653,12 @@ function deserializeTSEnumMember(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeTSEnumMemberName(pos + 8); node.initializer = deserializeOptionExpression(pos + 24); node.computed = deserializeU8(pos + 8) > 1; + parent = previousParent; return node; } @@ -3341,28 +3680,34 @@ function deserializeTSEnumMemberName(pos) { function deserializeTSTypeAnnotation(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeAnnotation', typeAnnotation: null, start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } function deserializeTSLiteralType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSLiteralType', literal: null, start, end, range: [start, end], + parent, }; node.literal = deserializeTSLiteral(pos + 8); + parent = previousParent; return node; } @@ -3469,7 +3814,8 @@ function deserializeTSType(pos) { function deserializeTSConditionalType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSConditionalType', checkType: null, extendsType: null, @@ -3478,39 +3824,47 @@ function deserializeTSConditionalType(pos) { start, end, range: [start, end], + parent, }; node.checkType = deserializeTSType(pos + 8); node.extendsType = deserializeTSType(pos + 24); node.trueType = deserializeTSType(pos + 40); node.falseType = deserializeTSType(pos + 56); + parent = previousParent; return node; } function deserializeTSUnionType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSUnionType', types: null, start, end, range: [start, end], + parent, }; node.types = deserializeVecTSType(pos + 8); + parent = previousParent; return node; } function deserializeTSIntersectionType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSIntersectionType', types: null, start, end, range: [start, end], + parent, }; node.types = deserializeVecTSType(pos + 8); + parent = previousParent; return node; } @@ -3523,15 +3877,18 @@ function deserializeTSParenthesizedType(pos) { function deserializeTSTypeOperator(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeOperator', operator: deserializeTSTypeOperatorOperator(pos + 24), typeAnnotation: null, start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } @@ -3551,51 +3908,61 @@ function deserializeTSTypeOperatorOperator(pos) { function deserializeTSArrayType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSArrayType', elementType: null, start, end, range: [start, end], + parent, }; node.elementType = deserializeTSType(pos + 8); + parent = previousParent; return node; } function deserializeTSIndexedAccessType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSIndexedAccessType', objectType: null, indexType: null, start, end, range: [start, end], + parent, }; node.objectType = deserializeTSType(pos + 8); node.indexType = deserializeTSType(pos + 24); + parent = previousParent; return node; } function deserializeTSTupleType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTupleType', elementTypes: null, start, end, range: [start, end], + parent, }; node.elementTypes = deserializeVecTSTupleElement(pos + 8); + parent = previousParent; return node; } function deserializeTSNamedTupleMember(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSNamedTupleMember', label: null, elementType: null, @@ -3603,37 +3970,45 @@ function deserializeTSNamedTupleMember(pos) { start, end, range: [start, end], + parent, }; node.label = deserializeIdentifierName(pos + 8); node.elementType = deserializeTSTupleElement(pos + 32); + parent = previousParent; return node; } function deserializeTSOptionalType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSOptionalType', typeAnnotation: null, start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } function deserializeTSRestType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSRestType', typeAnnotation: null, start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } @@ -3729,6 +4104,7 @@ function deserializeTSAnyKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3739,6 +4115,7 @@ function deserializeTSStringKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3749,6 +4126,7 @@ function deserializeTSBooleanKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3759,6 +4137,7 @@ function deserializeTSNumberKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3769,6 +4148,7 @@ function deserializeTSNeverKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3779,6 +4159,7 @@ function deserializeTSIntrinsicKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3789,6 +4170,7 @@ function deserializeTSUnknownKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3799,6 +4181,7 @@ function deserializeTSNullKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3809,6 +4192,7 @@ function deserializeTSUndefinedKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3819,6 +4203,7 @@ function deserializeTSVoidKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3829,6 +4214,7 @@ function deserializeTSSymbolKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3839,6 +4225,7 @@ function deserializeTSThisType(pos) { start, end, range: [start, end], + parent, }; } @@ -3849,6 +4236,7 @@ function deserializeTSObjectKeyword(pos) { start, end, range: [start, end], + parent, }; } @@ -3859,22 +4247,26 @@ function deserializeTSBigIntKeyword(pos) { start, end, range: [start, end], + parent, }; } function deserializeTSTypeReference(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeReference', typeName: null, typeArguments: null, start, end, range: [start, end], + parent, }; node.typeName = deserializeTSTypeName(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); + parent = previousParent; return node; } @@ -3894,37 +4286,44 @@ function deserializeTSTypeName(pos) { function deserializeTSQualifiedName(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSQualifiedName', left: null, right: null, start, end, range: [start, end], + parent, }; node.left = deserializeTSTypeName(pos + 8); node.right = deserializeIdentifierName(pos + 24); + parent = previousParent; return node; } function deserializeTSTypeParameterInstantiation(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeParameterInstantiation', params: null, start, end, range: [start, end], + parent, }; node.params = deserializeVecTSType(pos + 8); + parent = previousParent; return node; } function deserializeTSTypeParameter(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeParameter', name: null, constraint: null, @@ -3935,31 +4334,37 @@ function deserializeTSTypeParameter(pos) { start, end, range: [start, end], + parent, }; node.name = deserializeBindingIdentifier(pos + 8); node.constraint = deserializeOptionTSType(pos + 40); node.default = deserializeOptionTSType(pos + 56); + parent = previousParent; return node; } function deserializeTSTypeParameterDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeParameterDeclaration', params: null, start, end, range: [start, end], + parent, }; node.params = deserializeVecTSTypeParameter(pos + 8); + parent = previousParent; return node; } function deserializeTSTypeAliasDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeAliasDeclaration', id: null, typeParameters: null, @@ -3968,10 +4373,12 @@ function deserializeTSTypeAliasDeclaration(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeBindingIdentifier(pos + 8); node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 40); node.typeAnnotation = deserializeTSType(pos + 48); + parent = previousParent; return node; } @@ -3991,13 +4398,15 @@ function deserializeTSAccessibility(pos) { function deserializeTSClassImplements(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSClassImplements', expression: null, typeArguments: null, start, end, range: [start, end], + parent, }, expression = deserializeTSTypeName(pos + 8); if (expression.type === 'TSQualifiedName') { @@ -4014,8 +4423,14 @@ function deserializeTSClassImplements(pos) { start: start = expression.start, end: end = expression.end, range: [start, end], + parent, }; - for (; object.type === 'TSQualifiedName';) { + right.parent = previous; + for (;;) { + if (object.type !== 'TSQualifiedName') { + object.parent = previous; + break; + } let { left, right } = object; previous = previous.object = { type: 'MemberExpression', @@ -4026,19 +4441,23 @@ function deserializeTSClassImplements(pos) { start: start = object.start, end: end = object.end, range: [start, end], + parent: previous, }; + right.parent = previous; object = left; } } node.expression = expression; node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); + parent = previousParent; return node; } function deserializeTSInterfaceDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSInterfaceDeclaration', id: null, typeParameters: null, @@ -4048,32 +4467,38 @@ function deserializeTSInterfaceDeclaration(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeBindingIdentifier(pos + 8); node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 40); node.extends = deserializeVecTSInterfaceHeritage(pos + 48); node.body = deserializeBoxTSInterfaceBody(pos + 72); + parent = previousParent; return node; } function deserializeTSInterfaceBody(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSInterfaceBody', body: null, start, end, range: [start, end], + parent, }; node.body = deserializeVecTSSignature(pos + 8); + parent = previousParent; return node; } function deserializeTSPropertySignature(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSPropertySignature', computed: deserializeBool(pos + 32), optional: deserializeBool(pos + 33), @@ -4085,11 +4510,13 @@ function deserializeTSPropertySignature(pos) { start, end, range: [start, end], + parent, }; node.key = deserializePropertyKey(pos + 8); node.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 24); node.accessibility = null; node.static = false; + parent = previousParent; return node; } @@ -4113,7 +4540,8 @@ function deserializeTSSignature(pos) { function deserializeTSIndexSignature(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSIndexSignature', parameters: null, typeAnnotation: null, @@ -4123,17 +4551,20 @@ function deserializeTSIndexSignature(pos) { start, end, range: [start, end], + parent, }; node.parameters = deserializeVecTSIndexSignatureName(pos + 8); node.typeAnnotation = deserializeBoxTSTypeAnnotation(pos + 32); node.accessibility = null; + parent = previousParent; return node; } function deserializeTSCallSignatureDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSCallSignatureDeclaration', typeParameters: null, params: null, @@ -4141,6 +4572,7 @@ function deserializeTSCallSignatureDeclaration(pos) { start, end, range: [start, end], + parent, }, params = deserializeBoxFormalParameters(pos + 24), thisParam = deserializeOptionBoxTSThisParameter(pos + 16); @@ -4148,6 +4580,7 @@ function deserializeTSCallSignatureDeclaration(pos) { node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); node.params = params; node.returnType = deserializeOptionBoxTSTypeAnnotation(pos + 32); + parent = previousParent; return node; } @@ -4167,7 +4600,8 @@ function deserializeTSMethodSignatureKind(pos) { function deserializeTSMethodSignature(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSMethodSignature', key: null, computed: deserializeBool(pos + 60), @@ -4182,6 +4616,7 @@ function deserializeTSMethodSignature(pos) { start, end, range: [start, end], + parent, }, params = deserializeBoxFormalParameters(pos + 40), thisParam = deserializeOptionBoxTSThisParameter(pos + 32); @@ -4193,13 +4628,15 @@ function deserializeTSMethodSignature(pos) { node.accessibility = null; node.readonly = false; node.static = false; + parent = previousParent; return node; } function deserializeTSConstructSignatureDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSConstructSignatureDeclaration', typeParameters: null, params: null, @@ -4207,17 +4644,20 @@ function deserializeTSConstructSignatureDeclaration(pos) { start, end, range: [start, end], + parent, }; node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); node.params = deserializeBoxFormalParameters(pos + 16); node.returnType = deserializeOptionBoxTSTypeAnnotation(pos + 24); + parent = previousParent; return node; } function deserializeTSIndexSignatureName(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Identifier', decorators: null, name: deserializeStr(pos + 8), @@ -4226,33 +4666,39 @@ function deserializeTSIndexSignatureName(pos) { start, end, range: [start, end], + parent, }; node.decorators = []; node.optional = false; node.typeAnnotation = deserializeBoxTSTypeAnnotation(pos + 24); + parent = previousParent; return node; } function deserializeTSInterfaceHeritage(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSInterfaceHeritage', expression: null, typeArguments: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); + parent = previousParent; return node; } function deserializeTSTypePredicate(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypePredicate', parameterName: null, asserts: deserializeBool(pos + 32), @@ -4260,9 +4706,11 @@ function deserializeTSTypePredicate(pos) { start, end, range: [start, end], + parent, }; node.parameterName = deserializeTSTypePredicateName(pos + 8); node.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 24); + parent = previousParent; return node; } @@ -4284,9 +4732,10 @@ function deserializeTSModuleDeclaration(pos) { end = deserializeU32(pos + 4), declare = deserializeBool(pos + 85), node, + previousParent = parent, body = deserializeOptionTSModuleDeclarationBody(pos + 64); if (body === null) { - node = { + node = parent = { type: 'TSModuleDeclaration', id: null, kind, @@ -4295,10 +4744,11 @@ function deserializeTSModuleDeclaration(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeTSModuleDeclarationName(pos + 8); } else { - node = { + node = parent = { type: 'TSModuleDeclaration', id: null, body, @@ -4308,25 +4758,34 @@ function deserializeTSModuleDeclaration(pos) { start, end, range: [start, end], + parent, }; let id = deserializeTSModuleDeclarationName(pos + 8); - if (body.type === 'TSModuleBlock') node.id = id; - else { + if (body.type === 'TSModuleBlock') { + node.id = id; + body.parent = node; + } else { let innerId = body.id; if (innerId.type === 'Identifier') { let start, end; - node.id = { - type: 'TSQualifiedName', - left: id, - right: innerId, - start: start = id.start, - end: end = innerId.end, - range: [start, end], - }; + id.parent = + innerId.parent = + node.id = + parent = + { + type: 'TSQualifiedName', + left: id, + right: innerId, + start: start = id.start, + end: end = innerId.end, + range: [start, end], + parent: node, + }; } else { // Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of // this module on left, and previous `left` of innermost `TSQualifiedName` on right node.id = innerId; + innerId.parent = node; let { start } = id; for (;;) { innerId.start = innerId.range[0] = start; @@ -4334,21 +4793,24 @@ function deserializeTSModuleDeclaration(pos) { innerId = innerId.left; } let end, right = innerId.left; - innerId.left = { + id.parent = right.parent = innerId.left = { type: 'TSQualifiedName', left: id, right, start, end: end = right.end, range: [start, end], + parent: innerId, }; } if (Object.hasOwn(body, 'body')) { body = body.body; node.body = body; + body.parent = node; } else body = null; } } + parent = previousParent; return node; } @@ -4390,60 +4852,72 @@ function deserializeTSModuleDeclarationBody(pos) { function deserializeTSModuleBlock(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSModuleBlock', body: null, start, end, range: [start, end], + parent, }, body = deserializeVecDirective(pos + 8); body.push(...deserializeVecStatement(pos + 32)); node.body = body; + parent = previousParent; return node; } function deserializeTSTypeLiteral(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeLiteral', members: null, start, end, range: [start, end], + parent, }; node.members = deserializeVecTSSignature(pos + 8); + parent = previousParent; return node; } function deserializeTSInferType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSInferType', typeParameter: null, start, end, range: [start, end], + parent, }; node.typeParameter = deserializeBoxTSTypeParameter(pos + 8); + parent = previousParent; return node; } function deserializeTSTypeQuery(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeQuery', exprName: null, typeArguments: null, start, end, range: [start, end], + parent, }; node.exprName = deserializeTSTypeQueryExprName(pos + 8); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 24); + parent = previousParent; return node; } @@ -4465,7 +4939,8 @@ function deserializeTSTypeQueryExprName(pos) { function deserializeTSImportType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSImportType', argument: null, options: null, @@ -4474,11 +4949,13 @@ function deserializeTSImportType(pos) { start, end, range: [start, end], + parent, }; node.argument = deserializeTSType(pos + 8); node.options = deserializeOptionBoxObjectExpression(pos + 24); node.qualifier = deserializeOptionTSImportTypeQualifier(pos + 32); node.typeArguments = deserializeOptionBoxTSTypeParameterInstantiation(pos + 48); + parent = previousParent; return node; } @@ -4496,23 +4973,27 @@ function deserializeTSImportTypeQualifier(pos) { function deserializeTSImportTypeQualifiedName(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSQualifiedName', left: null, right: null, start, end, range: [start, end], + parent, }; node.left = deserializeTSImportTypeQualifier(pos + 8); node.right = deserializeIdentifierName(pos + 24); + parent = previousParent; return node; } function deserializeTSFunctionType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSFunctionType', typeParameters: null, params: null, @@ -4520,6 +5001,7 @@ function deserializeTSFunctionType(pos) { start, end, range: [start, end], + parent, }, params = deserializeBoxFormalParameters(pos + 24), thisParam = deserializeOptionBoxTSThisParameter(pos + 16); @@ -4527,13 +5009,15 @@ function deserializeTSFunctionType(pos) { node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); node.params = params; node.returnType = deserializeBoxTSTypeAnnotation(pos + 32); + parent = previousParent; return node; } function deserializeTSConstructorType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSConstructorType', abstract: deserializeBool(pos + 32), typeParameters: null, @@ -4542,17 +5026,20 @@ function deserializeTSConstructorType(pos) { start, end, range: [start, end], + parent, }; node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); node.params = deserializeBoxFormalParameters(pos + 16); node.returnType = deserializeBoxTSTypeAnnotation(pos + 24); + parent = previousParent; return node; } function deserializeTSMappedType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSMappedType', key: null, constraint: null, @@ -4563,17 +5050,21 @@ function deserializeTSMappedType(pos) { start, end, range: [start, end], + parent, }, typeParameter = deserializeBoxTSTypeParameter(pos + 8), - key = typeParameter.name, - { constraint } = typeParameter, - optional = deserializeOptionTSMappedTypeModifierOperator(pos + 52); + key = typeParameter.name; + key.parent = parent; + let { constraint } = typeParameter; + constraint !== null && (constraint.parent = parent); + let optional = deserializeOptionTSMappedTypeModifierOperator(pos + 52); optional === null && (optional = false); node.key = key; node.constraint = constraint; node.nameType = deserializeOptionTSType(pos + 16); node.typeAnnotation = deserializeOptionTSType(pos + 32); node.optional = optional; + parent = previousParent; return node; } @@ -4593,71 +5084,84 @@ function deserializeTSMappedTypeModifierOperator(pos) { function deserializeTSTemplateLiteralType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTemplateLiteralType', quasis: null, types: null, start, end, range: [start, end], + parent, }; node.quasis = deserializeVecTemplateElement(pos + 8); node.types = deserializeVecTSType(pos + 32); + parent = previousParent; return node; } function deserializeTSAsExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSAsExpression', expression: null, typeAnnotation: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); node.typeAnnotation = deserializeTSType(pos + 24); + parent = previousParent; return node; } function deserializeTSSatisfiesExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSSatisfiesExpression', expression: null, typeAnnotation: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); node.typeAnnotation = deserializeTSType(pos + 24); + parent = previousParent; return node; } function deserializeTSTypeAssertion(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSTypeAssertion', typeAnnotation: null, expression: null, start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); node.expression = deserializeExpression(pos + 24); + parent = previousParent; return node; } function deserializeTSImportEqualsDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSImportEqualsDeclaration', id: null, moduleReference: null, @@ -4665,9 +5169,11 @@ function deserializeTSImportEqualsDeclaration(pos) { start, end, range: [start, end], + parent, }; node.id = deserializeBindingIdentifier(pos + 8); node.moduleReference = deserializeTSModuleReference(pos + 40); + parent = previousParent; return node; } @@ -4689,86 +5195,104 @@ function deserializeTSModuleReference(pos) { function deserializeTSExternalModuleReference(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSExternalModuleReference', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeStringLiteral(pos + 8); + parent = previousParent; return node; } function deserializeTSNonNullExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSNonNullExpression', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); + parent = previousParent; return node; } function deserializeDecorator(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'Decorator', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); + parent = previousParent; return node; } function deserializeTSExportAssignment(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSExportAssignment', expression: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); + parent = previousParent; return node; } function deserializeTSNamespaceExportDeclaration(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSNamespaceExportDeclaration', id: null, start, end, range: [start, end], + parent, }; node.id = deserializeIdentifierName(pos + 8); + parent = previousParent; return node; } function deserializeTSInstantiationExpression(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSInstantiationExpression', expression: null, typeArguments: null, start, end, range: [start, end], + parent, }; node.expression = deserializeExpression(pos + 8); node.typeArguments = deserializeBoxTSTypeParameterInstantiation(pos + 24); + parent = previousParent; return node; } @@ -4786,30 +5310,36 @@ function deserializeImportOrExportKind(pos) { function deserializeJSDocNullableType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSJSDocNullableType', typeAnnotation: null, postfix: deserializeBool(pos + 24), start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } function deserializeJSDocNonNullableType(pos) { let start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type: 'TSJSDocNonNullableType', typeAnnotation: null, postfix: deserializeBool(pos + 24), start, end, range: [start, end], + parent, }; node.typeAnnotation = deserializeTSType(pos + 8); + parent = previousParent; return node; } @@ -4820,6 +5350,7 @@ function deserializeJSDocUnknownType(pos) { start, end, range: [start, end], + parent, }; } @@ -4838,15 +5369,18 @@ function deserializeComment(pos) { let type = deserializeCommentKind(pos + 12), start = deserializeU32(pos), end = deserializeU32(pos + 4), - node = { + previousParent = parent, + node = parent = { type, value: null, start, end, range: [start, end], + parent, }, endCut = type === 'Line' ? 0 : 2; node.value = sourceText.slice(start + 2, end - endCut); + parent = previousParent; return node; } diff --git a/tasks/ast_tools/src/generators/raw_transfer.rs b/tasks/ast_tools/src/generators/raw_transfer.rs index 170556a1b6321..578588b15d88b 100644 --- a/tasks/ast_tools/src/generators/raw_transfer.rs +++ b/tasks/ast_tools/src/generators/raw_transfer.rs @@ -248,7 +248,7 @@ fn generate_deserializers( } // `PRESERVE_PARENS = false` is only required for linter - create_deserializer(true, true, false, false); + create_deserializer(true, true, true, false); deserializers }