Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc
return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram);
}

export function reset() {
// Increment `astId` counter.
// This prevents `program.comments` being accessed after the AST is done with.
// (see `deserializeProgram`)
astId++;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
uint8 = buffer;
uint32 = buffer.uint32;
Expand All @@ -42,7 +49,7 @@ function deserializeProgram(pos) {
let refUint32 = uint32,
refUint8 = uint8,
refSourceText = sourceText,
localAstId = ++astId,
localAstId = astId,
end = deserializeU32(pos + 4),
program = parent = {
__proto__: NodeProto,
Expand Down
3 changes: 2 additions & 1 deletion apps/oxlint/src-js/plugins/source_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DATA_POINTER_POS_32, SOURCE_LEN_OFFSET } from '../generated/constants.j
// We use the deserializer which removes `ParenthesizedExpression`s from AST,
// and with `range`, `loc`, and `parent` properties on AST nodes, to match ESLint
// @ts-expect-error we need to generate `.d.ts` file for this module
import { deserializeProgramOnly } from '../../dist/generated/deserialize.js';
import { deserializeProgramOnly, reset as resetAst } from '../../dist/generated/deserialize.js';

import visitorKeys from '../generated/keys.js';
import {
Expand Down Expand Up @@ -78,6 +78,7 @@ export function resetSourceAndAst(): void {
buffer = null;
sourceText = null;
ast = null;
resetAst();
resetLines();
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Program<'_> {
let refUint32 = uint32;
let refUint8 = uint8;
let refSourceText = sourceText;
const localAstId = ++astId;
const localAstId = astId;
/* END_IF */

const start = IS_TS ? 0 : DESER[u32](POS_OFFSET.span.start),
Expand Down
7 changes: 7 additions & 0 deletions tasks/ast_tools/src/generators/raw_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ fn generate_deserializers(
export function deserializeProgramOnly(buffer, sourceText, sourceByteLen, getLoc) {{
return deserializeWith(buffer, sourceText, sourceByteLen, getLoc, deserializeProgram);
}}

export function reset() {{
// Increment `astId` counter.
// This prevents `program.comments` being accessed after the AST is done with.
// (see `deserializeProgram`)
astId++;
}}
/* END_IF */

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {{
Expand Down
Loading