77 * @typedef {import('esbuild').Message } Message
88 * @typedef {import('vfile').VFileValue } VFileValue
99 * @typedef {import('vfile-message').VFileMessage } VFileMessage
10- * @typedef {import('unist').Point } Point
1110 * @typedef {import('@mdx-js/mdx/lib/core.js').ProcessorOptions } ProcessorOptions
12- *
13- * @typedef {ProcessorOptions & {allowDangerousRemoteMdx?: boolean} } Options
11+ */
12+
13+ /**
14+ * @typedef {ProcessorOptions & {allowDangerousRemoteMdx?: boolean | null | undefined} } Options
15+ * Configuration.
1416 */
1517
1618import assert from 'node:assert'
@@ -32,11 +34,11 @@ const p = process
3234/**
3335 * Compile MDX w/ esbuild.
3436 *
35- * @param {Options } [options]
37+ * @param {Options | null | undefined } [options]
3638 * @return {Plugin }
3739 */
38- export function esbuild ( options = { } ) {
39- const { allowDangerousRemoteMdx, ...rest } = options
40+ export function esbuild ( options ) {
41+ const { allowDangerousRemoteMdx, ...rest } = options || { }
4042 const name = '@mdx-js/esbuild'
4143 const remoteNamespace = name + '-remote'
4244 const { extnames, process} = createFormatAwareProcessors ( rest )
@@ -123,22 +125,24 @@ export function esbuild(options = {}) {
123125 }
124126
125127 /**
126- * @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: string|Buffer }} } data
128+ * @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: Buffer | string | null | undefined }} } data
127129 * @returns {Promise<OnLoadResult> }
128130 */
129131 async function onload ( data ) {
130132 /** @type {string } */
131133 const doc = String (
132- data . pluginData && data . pluginData . contents !== undefined
134+ data . pluginData &&
135+ data . pluginData . contents !== null &&
136+ data . pluginData . contents !== undefined
133137 ? data . pluginData . contents
134138 : /* eslint-disable-next-line security/detect-non-literal-fs-filename */
135139 await fs . readFile ( data . path )
136140 )
137141
138142 let file = new VFile ( { value : doc , path : data . path } )
139- /** @type {VFileValue| undefined } */
143+ /** @type {VFileValue | undefined } */
140144 let value
141- /** @type {Array<VFileMessage| Error> } */
145+ /** @type {Array<Error | VFileMessage > } */
142146 let messages = [ ]
143147 /** @type {Array<Message> } */
144148 const errors = [ ]
@@ -150,7 +154,7 @@ export function esbuild(options = {}) {
150154 value = file . value
151155 messages = file . messages
152156 } catch ( error_ ) {
153- const error = /** @type {VFileMessage| Error } */ ( error_ )
157+ const error = /** @type {Error | VFileMessage } */ ( error_ )
154158 if ( 'fatal' in error ) error . fatal = true
155159 messages . push ( error )
156160 }
@@ -225,7 +229,7 @@ export function esbuild(options = {}) {
225229 // V8 on Erbium.
226230 /* c8 ignore next 9 */
227231 return {
228- contents : value ,
232+ contents : value || '' ,
229233 errors,
230234 warnings,
231235 resolveDir : http . test ( file . path )
0 commit comments