Skip to content
26 changes: 24 additions & 2 deletions apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen, parent = null, getLoc;
let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen, astId = 0, parent = null, getLoc;

const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
decodeStr = textDecoder.decode.bind(textDecoder),
Expand Down Expand Up @@ -38,13 +38,35 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu

function deserializeProgram(pos) {
let end = deserializeU32(pos + 4),
refUint32 = uint32,
refUint8 = uint8,
refSourceText = sourceText,
localAstId = ++astId,
program = parent = {
__proto__: NodeProto,
type: 'Program',
body: null,
sourceType: deserializeModuleKind(pos + 125),
hashbang: null,
comments: deserializeVecComment(pos + 24),
get comments() {
if (localAstId !== astId) throw Error('Comments are only accessible while linting the file');
// Restore buffers
uint32 = refUint32;
uint8 = refUint8;
sourceText = refSourceText;
// Deserialize the comments
let comments = deserializeVecComment(pos + 24);
// Drop the references
refUint32 =
refUint8 =
refSourceText =
uint32 =
uint8 =
sourceText =
void 0;
Object.defineProperty(this, 'comments', { value: comments });
return comments;
},
start: 0,
end,
range: [0, end],
Expand Down
26 changes: 25 additions & 1 deletion crates/oxc_ast/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,36 @@ impl Program<'_> {
const start = IS_TS ? 0 : DESER[u32](POS_OFFSET.span.start),
end = DESER[u32](POS_OFFSET.span.end);


/* 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 program = parent = {
type: 'Program',
body: null,
sourceType: DESER[ModuleKind](POS_OFFSET.source_type.module_kind),
hashbang: null,
...(COMMENTS && { comments: DESER[Vec<Comment>](POS_OFFSET.comments) }),
/* IF COMMENTS */
get comments() {
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
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;
},
/* END_IF */
start,
end,
...(RANGE && { range: [start, end] }),
Expand Down
1 change: 1 addition & 0 deletions tasks/ast_tools/src/generators/raw_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn generate_deserializers(
let mut code = format!("
let uint8, uint32, float64, sourceText, sourceIsAscii, sourceByteLen;

let astId = 0;
let parent = null;
let getLoc;

Expand Down
Loading