Skip to content
24 changes: 22 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,33 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu

function deserializeProgram(pos) {
let end = deserializeU32(pos + 4),
ref_uint32 = uint32,
ref_uint8 = uint8,
ref_sourceText = 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(
'The AST being accessed has already been cleaned up. Please ensure that the plugin works synchronously.',
);}
// restore buffers
uint32 = ref_uint32;
uint8 = ref_uint8;
sourceText = ref_sourceText;
// deserialize the comments
let c = deserializeVecComment(pos + 24);
// drop the references
ref_uint32 = void 0;
ref_uint8 = void 0;
ref_sourceText = void 0;
Object.defineProperty(this, 'comments', { value: c });
return c;
},
start: 0,
end,
range: [0, end],
Expand Down
28 changes: 27 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,38 @@ impl Program<'_> {
const start = IS_TS ? 0 : DESER[u32](POS_OFFSET.span.start),
end = DESER[u32](POS_OFFSET.span.end);


/* IF LINTER */
// 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 ref_uint32 = uint32;
let ref_uint8 = uint8;
let ref_sourceText = sourceText;
Comment thread
lilnasy marked this conversation as resolved.
Outdated
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 LINTER */
get comments() {
if (localAstId !== astId) throw new Error(`The AST being accessed has already been cleaned up. Please ensure that the plugin works synchronously.`);
// restore buffers
Comment thread
lilnasy marked this conversation as resolved.
Outdated
uint32 = ref_uint32;
uint8 = ref_uint8;
sourceText = ref_sourceText;
// deserialize the comments
const c = DESER[Vec<Comment>](POS_OFFSET.comments);
Comment thread
lilnasy marked this conversation as resolved.
Outdated
// drop the references
ref_uint32 = undefined;
ref_uint8 = undefined;
ref_sourceText = undefined;
Comment thread
lilnasy marked this conversation as resolved.
Outdated
Object.defineProperty(this, 'comments', { value: c });
return c;
},
/* END_IF */
start,
end,
...(RANGE && { range: [start, end] }),
Expand Down
9 changes: 4 additions & 5 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 Expand Up @@ -221,7 +222,7 @@ fn generate_deserializers(
}

impl VariantGenerator<7> for VariantGen {
const FLAG_NAMES: [&str; 7] =
const FLAG_NAMES: [&str;7] =
["IS_TS", "RANGE", "LOC", "PARENT", "PRESERVE_PARENS", "COMMENTS", "LINTER"];

fn variants(&mut self) -> Vec<[bool; 7]> {
Expand All @@ -240,8 +241,7 @@ fn generate_deserializers(

variants.push([
is_ts, range, /* loc */ false, parent,
/* preserve_parens */ true, /* comments */ false,
/* linter */ false,
/* preserve_parens */ true, /* comments */ false, /* linter */ false,
]);
}
}
Expand All @@ -251,8 +251,7 @@ fn generate_deserializers(
self.variant_paths.push(format!("{OXLINT_APP_PATH}/src-js/generated/deserialize.js"));
variants.push([
/* is_ts */ true, /* range */ true, /* loc */ true,
/* parent */ true, /* preserve_parens */ false, /* comments */ true,
/* linter */ true,
/* parent */ true, /* preserve_parens */ false, /* comments */ true, /* linter */ true,
]);

variants
Expand Down
Loading