Skip to content

Commit 8f92cc2

Browse files
committed
Null check tweaks.
1 parent 36e6fc0 commit 8f92cc2

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

esm.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ if (cachePath !== "") {
164164
let cache = dir.get(cachePath)
165165

166166
if (cache === void 0) {
167+
let scriptData = cachedData
168+
169+
if (scriptData === void 0) {
170+
scriptData = null
171+
}
172+
167173
cache = {
168174
buffer: cachedData,
169175
compile: new Map([
@@ -174,7 +180,7 @@ if (cachePath !== "") {
174180
filename: null,
175181
firstAwaitOutsideFunction: null,
176182
mtime: -1,
177-
scriptData: cachedData || null,
183+
scriptData,
178184
sourceType: 1,
179185
transforms: 0,
180186
yieldIndex: -1

src/acorn/parser/numeric-separator.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function init() {
2424

2525
function readInt(radix, length) {
2626
const start = this.pos
27-
const hasLength = length != null
27+
const hasLength = typeof length === "number"
2828
const end = hasLength ? length : Infinity
2929

3030
let i = -1
@@ -57,9 +57,11 @@ function init() {
5757
total = (total * radix) + value
5858
}
5959

60-
if (this.pos === start ||
60+
const { pos } = this
61+
62+
if (pos === start ||
6163
(hasLength &&
62-
this.pos - start !== length)) {
64+
pos - start !== length)) {
6365
return null
6466
}
6567

src/caching-compiler.js

+46-18
Original file line numberDiff line numberDiff line change
@@ -211,27 +211,43 @@ function init() {
211211
const metas = cache.meta
212212

213213
scripts.forEach((script, cacheName) => {
214-
const compileData = compileDatas.get(cacheName)
215-
const cachedData = compileData != null ? compileData.scriptData : null
214+
let compileData = compileDatas.get(cacheName)
216215

217-
let scriptData
218-
let changed = false
216+
if (compileData === void 0) {
217+
compileData = null
218+
}
219+
220+
let cachedData
221+
222+
if (compileData !== null) {
223+
cachedData = compileData.scriptData
219224

220-
if (cachedData === null) {
221-
scriptData = useCreateCachedData
222-
? script.createCachedData()
223-
: script.cachedData
225+
if (cachedData === null) {
226+
cachedData = void 0
227+
}
224228
}
225229

226-
if (scriptData &&
230+
let changed = false
231+
let scriptData = null
232+
233+
if (cachedData === void 0) {
234+
if (useCreateCachedData &&
235+
typeof script.createCachedData === "function") {
236+
scriptData = script.createCachedData()
237+
} else if (script.cachedDataProduced) {
238+
scriptData = script.cachedData
239+
}
240+
}
241+
242+
if (scriptData !== null &&
227243
scriptData.length) {
228244
changed = true
229245
}
230246

231-
if (compileData) {
232-
if (scriptData) {
247+
if (compileData !== null) {
248+
if (scriptData !== null) {
233249
compileData.scriptData = scriptData
234-
} else if (cachedData &&
250+
} else if (cachedData !== void 0 &&
235251
script.cachedDataRejected) {
236252
changed = true
237253

@@ -275,9 +291,13 @@ function init() {
275291

276292
meta = [-1, -1]
277293

278-
const compileData = compileDatas.get(cacheName)
294+
let compileData = compileDatas.get(cacheName)
295+
296+
if (compileData === void 0) {
297+
compileData = null
298+
}
279299

280-
if (compileData != null) {
300+
if (compileData !== null) {
281301
const {
282302
filename,
283303
firstAwaitOutsideFunction,
@@ -331,20 +351,28 @@ function init() {
331351
let scriptData = scriptDatas.get(cacheName)
332352

333353
if (scriptData === void 0) {
334-
const compileData = compileDatas.get(cacheName)
354+
let compileData = compileDatas.get(cacheName)
355+
356+
if (compileData === void 0) {
357+
compileData = null
358+
}
359+
335360
const [offsetStart, offsetEnd] = meta
336361

337-
if (compileData != null) {
362+
scriptData = null
363+
364+
if (compileData !== null) {
338365
scriptData = compileData.scriptData
339366
} else if (offsetStart !== -1 &&
340367
offsetEnd !== -1) {
341368
scriptData = GenericBuffer.slice(buffer, offsetStart, offsetEnd)
342369
}
343370
}
344371

345-
if (scriptData) {
372+
if (scriptData !== null) {
346373
meta[0] = offset
347-
meta[1] = offset += scriptData.length
374+
offset += scriptData.length
375+
meta[1] = offset
348376
buffers.push(scriptData)
349377
}
350378

src/module/internal/compile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ function compile(caller, entry, content, filename, fallback) {
9494
const { cacheName } = entry
9595
const { cjs } = options
9696

97-
const scriptData = compileData
98-
? compileData.scriptData
99-
: null
97+
const scriptData = compileData === null
98+
? null
99+
: compileData.scriptData
100100

101101
compileData = tryCompile(caller, entry, content, {
102102
cacheName,

0 commit comments

Comments
 (0)