diff --git a/.github/generated/ast_changes_watch_list.yml b/.github/generated/ast_changes_watch_list.yml index bf902358c8976..7b65f100d81ed 100644 --- a/.github/generated/ast_changes_watch_list.yml +++ b/.github/generated/ast_changes_watch_list.yml @@ -76,8 +76,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_loc_parent_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 3450568945f28..c71a85184ca9d 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_parent_no_parens.js', + 'generated/deserialize/ts_range_loc_parent_no_parens.js', 'generated/visit/keys.js', 'generated/visit/types.js', 'generated/visit/walk.js', diff --git a/apps/oxlint/src-js/generated/types.d.ts b/apps/oxlint/src-js/generated/types.d.ts index 2a2046a210554..595edae84d6af 100644 --- a/apps/oxlint/src-js/generated/types.d.ts +++ b/apps/oxlint/src-js/generated/types.d.ts @@ -1,6 +1,9 @@ // Auto-generated code, DO NOT EDIT DIRECTLY! // To edit this generated file you have to edit `tasks/ast_tools/src/generators/typescript.rs`. +import { Span } from '../plugins/types.ts'; +export { Span }; + export interface Program extends Span { type: 'Program'; body: Array; @@ -1701,12 +1704,6 @@ export type UnaryOperator = '+' | '-' | '!' | '~' | 'typeof' | 'void' | 'delete' export type UpdateOperator = '++' | '--'; -export interface Span { - start: number; - end: number; - range: [number, number]; -} - export type ModuleKind = 'script' | 'module'; export type Node = diff --git a/apps/oxlint/src-js/index.ts b/apps/oxlint/src-js/index.ts index a3425202fbfcb..7578cb3436344 100644 --- a/apps/oxlint/src-js/index.ts +++ b/apps/oxlint/src-js/index.ts @@ -27,6 +27,7 @@ export type { Range, Ranged, RuleMeta, + Span, Token, Visitor, VisitorWithHooks, diff --git a/apps/oxlint/src-js/plugins/location.ts b/apps/oxlint/src-js/plugins/location.ts index a24fa270eead4..ff65e6fdb4928 100644 --- a/apps/oxlint/src-js/plugins/location.ts +++ b/apps/oxlint/src-js/plugins/location.ts @@ -1,6 +1,8 @@ import { initSourceText, sourceText } from './source_code.js'; -import type { LineColumn } from './types.ts'; +import type { LineColumn, Location, Node } from './types.ts'; + +const { defineProperty } = Object; // Pattern for splitting source text into lines const LINE_BREAK_PATTERN = /\r\n|[\r\n\u2028\u2029]/gu; @@ -69,6 +71,18 @@ export function getLineColumnFromOffset(offset: number): LineColumn { ); } + return getLineColumnFromOffsetUnchecked(offset); +} + +/** + * Convert a source text index into a (line, column) pair without: + * 1. Checking type of `offset`, or that it's in range. + * 2. Initializing `lineStartOffsets`. Caller must do that before calling this method. + * + * @param offset - The index of a character in a file. + * @returns `{line, column}` location object with 1-indexed line and 0-indexed column. + */ +function getLineColumnFromOffsetUnchecked(offset: number): LineColumn { // Binary search `lineStartOffsets` for the line containing `offset` let low = 0, high = lineStartOffsets.length, mid: number; do { @@ -138,3 +152,30 @@ export function getOffsetFromLineColumn(loc: LineColumn): number { throw new TypeError('Expected `loc` to be an object with integer `line` and `column` properties.'); } + +/** + * Get the `Location` for an AST node. Used in `loc` getters on AST nodes. + * + * Overwrites the `loc` getter with the calculated `Location`, so accessing `loc` twice on same node + * results in the same object each time. + * + * For internal use only. + * + * @param node - AST node object + * @returns Location + */ +export function getNodeLoc(node: Node): Location { + // Build `lines` and `lineStartOffsets` tables if they haven't been already. + // This also decodes `sourceText` if it wasn't already. + if (lines.length === 0) initLines(); + + const loc = { + start: getLineColumnFromOffsetUnchecked(node.start), + end: getLineColumnFromOffsetUnchecked(node.end), + }; + + // Replace `loc` getter with the calculated value + defineProperty(node, 'loc', { value: loc, writable: true }); + + return loc; +} diff --git a/apps/oxlint/src-js/plugins/source_code.ts b/apps/oxlint/src-js/plugins/source_code.ts index 864ec8286335a..aca8274ff2e50 100644 --- a/apps/oxlint/src-js/plugins/source_code.ts +++ b/apps/oxlint/src-js/plugins/source_code.ts @@ -6,9 +6,18 @@ import { // @ts-expect-error } 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_parent_no_parens.js'; -import { getLineColumnFromOffset, getOffsetFromLineColumn, initLines, lines, resetLines } from './location.js'; +// We use the deserializer which removes `ParenthesizedExpression`s from AST, +// and with `range`, `loc`, and `parent` properties on AST nodes, to match ESLint +import { deserializeProgramOnly } from '../../dist/generated/deserialize/ts_range_loc_parent_no_parens.js'; + +import { + getLineColumnFromOffset, + getNodeLoc, + getOffsetFromLineColumn, + initLines, + lines, + resetLines, +} from './location.js'; import type { Program } from '../generated/types.d.ts'; import type { Scope, ScopeManager, Variable } from './scope.ts'; @@ -61,7 +70,7 @@ export function initSourceText(): void { */ export function initAst(): void { if (sourceText === null) initSourceText(); - ast = deserializeProgramOnly(buffer, sourceText, sourceByteLen); + ast = deserializeProgramOnly(buffer, sourceText, sourceByteLen, getNodeLoc); } /** diff --git a/apps/oxlint/src-js/plugins/types.ts b/apps/oxlint/src-js/plugins/types.ts index 1d0ddc38e1d41..4efdf2346d341 100644 --- a/apps/oxlint/src-js/plugins/types.ts +++ b/apps/oxlint/src-js/plugins/types.ts @@ -25,21 +25,21 @@ export interface VisitorWithHooks extends Visitor { // Visit function for a specific AST node type. export type VisitFn = (node: Node) => void; +// Range of source offsets. +export type Range = [number, number]; + // Interface for any type which has `range` field export interface Ranged { range: Range; } -// Internal interface for any type which has location properties. -interface Spanned extends Ranged { +// Interface for any type which has location properties. +export interface Span extends Ranged { start: number; end: number; - loc?: Location; + loc: Location; } -// Range of source offsets. -export type Range = [number, number]; - // Source code location. export interface Location { start: LineColumn; @@ -54,10 +54,10 @@ export interface LineColumn { } // AST node type. -export interface Node extends Spanned {} +export interface Node extends Span {} // AST token type. -export interface Token extends Spanned { +export interface Token extends Span { type: string; value: string; } @@ -66,7 +66,7 @@ export interface Token extends Spanned { export type NodeOrToken = Node | Token; // Comment. -export interface Comment extends Spanned { +export interface Comment extends Span { type: 'Line' | 'Block'; value: string; } diff --git a/apps/oxlint/test/compile-visitor.test.ts b/apps/oxlint/test/compile-visitor.test.ts index cba23c0351045..45292740b066a 100644 --- a/apps/oxlint/test/compile-visitor.test.ts +++ b/apps/oxlint/test/compile-visitor.test.ts @@ -20,7 +20,15 @@ import type { EnterExit, Node, VisitFn } from '../src-js/plugins/types.ts'; const PROGRAM_TYPE_ID = NODE_TYPE_IDS_MAP.get('Program'), EMPTY_STMT_TYPE_ID = NODE_TYPE_IDS_MAP.get('EmptyStatement'); -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; describe('compile visitor', () => { beforeEach(initCompiledVisitor); diff --git a/apps/oxlint/test/fixtures/context_properties/plugin.ts b/apps/oxlint/test/fixtures/context_properties/plugin.ts index feddd7dcf3eee..59a2ba45e47b5 100644 --- a/apps/oxlint/test/fixtures/context_properties/plugin.ts +++ b/apps/oxlint/test/fixtures/context_properties/plugin.ts @@ -2,7 +2,15 @@ import { sep } from 'node:path'; import type { Node, Plugin, Rule } from '../../../dist/index.js'; -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; const DIR_PATH_LEN = import.meta.dirname.length + 1; diff --git a/apps/oxlint/test/fixtures/createOnce/plugin.ts b/apps/oxlint/test/fixtures/createOnce/plugin.ts index a855c53f4ea08..ac94bdbde7182 100644 --- a/apps/oxlint/test/fixtures/createOnce/plugin.ts +++ b/apps/oxlint/test/fixtures/createOnce/plugin.ts @@ -2,7 +2,15 @@ import { sep } from 'node:path'; import type { Node, Plugin, Rule } from '../../../dist/index.js'; -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; const DIR_PATH_LEN = import.meta.dirname.length + 1; diff --git a/apps/oxlint/test/fixtures/definePlugin/plugin.ts b/apps/oxlint/test/fixtures/definePlugin/plugin.ts index b8d92de77a37a..ba9f62704173a 100644 --- a/apps/oxlint/test/fixtures/definePlugin/plugin.ts +++ b/apps/oxlint/test/fixtures/definePlugin/plugin.ts @@ -3,7 +3,6 @@ import { definePlugin } from '../../../dist/index.js'; import type { Node, Rule } from '../../../dist/index.js'; -// `loc` is required for ESLint const SPAN: Node = { start: 0, end: 0, diff --git a/apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.ts b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.ts index 1aaa346d6723c..7f94641eb586b 100644 --- a/apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.ts +++ b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.ts @@ -3,7 +3,6 @@ import { definePlugin, defineRule } from '../../../dist/index.js'; import type { Node } from '../../../dist/index.js'; -// `loc` is required for ESLint const SPAN: Node = { start: 0, end: 0, diff --git a/apps/oxlint/test/fixtures/defineRule/plugin.ts b/apps/oxlint/test/fixtures/defineRule/plugin.ts index f559efedf29b7..534bb47319297 100644 --- a/apps/oxlint/test/fixtures/defineRule/plugin.ts +++ b/apps/oxlint/test/fixtures/defineRule/plugin.ts @@ -3,7 +3,6 @@ import { defineRule } from '../../../dist/index.js'; import type { Node } from '../../../dist/index.js'; -// `loc` is required for ESLint const SPAN: Node = { start: 0, end: 0, diff --git a/apps/oxlint/test/fixtures/estree/output.snap.md b/apps/oxlint/test/fixtures/estree/output.snap.md index e015720d7e793..f844a840b6ce9 100644 --- a/apps/oxlint/test/fixtures/estree/output.snap.md +++ b/apps/oxlint/test/fixtures/estree/output.snap.md @@ -50,6 +50,7 @@ x estree-check(check): program: | start/end: [59,265] | range: [59,265] + | loc: [{"start":{"line":5,"column":0},"end":{"line":15,"column":0}}] ,-[files/index.ts:5:1] 4 | // All `Identifier`s 5 | ,-> let a = { x: y }; @@ -67,6 +68,7 @@ x estree-check(check): ident "a": | start/end: [63,64] | range: [63,64] + | loc: [{"start":{"line":5,"column":4},"end":{"line":5,"column":5}}] ,-[files/index.ts:5:5] 4 | // All `Identifier`s 5 | let a = { x: y }; @@ -77,6 +79,7 @@ x estree-check(check): ident "x": | start/end: [69,70] | range: [69,70] + | loc: [{"start":{"line":5,"column":10},"end":{"line":5,"column":11}}] ,-[files/index.ts:5:11] 4 | // All `Identifier`s 5 | let a = { x: y }; @@ -87,6 +90,7 @@ x estree-check(check): ident "y": | start/end: [72,73] | range: [72,73] + | loc: [{"start":{"line":5,"column":13},"end":{"line":5,"column":14}}] ,-[files/index.ts:5:14] 4 | // All `Identifier`s 5 | let a = { x: y }; @@ -97,6 +101,7 @@ x estree-check(check): ident "b": | start/end: [124,125] | range: [124,125] + | loc: [{"start":{"line":8,"column":6},"end":{"line":8,"column":7}}] ,-[files/index.ts:8:7] 7 | // No `ParenthesizedExpression`s in AST 8 | const b = (x * ((('str' + ((123)))))); @@ -107,6 +112,7 @@ x estree-check(check): ident "x": | start/end: [129,130] | range: [129,130] + | loc: [{"start":{"line":8,"column":11},"end":{"line":8,"column":12}}] ,-[files/index.ts:8:12] 7 | // No `ParenthesizedExpression`s in AST 8 | const b = (x * ((('str' + ((123)))))); @@ -117,6 +123,7 @@ x estree-check(check): ident "T": | start/end: [176,177] | range: [176,177] + | loc: [{"start":{"line":11,"column":5},"end":{"line":11,"column":6}}] ,-[files/index.ts:11:6] 10 | // TS syntax 11 | type T = string; @@ -127,6 +134,7 @@ x estree-check(check): ident "U": | start/end: [230,231] | range: [230,231] + | loc: [{"start":{"line":14,"column":5},"end":{"line":14,"column":6}}] ,-[files/index.ts:14:6] 13 | // No `TSParenthesizedType`s in AST 14 | type U = (((((string)) | ((number))))); diff --git a/apps/oxlint/test/fixtures/estree/plugin.ts b/apps/oxlint/test/fixtures/estree/plugin.ts index 1748622af1f0e..8a01ae14c218d 100644 --- a/apps/oxlint/test/fixtures/estree/plugin.ts +++ b/apps/oxlint/test/fixtures/estree/plugin.ts @@ -1,3 +1,5 @@ +import assert from 'node:assert'; + import type { Plugin } from '../../../dist/index.js'; const plugin: Plugin = { @@ -16,7 +18,8 @@ const plugin: Plugin = { context.report({ message: 'program:\n' + `start/end: [${program.start},${program.end}]\n` + - `range: [${program.range}]`, + `range: [${program.range}]\n` + + `loc: [${JSON.stringify(program.loc)}]`, node: program, }); visits.push(program.type); @@ -32,10 +35,16 @@ const plugin: Plugin = { visits.push(`${decl.type}: (init: ${decl.init.type})`); }, Identifier(ident) { + // Check `loc` property returns same object each time it's accessed + const { loc } = ident; + const loc2 = ident.loc; + assert(loc2 === loc); + context.report({ message: `ident "${ident.name}":\n` + `start/end: [${ident.start},${ident.end}]\n` + - `range: [${ident.range}]`, + `range: [${ident.range}]\n` + + `loc: [${JSON.stringify(loc)}]`, node: ident, }); visits.push(`${ident.type}: ${ident.name}`); diff --git a/apps/oxlint/test/fixtures/sourceCode/plugin.ts b/apps/oxlint/test/fixtures/sourceCode/plugin.ts index 9028fbbda97ad..48634df6d4ff5 100644 --- a/apps/oxlint/test/fixtures/sourceCode/plugin.ts +++ b/apps/oxlint/test/fixtures/sourceCode/plugin.ts @@ -4,7 +4,15 @@ import type { ESTree, Node, Plugin, Rule } from '../../../dist/index.js'; type Program = ESTree.Program; -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; const createRule: Rule = { create(context) { diff --git a/apps/oxlint/test/fixtures/sourceCode_late_access/plugin.ts b/apps/oxlint/test/fixtures/sourceCode_late_access/plugin.ts index 3b96d3fdcf1ff..ce7cdaa0518b6 100644 --- a/apps/oxlint/test/fixtures/sourceCode_late_access/plugin.ts +++ b/apps/oxlint/test/fixtures/sourceCode_late_access/plugin.ts @@ -4,7 +4,15 @@ import type { ESTree, Node, Plugin, Rule } from '../../../dist/index.js'; type Program = ESTree.Program; -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; // Purpose of this test fixture is to ensure that AST is not deserialized twice // if `context.sourceCode.ast` is accessed during AST traversal. diff --git a/apps/oxlint/test/fixtures/sourceCode_late_access_after_only/plugin.ts b/apps/oxlint/test/fixtures/sourceCode_late_access_after_only/plugin.ts index d6748071a6dee..8c18c5bdcee9e 100644 --- a/apps/oxlint/test/fixtures/sourceCode_late_access_after_only/plugin.ts +++ b/apps/oxlint/test/fixtures/sourceCode_late_access_after_only/plugin.ts @@ -1,6 +1,14 @@ import type { Node, Plugin, Rule } from '../../../dist/index.js'; -const SPAN: Node = { start: 0, end: 0, range: [0, 0] }; +const SPAN: Node = { + start: 0, + end: 0, + range: [0, 0], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 }, + }, +}; // Purpose of this test fixture is to ensure that source text and AST are available in `after` hook // via `context.sourceCode` when the AST is not traversed diff --git a/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md b/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md index 6a268312cbba4..edeef4640c8b2 100644 --- a/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md +++ b/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md @@ -14,6 +14,7 @@ x utf16-plugin(no-debugger): debugger: | start/end: [0,9] | range: [0,9] + | loc: [{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}] ,-[files/index.js:1:1] 1 | debugger; : ^^^^^^^^^ @@ -23,6 +24,7 @@ x utf16-plugin(no-debugger): program: | start/end: [0,47] | range: [0,47] + | loc: [{"start":{"line":1,"column":0},"end":{"line":8,"column":0}}] ,-[files/index.js:1:1] 1 | ,-> debugger; 2 | | // £ @@ -45,6 +47,7 @@ x utf16-plugin(no-debugger): debugger: | start/end: [15,24] | range: [15,24] + | loc: [{"start":{"line":3,"column":0},"end":{"line":3,"column":9}}] ,-[files/index.js:3:1] 2 | // £ 3 | debugger; @@ -64,6 +67,7 @@ x utf16-plugin(no-debugger): debugger: | start/end: [35,44] | range: [35,44] + | loc: [{"start":{"line":6,"column":2},"end":{"line":6,"column":11}}] ,-[files/index.js:6:3] 5 | { 6 | debugger; diff --git a/apps/oxlint/test/fixtures/utf16_offsets/plugin.ts b/apps/oxlint/test/fixtures/utf16_offsets/plugin.ts index 3f14fa28e8b35..ce4244439b88f 100644 --- a/apps/oxlint/test/fixtures/utf16_offsets/plugin.ts +++ b/apps/oxlint/test/fixtures/utf16_offsets/plugin.ts @@ -12,7 +12,8 @@ const plugin: Plugin = { context.report({ message: 'program:\n' + `start/end: [${program.start},${program.end}]\n` + - `range: [${program.range}]`, + `range: [${program.range}]\n` + + `loc: [${JSON.stringify(program.loc)}]`, node: program, }); }, @@ -20,7 +21,8 @@ const plugin: Plugin = { context.report({ message: 'debugger:\n' + `start/end: [${debuggerStatement.start},${debuggerStatement.end}]\n` + - `range: [${debuggerStatement.range}]`, + `range: [${debuggerStatement.range}]\n` + + `loc: [${JSON.stringify(debuggerStatement.loc)}]`, node: debuggerStatement, }); }, diff --git a/napi/parser/generated/deserialize/js.js b/napi/parser/generated/deserialize/js.js index 376899359cea5..90907270d20d8 100644 --- a/napi/parser/generated/deserialize/js.js +++ b/napi/parser/generated/deserialize/js.js @@ -7,14 +7,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), { fromCodePoint } = String; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/js_parent.js b/napi/parser/generated/deserialize/js_parent.js index ff96044c1d1c9..30bf9ae4a8816 100644 --- a/napi/parser/generated/deserialize/js_parent.js +++ b/napi/parser/generated/deserialize/js_parent.js @@ -8,14 +8,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), let parent = null; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/js_range.js b/napi/parser/generated/deserialize/js_range.js index a0ef0eeadf974..f3184980cec8e 100644 --- a/napi/parser/generated/deserialize/js_range.js +++ b/napi/parser/generated/deserialize/js_range.js @@ -7,14 +7,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), { fromCodePoint } = String; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/js_range_parent.js b/napi/parser/generated/deserialize/js_range_parent.js index 432e005800d37..9e9027c0045f2 100644 --- a/napi/parser/generated/deserialize/js_range_parent.js +++ b/napi/parser/generated/deserialize/js_range_parent.js @@ -8,14 +8,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), let parent = null; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/ts.js b/napi/parser/generated/deserialize/ts.js index 08f5cdc215a27..88adaf03b119a 100644 --- a/napi/parser/generated/deserialize/ts.js +++ b/napi/parser/generated/deserialize/ts.js @@ -7,14 +7,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), { fromCodePoint } = String; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/ts_parent.js b/napi/parser/generated/deserialize/ts_parent.js index 80b41121feac0..f39d4c638d23d 100644 --- a/napi/parser/generated/deserialize/ts_parent.js +++ b/napi/parser/generated/deserialize/ts_parent.js @@ -8,14 +8,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), let parent = null; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/ts_range.js b/napi/parser/generated/deserialize/ts_range.js index eaffe148e721d..cf42d4a6c9bb9 100644 --- a/napi/parser/generated/deserialize/ts_range.js +++ b/napi/parser/generated/deserialize/ts_range.js @@ -7,14 +7,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), { fromCodePoint } = String; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/napi/parser/generated/deserialize/ts_range_parent_no_parens.js b/napi/parser/generated/deserialize/ts_range_loc_parent_no_parens.js similarity index 93% rename from napi/parser/generated/deserialize/ts_range_parent_no_parens.js rename to napi/parser/generated/deserialize/ts_range_loc_parent_no_parens.js index fc1c85b00f3d1..d4276e73b50d3 100644 --- a/napi/parser/generated/deserialize/ts_range_parent_no_parens.js +++ b/napi/parser/generated/deserialize/ts_range_loc_parent_no_parens.js @@ -5,23 +5,24 @@ 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; +let parent = null, getLoc; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; sourceText = sourceTextInput; sourceByteLen = sourceByteLenInput; sourceIsAscii = sourceText.length === sourceByteLen; + getLoc = getLocInput; let data = deserialize(uint32[536870902]); uint8 = uint32 = @@ -41,6 +42,9 @@ function deserializeProgram(pos) { start: 0, end, range: [0, end], + get loc() { + return getLoc(this); + }, parent: null, }; program.hashbang = deserializeOptionHashbang(pos + 48); @@ -171,6 +175,9 @@ function deserializeIdentifierName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -193,6 +200,9 @@ function deserializeIdentifierReference(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -215,6 +225,9 @@ function deserializeBindingIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -237,6 +250,9 @@ function deserializeLabelIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -253,6 +269,9 @@ function deserializeThisExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -267,6 +286,9 @@ function deserializeArrayExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.elements = deserializeVecArrayExpressionElement(pos + 8); @@ -385,6 +407,9 @@ function deserializeObjectExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.properties = deserializeVecObjectPropertyKind(pos + 8); @@ -419,6 +444,9 @@ function deserializeObjectProperty(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.key = deserializePropertyKey(pos + 8); @@ -549,6 +577,9 @@ function deserializeTemplateLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.quasis = deserializeVecTemplateElement(pos + 8); @@ -569,6 +600,9 @@ function deserializeTaggedTemplateExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.tag = deserializeExpression(pos + 8); @@ -592,6 +626,9 @@ function deserializeTemplateElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -616,6 +653,9 @@ function deserializeComputedMemberExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.object = deserializeExpression(pos + 8); @@ -638,6 +678,9 @@ function deserializeStaticMemberExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.object = deserializeExpression(pos + 8); @@ -660,6 +703,9 @@ function deserializePrivateFieldExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.object = deserializeExpression(pos + 8); @@ -682,6 +728,9 @@ function deserializeCallExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.callee = deserializeExpression(pos + 8); @@ -703,6 +752,9 @@ function deserializeNewExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.callee = deserializeExpression(pos + 8); @@ -723,6 +775,9 @@ function deserializeMetaProperty(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.meta = deserializeIdentifierName(pos + 8); @@ -741,6 +796,9 @@ function deserializeSpreadElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeExpression(pos + 8); @@ -855,6 +913,9 @@ function deserializeUpdateExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeSimpleAssignmentTarget(pos + 8); @@ -874,6 +935,9 @@ function deserializeUnaryExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeExpression(pos + 8); @@ -894,6 +958,9 @@ function deserializeBinaryExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeExpression(pos + 8); @@ -914,6 +981,9 @@ function deserializePrivateInExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializePrivateIdentifier(pos + 8); @@ -935,6 +1005,9 @@ function deserializeLogicalExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeExpression(pos + 8); @@ -955,6 +1028,9 @@ function deserializeConditionalExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.test = deserializeExpression(pos + 8); @@ -976,6 +1052,9 @@ function deserializeAssignmentExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeAssignmentTarget(pos + 8); @@ -1047,6 +1126,9 @@ function deserializeArrayAssignmentTarget(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, elements = deserializeVecOptionAssignmentTargetMaybeDefault(pos + 8), @@ -1073,6 +1155,9 @@ function deserializeObjectAssignmentTarget(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, properties = deserializeVecAssignmentTargetProperty(pos + 8), @@ -1100,6 +1185,9 @@ function deserializeAssignmentTargetRest(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -1154,6 +1242,9 @@ function deserializeAssignmentTargetWithDefault(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -1192,6 +1283,9 @@ function deserializeAssignmentTargetPropertyIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, key = deserializeIdentifierReference(pos + 8), @@ -1209,6 +1303,9 @@ function deserializeAssignmentTargetPropertyIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; left.parent = value; @@ -1242,6 +1339,9 @@ function deserializeAssignmentTargetPropertyProperty(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.kind = 'init'; @@ -1264,6 +1364,9 @@ function deserializeSequenceExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expressions = deserializeVecExpression(pos + 8); @@ -1278,6 +1381,9 @@ function deserializeSuper(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -1292,6 +1398,9 @@ function deserializeAwaitExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeExpression(pos + 8); @@ -1309,6 +1418,9 @@ function deserializeChainExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeChainElement(pos + 8); @@ -1421,6 +1533,9 @@ function deserializeDirective(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeStringLiteral(pos + 8); @@ -1436,6 +1551,9 @@ function deserializeHashbang(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -1450,6 +1568,9 @@ function deserializeBlockStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.body = deserializeVecStatement(pos + 8); @@ -1492,6 +1613,9 @@ function deserializeVariableDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.declarations = deserializeVecVariableDeclarator(pos + 8); @@ -1528,6 +1652,9 @@ function deserializeVariableDeclarator(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeBindingPattern(pos + 8); @@ -1543,6 +1670,9 @@ function deserializeEmptyStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -1558,6 +1688,9 @@ function deserializeExpressionStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -1578,6 +1711,9 @@ function deserializeIfStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.test = deserializeExpression(pos + 8); @@ -1598,6 +1734,9 @@ function deserializeDoWhileStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.body = deserializeStatement(pos + 8); @@ -1617,6 +1756,9 @@ function deserializeWhileStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.test = deserializeExpression(pos + 8); @@ -1638,6 +1780,9 @@ function deserializeForStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.init = deserializeOptionForStatementInit(pos + 8); @@ -1755,6 +1900,9 @@ function deserializeForInStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeForStatementLeft(pos + 8); @@ -1806,6 +1954,9 @@ function deserializeForOfStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeForStatementLeft(pos + 8); @@ -1825,6 +1976,9 @@ function deserializeContinueStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.label = deserializeOptionLabelIdentifier(pos + 8); @@ -1842,6 +1996,9 @@ function deserializeBreakStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.label = deserializeOptionLabelIdentifier(pos + 8); @@ -1859,6 +2016,9 @@ function deserializeReturnStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeOptionExpression(pos + 8); @@ -1877,6 +2037,9 @@ function deserializeWithStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.object = deserializeExpression(pos + 8); @@ -1896,6 +2059,9 @@ function deserializeSwitchStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.discriminant = deserializeExpression(pos + 8); @@ -1915,6 +2081,9 @@ function deserializeSwitchCase(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.test = deserializeOptionExpression(pos + 8); @@ -1934,6 +2103,9 @@ function deserializeLabeledStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.label = deserializeLabelIdentifier(pos + 8); @@ -1952,6 +2124,9 @@ function deserializeThrowStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeExpression(pos + 8); @@ -1971,6 +2146,9 @@ function deserializeTryStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.block = deserializeBoxBlockStatement(pos + 8); @@ -1991,6 +2169,9 @@ function deserializeCatchClause(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.param = deserializeOptionCatchParameter(pos + 8); @@ -2010,6 +2191,9 @@ function deserializeDebuggerStatement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -2055,6 +2239,9 @@ function deserializeAssignmentPattern(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -2079,6 +2266,9 @@ function deserializeObjectPattern(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, properties = deserializeVecBindingProperty(pos + 8), @@ -2108,6 +2298,9 @@ function deserializeBindingProperty(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.kind = 'init'; @@ -2132,6 +2325,9 @@ function deserializeArrayPattern(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, elements = deserializeVecOptionBindingPattern(pos + 8), @@ -2159,6 +2355,9 @@ function deserializeBindingRestElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -2188,6 +2387,9 @@ function deserializeFunction(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, params = deserializeBoxFormalParameters(pos + 56); @@ -2237,6 +2439,9 @@ function deserializeFormalParameters(pos) { start: start = deserializeU32(pos), end: end = deserializeU32(pos + 4), range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; rest.argument = deserializeBindingPatternKind(pos + 8); @@ -2272,6 +2477,9 @@ function deserializeFormalParameter(pos) { start: start = deserializeU32(pos), end: end = deserializeU32(pos + 4), range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; param.decorators = deserializeVecDecorator(pos + 8); @@ -2292,6 +2500,9 @@ function deserializeFunctionBody(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, body = deserializeVecDirective(pos + 8); @@ -2319,6 +2530,9 @@ function deserializeArrowFunctionExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, body = deserializeBoxFunctionBody(pos + 32); @@ -2347,6 +2561,9 @@ function deserializeYieldExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeOptionExpression(pos + 8); @@ -2372,6 +2589,9 @@ function deserializeClass(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = deserializeVecDecorator(pos + 8); @@ -2406,6 +2626,9 @@ function deserializeClassBody(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.body = deserializeVecClassElement(pos + 8); @@ -2448,6 +2671,9 @@ function deserializeMethodDefinition(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = deserializeVecDecorator(pos + 8); @@ -2489,6 +2715,9 @@ function deserializePropertyDefinition(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = deserializeVecDecorator(pos + 8); @@ -2533,6 +2762,9 @@ function deserializePrivateIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -2547,6 +2779,9 @@ function deserializeStaticBlock(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.body = deserializeVecStatement(pos + 8); @@ -2586,6 +2821,9 @@ function deserializeAccessorProperty(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = deserializeVecDecorator(pos + 8); @@ -2611,6 +2849,9 @@ function deserializeImportExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.source = deserializeExpression(pos + 8); @@ -2633,6 +2874,9 @@ function deserializeImportDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8); @@ -2681,6 +2925,9 @@ function deserializeImportSpecifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.imported = deserializeModuleExportName(pos + 8); @@ -2699,6 +2946,9 @@ function deserializeImportDefaultSpecifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.local = deserializeBindingIdentifier(pos + 8); @@ -2716,6 +2966,9 @@ function deserializeImportNamespaceSpecifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.local = deserializeBindingIdentifier(pos + 8); @@ -2738,6 +2991,9 @@ function deserializeImportAttribute(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.key = deserializeImportAttributeKey(pos + 8); @@ -2771,6 +3027,9 @@ function deserializeExportNamedDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, withClause = deserializeOptionBoxWithClause(pos + 96); @@ -2793,6 +3052,9 @@ function deserializeExportDefaultDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.declaration = deserializeExportDefaultDeclarationKind(pos + 8); @@ -2814,6 +3076,9 @@ function deserializeExportAllDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, withClause = deserializeOptionBoxWithClause(pos + 112); @@ -2836,6 +3101,9 @@ function deserializeExportSpecifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.local = deserializeModuleExportName(pos + 8); @@ -2967,6 +3235,9 @@ function deserializeV8IntrinsicExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.name = deserializeIdentifierName(pos + 8); @@ -2987,6 +3258,9 @@ function deserializeBooleanLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.raw = start === 0 && end === 0 ? null : value + ''; @@ -3005,6 +3279,9 @@ function deserializeNullLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.value = null; @@ -3022,6 +3299,9 @@ function deserializeNumericLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -3037,6 +3317,9 @@ function deserializeStringLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, value = deserializeStr(pos + 8); @@ -3059,6 +3342,9 @@ function deserializeBigIntLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, bigint = deserializeStr(pos + 8); @@ -3080,6 +3366,9 @@ function deserializeRegExpLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, regex = deserializeRegExp(pos + 8), @@ -3126,6 +3415,9 @@ function deserializeJSXElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, closingElement = deserializeOptionBoxJSXClosingElement(pos + 40), @@ -3151,6 +3443,9 @@ function deserializeJSXOpeningElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.name = deserializeJSXElementName(pos + 8); @@ -3171,6 +3466,9 @@ function deserializeJSXClosingElement(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.name = deserializeJSXElementName(pos + 8); @@ -3190,6 +3488,9 @@ function deserializeJSXFragment(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.openingFragment = deserializeJSXOpeningFragment(pos + 8); @@ -3208,6 +3509,9 @@ function deserializeJSXOpeningFragment(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; parent = previousParent; @@ -3221,6 +3525,9 @@ function deserializeJSXClosingFragment(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -3237,6 +3544,9 @@ function deserializeJSXElementName(pos) { start: ident.start, end: ident.end, range: ident.range, + get loc() { + return getLoc(this); + }, parent, }; case 2: @@ -3251,6 +3561,9 @@ function deserializeJSXElementName(pos) { start: thisExpr.start, end: thisExpr.end, range: thisExpr.range, + get loc() { + return getLoc(this); + }, parent, }; default: @@ -3269,6 +3582,9 @@ function deserializeJSXNamespacedName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.namespace = deserializeJSXIdentifier(pos + 8); @@ -3288,6 +3604,9 @@ function deserializeJSXMemberExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.object = deserializeJSXMemberExpressionObject(pos + 8); @@ -3306,6 +3625,9 @@ function deserializeJSXMemberExpressionObject(pos) { start: ident.start, end: ident.end, range: ident.range, + get loc() { + return getLoc(this); + }, parent, }; case 1: @@ -3318,6 +3640,9 @@ function deserializeJSXMemberExpressionObject(pos) { start: thisExpr.start, end: thisExpr.end, range: thisExpr.range, + get loc() { + return getLoc(this); + }, parent, }; default: @@ -3335,6 +3660,9 @@ function deserializeJSXExpressionContainer(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeJSXExpression(pos + 8); @@ -3444,6 +3772,9 @@ function deserializeJSXEmptyExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -3470,6 +3801,9 @@ function deserializeJSXAttribute(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.name = deserializeJSXAttributeName(pos + 8); @@ -3488,6 +3822,9 @@ function deserializeJSXSpreadAttribute(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeExpression(pos + 8); @@ -3529,6 +3866,9 @@ function deserializeJSXIdentifier(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -3560,6 +3900,9 @@ function deserializeJSXSpreadChild(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -3576,6 +3919,9 @@ function deserializeJSXText(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -3593,6 +3939,9 @@ function deserializeTSThisParameter(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -3616,6 +3965,9 @@ function deserializeTSEnumDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeBindingIdentifier(pos + 8); @@ -3634,6 +3986,9 @@ function deserializeTSEnumBody(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.members = deserializeVecTSEnumMember(pos + 8); @@ -3653,6 +4008,9 @@ function deserializeTSEnumMember(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeTSEnumMemberName(pos + 8); @@ -3687,6 +4045,9 @@ function deserializeTSTypeAnnotation(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -3704,6 +4065,9 @@ function deserializeTSLiteralType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.literal = deserializeTSLiteral(pos + 8); @@ -3824,6 +4188,9 @@ function deserializeTSConditionalType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.checkType = deserializeTSType(pos + 8); @@ -3844,6 +4211,9 @@ function deserializeTSUnionType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.types = deserializeVecTSType(pos + 8); @@ -3861,6 +4231,9 @@ function deserializeTSIntersectionType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.types = deserializeVecTSType(pos + 8); @@ -3885,6 +4258,9 @@ function deserializeTSTypeOperator(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -3915,6 +4291,9 @@ function deserializeTSArrayType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.elementType = deserializeTSType(pos + 8); @@ -3933,6 +4312,9 @@ function deserializeTSIndexedAccessType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.objectType = deserializeTSType(pos + 8); @@ -3951,6 +4333,9 @@ function deserializeTSTupleType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.elementTypes = deserializeVecTSTupleElement(pos + 8); @@ -3970,6 +4355,9 @@ function deserializeTSNamedTupleMember(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.label = deserializeIdentifierName(pos + 8); @@ -3988,6 +4376,9 @@ function deserializeTSOptionalType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -4005,6 +4396,9 @@ function deserializeTSRestType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -4104,6 +4498,9 @@ function deserializeTSAnyKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4115,6 +4512,9 @@ function deserializeTSStringKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4126,6 +4526,9 @@ function deserializeTSBooleanKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4137,6 +4540,9 @@ function deserializeTSNumberKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4148,6 +4554,9 @@ function deserializeTSNeverKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4159,6 +4568,9 @@ function deserializeTSIntrinsicKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4170,6 +4582,9 @@ function deserializeTSUnknownKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4181,6 +4596,9 @@ function deserializeTSNullKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4192,6 +4610,9 @@ function deserializeTSUndefinedKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4203,6 +4624,9 @@ function deserializeTSVoidKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4214,6 +4638,9 @@ function deserializeTSSymbolKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4225,6 +4652,9 @@ function deserializeTSThisType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4236,6 +4666,9 @@ function deserializeTSObjectKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4247,6 +4680,9 @@ function deserializeTSBigIntKeyword(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -4262,6 +4698,9 @@ function deserializeTSTypeReference(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeName = deserializeTSTypeName(pos + 8); @@ -4294,6 +4733,9 @@ function deserializeTSQualifiedName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeTSTypeName(pos + 8); @@ -4312,6 +4754,9 @@ function deserializeTSTypeParameterInstantiation(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.params = deserializeVecTSType(pos + 8); @@ -4334,6 +4779,9 @@ function deserializeTSTypeParameter(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.name = deserializeBindingIdentifier(pos + 8); @@ -4353,6 +4801,9 @@ function deserializeTSTypeParameterDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.params = deserializeVecTSTypeParameter(pos + 8); @@ -4373,6 +4824,9 @@ function deserializeTSTypeAliasDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeBindingIdentifier(pos + 8); @@ -4406,6 +4860,9 @@ function deserializeTSClassImplements(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, expression = deserializeTSTypeName(pos + 8); @@ -4423,6 +4880,9 @@ function deserializeTSClassImplements(pos) { start: start = expression.start, end: end = expression.end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; right.parent = previous; @@ -4441,6 +4901,9 @@ function deserializeTSClassImplements(pos) { start: start = object.start, end: end = object.end, range: [start, end], + get loc() { + return getLoc(this); + }, parent: previous, }; right.parent = previous; @@ -4467,6 +4930,9 @@ function deserializeTSInterfaceDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeBindingIdentifier(pos + 8); @@ -4487,6 +4953,9 @@ function deserializeTSInterfaceBody(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.body = deserializeVecTSSignature(pos + 8); @@ -4510,6 +4979,9 @@ function deserializeTSPropertySignature(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.key = deserializePropertyKey(pos + 8); @@ -4551,6 +5023,9 @@ function deserializeTSIndexSignature(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.parameters = deserializeVecTSIndexSignatureName(pos + 8); @@ -4572,6 +5047,9 @@ function deserializeTSCallSignatureDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, params = deserializeBoxFormalParameters(pos + 24), @@ -4616,6 +5094,9 @@ function deserializeTSMethodSignature(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, params = deserializeBoxFormalParameters(pos + 40), @@ -4644,6 +5125,9 @@ function deserializeTSConstructSignatureDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); @@ -4666,6 +5150,9 @@ function deserializeTSIndexSignatureName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.decorators = []; @@ -4686,6 +5173,9 @@ function deserializeTSInterfaceHeritage(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -4706,6 +5196,9 @@ function deserializeTSTypePredicate(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.parameterName = deserializeTSTypePredicateName(pos + 8); @@ -4744,6 +5237,9 @@ function deserializeTSModuleDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeTSModuleDeclarationName(pos + 8); @@ -4758,6 +5254,9 @@ function deserializeTSModuleDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; let id = deserializeTSModuleDeclarationName(pos + 8); @@ -4779,6 +5278,9 @@ function deserializeTSModuleDeclaration(pos) { start: start = id.start, end: end = innerId.end, range: [start, end], + get loc() { + return getLoc(this); + }, parent: node, }; } else { @@ -4800,6 +5302,9 @@ function deserializeTSModuleDeclaration(pos) { start, end: end = right.end, range: [start, end], + get loc() { + return getLoc(this); + }, parent: innerId, }; } @@ -4859,6 +5364,9 @@ function deserializeTSModuleBlock(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, body = deserializeVecDirective(pos + 8); @@ -4878,6 +5386,9 @@ function deserializeTSTypeLiteral(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.members = deserializeVecTSSignature(pos + 8); @@ -4895,6 +5406,9 @@ function deserializeTSInferType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeParameter = deserializeBoxTSTypeParameter(pos + 8); @@ -4913,6 +5427,9 @@ function deserializeTSTypeQuery(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.exprName = deserializeTSTypeQueryExprName(pos + 8); @@ -4949,6 +5466,9 @@ function deserializeTSImportType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.argument = deserializeTSType(pos + 8); @@ -4981,6 +5501,9 @@ function deserializeTSImportTypeQualifiedName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.left = deserializeTSImportTypeQualifier(pos + 8); @@ -5001,6 +5524,9 @@ function deserializeTSFunctionType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, params = deserializeBoxFormalParameters(pos + 24), @@ -5026,6 +5552,9 @@ function deserializeTSConstructorType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeParameters = deserializeOptionBoxTSTypeParameterDeclaration(pos + 8); @@ -5050,6 +5579,9 @@ function deserializeTSMappedType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, typeParameter = deserializeBoxTSTypeParameter(pos + 8), @@ -5092,6 +5624,9 @@ function deserializeTSTemplateLiteralType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.quasis = deserializeVecTemplateElement(pos + 8); @@ -5111,6 +5646,9 @@ function deserializeTSAsExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5130,6 +5668,9 @@ function deserializeTSSatisfiesExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5149,6 +5690,9 @@ function deserializeTSTypeAssertion(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -5169,6 +5713,9 @@ function deserializeTSImportEqualsDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeBindingIdentifier(pos + 8); @@ -5202,6 +5749,9 @@ function deserializeTSExternalModuleReference(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeStringLiteral(pos + 8); @@ -5219,6 +5769,9 @@ function deserializeTSNonNullExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5236,6 +5789,9 @@ function deserializeDecorator(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5253,6 +5809,9 @@ function deserializeTSExportAssignment(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5270,6 +5829,9 @@ function deserializeTSNamespaceExportDeclaration(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.id = deserializeIdentifierName(pos + 8); @@ -5288,6 +5850,9 @@ function deserializeTSInstantiationExpression(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.expression = deserializeExpression(pos + 8); @@ -5318,6 +5883,9 @@ function deserializeJSDocNullableType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -5336,6 +5904,9 @@ function deserializeJSDocNonNullableType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; node.typeAnnotation = deserializeTSType(pos + 8); @@ -5350,6 +5921,9 @@ function deserializeJSDocUnknownType(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }; } @@ -5376,6 +5950,9 @@ function deserializeComment(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, parent, }, endCut = type === 'Line' ? 0 : 2; @@ -5391,6 +5968,9 @@ function deserializeNameSpan(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } @@ -5412,6 +5992,9 @@ function deserializeImportImportName(pos) { start: nameSpan.start, end: nameSpan.end, range: nameSpan.range, + get loc() { + return getLoc(this); + }, }; case 1: return { @@ -5420,6 +6003,9 @@ function deserializeImportImportName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; case 2: var { start, end } = deserializeSpan(pos + 8); @@ -5429,6 +6015,9 @@ function deserializeImportImportName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for ImportImportName`); @@ -5446,6 +6035,9 @@ function deserializeExportEntry(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } @@ -5459,6 +6051,9 @@ function deserializeExportImportName(pos) { start: nameSpan.start, end: nameSpan.end, range: nameSpan.range, + get loc() { + return getLoc(this); + }, }; case 1: return { @@ -5467,6 +6062,9 @@ function deserializeExportImportName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; case 2: return { @@ -5475,6 +6073,9 @@ function deserializeExportImportName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; case 3: return { @@ -5483,6 +6084,9 @@ function deserializeExportImportName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for ExportImportName`); @@ -5499,6 +6103,9 @@ function deserializeExportExportName(pos) { start: nameSpan.start, end: nameSpan.end, range: nameSpan.range, + get loc() { + return getLoc(this); + }, }; case 1: var { start, end } = deserializeSpan(pos + 8); @@ -5508,6 +6115,9 @@ function deserializeExportExportName(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; case 2: return { @@ -5516,6 +6126,9 @@ function deserializeExportExportName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for ExportExportName`); @@ -5532,6 +6145,9 @@ function deserializeExportLocalName(pos) { start: nameSpan.start, end: nameSpan.end, range: nameSpan.range, + get loc() { + return getLoc(this); + }, }; case 1: var nameSpan = deserializeNameSpan(pos + 8); @@ -5541,6 +6157,9 @@ function deserializeExportLocalName(pos) { start: nameSpan.start, end: nameSpan.end, range: nameSpan.range, + get loc() { + return getLoc(this); + }, }; case 2: return { @@ -5549,6 +6168,9 @@ function deserializeExportLocalName(pos) { start: null, end: null, range: [null, null], + get loc() { + return getLoc(this); + }, }; default: throw Error(`Unexpected discriminant ${uint8[pos]} for ExportLocalName`); @@ -5562,6 +6184,9 @@ function deserializeDynamicImport(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } @@ -5757,6 +6382,9 @@ function deserializeErrorLabel(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } @@ -5778,6 +6406,9 @@ function deserializeStaticImport(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } @@ -5788,6 +6419,9 @@ function deserializeStaticExport(pos) { start, end, range: [start, end], + get loc() { + return getLoc(this); + }, }; } diff --git a/napi/parser/generated/deserialize/ts_range_parent.js b/napi/parser/generated/deserialize/ts_range_parent.js index 18ed403a028dc..e95d1ffe06ee3 100644 --- a/napi/parser/generated/deserialize/ts_range_parent.js +++ b/napi/parser/generated/deserialize/ts_range_parent.js @@ -8,14 +8,14 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }), let parent = null; export function deserialize(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); } -export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) { - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); +export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) { + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); } -function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) { +function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) { uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; diff --git a/tasks/ast_tools/src/generators/raw_transfer.rs b/tasks/ast_tools/src/generators/raw_transfer.rs index a6cbbe9b816b6..41e8fbb4bba3d 100644 --- a/tasks/ast_tools/src/generators/raw_transfer.rs +++ b/tasks/ast_tools/src/generators/raw_transfer.rs @@ -10,8 +10,12 @@ use rustc_hash::FxHashSet; use oxc_allocator::{Allocator, CloneIn}; use oxc_ast::{ - AstBuilder, - ast::{BindingPatternKind, Expression, Program, Statement, UnaryOperator}, + AstBuilder, NONE, + ast::{ + Argument, BindingPatternKind, Expression, FormalParameterKind, FunctionType, + LogicalOperator, ObjectExpression, ObjectPropertyKind, Program, PropertyKind, Statement, + UnaryOperator, + }, }; use oxc_ast_visit::{VisitMut, walk_mut}; use oxc_codegen::Codegen as Printer; @@ -20,7 +24,7 @@ use oxc_minifier::{ TreeShakeOptions, }; use oxc_parser::Parser; -use oxc_span::SourceType; +use oxc_span::{SPAN, SourceType}; use crate::{ ALLOCATOR_CRATE_PATH, Generator, NAPI_PARSER_PACKAGE_PATH, OXLINT_APP_PATH, @@ -143,6 +147,7 @@ fn generate_deserializers( const IS_TS = false; const RANGE = false; + const LOC = false; const PARENT = false; const PRESERVE_PARENS = false; @@ -151,16 +156,17 @@ fn generate_deserializers( {{ fromCodePoint }} = String; let parent = null; + let getLoc; export function deserialize(buffer, sourceText, sourceByteLen) {{ - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeRawTransferData); + return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData); }} - export function deserializeProgramOnly(buffer, sourceText, sourceByteLen) {{ - return deserializeWith(buffer, sourceText, sourceByteLen, deserializeProgram); + export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) {{ + return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram); }} - function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, deserialize) {{ + function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {{ uint8 = buffer; uint32 = buffer.uint32; float64 = buffer.float64; @@ -169,6 +175,8 @@ fn generate_deserializers( sourceByteLen = sourceByteLenInput; sourceIsAscii = sourceText.length === sourceByteLen; + if (LOC) getLoc = getLocInput; + const data = deserialize(uint32[{data_pointer_pos_32}]); uint8 = uint32 = float64 = sourceText = undefined; @@ -218,12 +226,19 @@ fn generate_deserializers( // and running through minifier to shake out irrelevant code let mut print_allocator = Allocator::new(); let mut deserializers = vec![]; - let mut create_deserializer = |is_ts, range, parent, preserve_parens| { + let mut create_deserializer = |is_ts, range, loc, parent, preserve_parens| { let mut program = program.clone_in(&print_allocator); replace_const(&mut program, "IS_TS", is_ts); replace_const(&mut program, "RANGE", range); + replace_const(&mut program, "LOC", loc); replace_const(&mut program, "PARENT", parent); replace_const(&mut program, "PRESERVE_PARENS", preserve_parens); + + if loc { + assert!(range, "`loc` requires `range`"); + LocFieldAdder::new(&allocator).visit_program(&mut program); + } + let code = print_minified(&mut program, &print_allocator); print_allocator.reset(); @@ -231,6 +246,9 @@ fn generate_deserializers( if range { name.push_str("_range"); } + if loc { + name.push_str("_loc"); + } if parent { name.push_str("_parent"); } @@ -244,13 +262,13 @@ fn generate_deserializers( for is_ts in [false, true] { for range in [false, true] { for parent in [false, true] { - create_deserializer(is_ts, range, parent, true); + create_deserializer(is_ts, range, false, parent, true); } } } // `PRESERVE_PARENS = false` is only required for linter - create_deserializer(true, true, true, false); + create_deserializer(true, true, true, true, false); deserializers } @@ -1352,3 +1370,80 @@ impl<'a> VisitMut<'a> for BooleanUnminifier<'a> { walk_mut::walk_expression(self, expr); } } + +/// Visitor to add `loc` field after `range` in all deserialize functions. +/// +/// Works on AST pre-minification. +struct LocFieldAdder<'a> { + ast: AstBuilder<'a>, +} + +impl<'a> LocFieldAdder<'a> { + fn new(allocator: &'a Allocator) -> Self { + Self { ast: AstBuilder::new(allocator) } + } +} + +impl<'a> VisitMut<'a> for LocFieldAdder<'a> { + fn visit_object_expression(&mut self, obj_expr: &mut ObjectExpression<'a>) { + // Locate `range` field + let index = obj_expr.properties.iter().position(|prop| { + if let ObjectPropertyKind::SpreadProperty(spread) = prop + && let Expression::ParenthesizedExpression(paren_expr) = &spread.argument + && let Expression::LogicalExpression(logical_expr) = &paren_expr.expression + && logical_expr.operator == LogicalOperator::And + && let Expression::Identifier(ident) = &logical_expr.left + && ident.name == "RANGE" + { + true + } else { + false + } + }); + let Some(index) = index else { return }; + + // Insert `get loc() { return getLoc(this) }` after `range` field + let ast = self.ast; + let prop = ast.object_property_kind_object_property( + SPAN, + PropertyKind::Get, + ast.property_key_static_identifier(SPAN, "loc"), + ast.expression_function( + SPAN, + FunctionType::FunctionExpression, + None, + false, + false, + false, + NONE, + NONE, + ast.formal_parameters( + SPAN, + FormalParameterKind::UniqueFormalParameters, + ast.vec(), + NONE, + ), + NONE, + Some(ast.function_body( + SPAN, + ast.vec(), + ast.vec1(ast.statement_return( + SPAN, + Some(ast.expression_call( + SPAN, + ast.expression_identifier(SPAN, "getLoc"), + NONE, + ast.vec1(Argument::from(ast.expression_this(SPAN))), + false, + )), + )), + )), + ), + false, + false, + false, + ); + + obj_expr.properties.insert(index + 1, prop); + } +} diff --git a/tasks/ast_tools/src/generators/typescript.rs b/tasks/ast_tools/src/generators/typescript.rs index 626daffc6cc45..78bb47e0997a0 100644 --- a/tasks/ast_tools/src/generators/typescript.rs +++ b/tasks/ast_tools/src/generators/typescript.rs @@ -3,6 +3,7 @@ use std::borrow::Cow; use itertools::Itertools; +use lazy_regex::{Captures, Lazy, Regex, lazy_regex, regex::Replacer}; use crate::{ Codegen, Generator, OXLINT_APP_PATH, TYPESCRIPT_DEFINITIONS_PATH, @@ -26,10 +27,7 @@ impl Generator for TypescriptGenerator { /// Generate Typescript type definitions for all AST types. fn generate_many(&self, schema: &Schema, codegen: &Codegen) -> Vec { let code = generate_ts_type_defs(schema, codegen); - - // In Oxlint AST, `range` field is not optional - #[expect(clippy::disallowed_methods)] - let oxlint_code = code.replace("range?: [number, number];", "range: [number, number];"); + let oxlint_code = amend_oxlint_types(&code); vec![ Output::Javascript { path: TYPESCRIPT_DEFINITIONS_PATH.to_string(), code }, @@ -453,3 +451,29 @@ fn get_single_field<'s>(struct_def: &'s StructDef, schema: &Schema) -> Option<&' None } } + +/// Amend version of types for Oxlint. +/// +/// Remove `export interface Span`, and instead import local version of same interface, +/// which includes non-optional `range` and `loc` fields. +fn amend_oxlint_types(code: &str) -> String { + static SPAN_REGEX: Lazy = lazy_regex!(r"export interface Span \{.+?\}"); + + struct SpanReplacer; + impl Replacer for SpanReplacer { + fn replace_append(&mut self, _caps: &Captures, _dst: &mut String) { + // Remove it + } + } + + let mut code = SPAN_REGEX.replace(code, SpanReplacer).into_owned(); + + #[rustfmt::skip] + code.insert_str(0, " + import { Span } from '../plugins/types.ts'; + export { Span }; + + "); + + code +}