Skip to content

Commit 1831c50

Browse files
committed
spread immediately ran the deserializer, make it actually lazy this time
1 parent 09bc1a8 commit 1831c50

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

apps/oxlint/src-js/generated/deserialize.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, getLocInpu
3131
sourceByteLen = sourceByteLenInput;
3232
sourceIsAscii = sourceText.length === sourceByteLen;
3333
getLoc = getLocInput;
34-
let data = deserialize(uint32[536870902]);
35-
uint8 =
36-
uint32 =
37-
float64 =
38-
sourceText =
39-
void 0;
40-
return data;
34+
return deserialize(uint32[536870902]);
4135
}
4236

4337
function deserializeProgram(pos) {
@@ -48,18 +42,24 @@ function deserializeProgram(pos) {
4842
body: null,
4943
sourceType: deserializeModuleKind(pos + 125),
5044
hashbang: null,
51-
...{
52-
get comments() {
53-
let c = deserializeVecComment(pos + 24);
54-
Object.defineProperty(this, 'comments', { value: c });
55-
return c;
56-
},
57-
},
5845
start: 0,
5946
end,
6047
range: [0, end],
6148
parent: null,
6249
};
50+
Object.defineProperty(program, 'comments', {
51+
configurable: true,
52+
get() {
53+
let c = deserializeVecComment(pos + 24);
54+
uint8 =
55+
uint32 =
56+
float64 =
57+
sourceText =
58+
void 0;
59+
Object.defineProperty(this, 'comments', { value: c });
60+
return c;
61+
},
62+
});
6363
program.hashbang = deserializeOptionHashbang(pos + 48);
6464
let body = program.body = deserializeVecDirective(pos + 72);
6565
body.push(...deserializeVecStatement(pos + 96));

crates/oxc_ast/src/serialize/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,24 @@ impl Program<'_> {
129129
body: null,
130130
sourceType: DESER[ModuleKind](POS_OFFSET.source_type.module_kind),
131131
hashbang: null,
132-
...(COMMENTS && {
133-
get comments() {
134-
const c = DESER[Vec<Comment>](POS_OFFSET.comments);
135-
Object.defineProperty(this, 'comments', { value: c });
136-
return c;
137-
}
138-
}),
139132
start,
140133
end,
141134
...(RANGE && { range: [start, end] }),
142135
...(PARENT && { parent: null }),
143136
};
144137
138+
if (COMMENTS) {
139+
Object.defineProperty(program, 'comments', {
140+
configurable: true,
141+
get() {
142+
const c = DESER[Vec<Comment>](POS_OFFSET.comments);
143+
uint8 = uint32 = float64 = sourceText = undefined;
144+
Object.defineProperty(this, 'comments', { value: c });
145+
return c;
146+
}
147+
})
148+
}
149+
145150
program.hashbang = DESER[Option<Hashbang>](POS_OFFSET.hashbang);
146151
147152
const body = program.body = DESER[Vec<Directive>](POS_OFFSET.directives);

tasks/ast_tools/src/generators/raw_transfer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ fn generate_deserializers(
173173
174174
const data = deserialize(uint32[{data_pointer_pos_32}]);
175175
176+
if (!COMMENTS)
176177
uint8 = uint32 = float64 = sourceText = undefined;
177178
178179
return data;

0 commit comments

Comments
 (0)