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
38 changes: 10 additions & 28 deletions apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ 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 @@ -34,22 +27,21 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
getLoc = getLocInput;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
astId++;
}

function deserializeProgram(pos) {
// Buffers will be cleaned up after the main program is deserialized.
// We hold references here in case the comments need to be later accessed.
let refUint32 = uint32,
refUint8 = uint8,
refSourceText = sourceText,
localAstId = astId,
let localAstId = astId,
end = deserializeU32(pos + 4),
program = parent = {
__proto__: NodeProto,
Expand All @@ -58,21 +50,11 @@ function deserializeProgram(pos) {
sourceType: deserializeModuleKind(pos + 125),
hashbang: null,
get comments() {
// Check AST in buffer is still the same AST (buffers are reused)
if (localAstId !== astId) throw Error('Comments are only accessible while linting the file');
// Restore buffers
uint32 = refUint32;
uint8 = refUint8;
sourceText = refSourceText;
// Deserialize the comments
// Deserialize the comments.
// Replace this getter with the comments array, so we don't deserialize twice.
let comments = deserializeVecComment(pos + 24);
// Drop the references
refUint32 =
refUint8 =
refSourceText =
uint32 =
uint8 =
sourceText =
void 0;
Object.defineProperty(this, 'comments', { value: comments });
return comments;
},
Expand Down
4 changes: 2 additions & 2 deletions 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, reset as resetAst } from '../../dist/generated/deserialize.js';
import { deserializeProgramOnly, resetBuffer } from '../../dist/generated/deserialize.js';

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

Expand Down
17 changes: 3 additions & 14 deletions crates/oxc_ast/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,7 @@ impl Program<'_> {
/// `Program` span start is 0 (not 5).
#[ast_meta]
#[estree(raw_deser = "
/* IF COMMENTS */
// Buffers will be cleaned up after the main program is deserialized.
// We hold references here in case the comments need to be later accessed.
let refUint32 = uint32;
let refUint8 = uint8;
let refSourceText = sourceText;
const localAstId = astId;
/* END_IF */

const start = IS_TS ? 0 : DESER[u32](POS_OFFSET.span.start),
end = DESER[u32](POS_OFFSET.span.end);
Expand All @@ -140,15 +133,11 @@ impl Program<'_> {
hashbang: null,
/* IF COMMENTS */
get comments() {
// Check AST in buffer is still the same AST (buffers are reused)
if (localAstId !== astId) throw new Error('Comments are only accessible while linting the file');
// Restore buffers
uint32 = refUint32;
uint8 = refUint8;
sourceText = refSourceText;
// Deserialize the comments
// Deserialize the comments.
// Replace this getter with the comments array, so we don't deserialize twice.
const comments = DESER[Vec<Comment>](POS_OFFSET.comments);
// Drop the references
refUint32 = refUint8 = refSourceText = uint32 = uint8 = sourceText = undefined;
Object.defineProperty(this, 'comments', { value: comments });
return comments;
},
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/js_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/js_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/js_range_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/ts_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/ts_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
11 changes: 8 additions & 3 deletions napi/parser/generated/deserialize/ts_range_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
{ fromCodePoint } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
return deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
}

function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInput, deserialize) {
Expand All @@ -18,13 +20,16 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
sourceText = sourceTextInput;
sourceByteLen = sourceByteLenInput;
sourceIsAscii = sourceText.length === sourceByteLen;
let data = deserialize(uint32[536870902]);
return deserialize(uint32[536870902]);
}

export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 =
uint32 =
float64 =
sourceText =
void 0;
return data;
}

function deserializeProgram(pos) {
Expand Down
Loading
Loading