7
7
* @typedef {import('esbuild').Message } Message
8
8
* @typedef {import('vfile').VFileValue } VFileValue
9
9
* @typedef {import('vfile-message').VFileMessage } VFileMessage
10
- * @typedef {import('unist').Point } Point
11
10
* @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.
14
16
*/
15
17
16
18
import assert from 'node:assert'
@@ -32,11 +34,11 @@ const p = process
32
34
/**
33
35
* Compile MDX w/ esbuild.
34
36
*
35
- * @param {Options } [options]
37
+ * @param {Options | null | undefined } [options]
36
38
* @return {Plugin }
37
39
*/
38
- export function esbuild ( options = { } ) {
39
- const { allowDangerousRemoteMdx, ...rest } = options
40
+ export function esbuild ( options ) {
41
+ const { allowDangerousRemoteMdx, ...rest } = options || { }
40
42
const name = '@mdx-js/esbuild'
41
43
const remoteNamespace = name + '-remote'
42
44
const { extnames, process} = createFormatAwareProcessors ( rest )
@@ -123,22 +125,24 @@ export function esbuild(options = {}) {
123
125
}
124
126
125
127
/**
126
- * @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: string|Buffer }} } data
128
+ * @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: Buffer | string | null | undefined }} } data
127
129
* @returns {Promise<OnLoadResult> }
128
130
*/
129
131
async function onload ( data ) {
130
132
/** @type {string } */
131
133
const doc = String (
132
- data . pluginData && data . pluginData . contents !== undefined
134
+ data . pluginData &&
135
+ data . pluginData . contents !== null &&
136
+ data . pluginData . contents !== undefined
133
137
? data . pluginData . contents
134
138
: /* eslint-disable-next-line security/detect-non-literal-fs-filename */
135
139
await fs . readFile ( data . path )
136
140
)
137
141
138
142
let file = new VFile ( { value : doc , path : data . path } )
139
- /** @type {VFileValue| undefined } */
143
+ /** @type {VFileValue | undefined } */
140
144
let value
141
- /** @type {Array<VFileMessage| Error> } */
145
+ /** @type {Array<Error | VFileMessage > } */
142
146
let messages = [ ]
143
147
/** @type {Array<Message> } */
144
148
const errors = [ ]
@@ -150,7 +154,7 @@ export function esbuild(options = {}) {
150
154
value = file . value
151
155
messages = file . messages
152
156
} catch ( error_ ) {
153
- const error = /** @type {VFileMessage| Error } */ ( error_ )
157
+ const error = /** @type {Error | VFileMessage } */ ( error_ )
154
158
if ( 'fatal' in error ) error . fatal = true
155
159
messages . push ( error )
156
160
}
@@ -225,7 +229,7 @@ export function esbuild(options = {}) {
225
229
// V8 on Erbium.
226
230
/* c8 ignore next 9 */
227
231
return {
228
- contents : value ,
232
+ contents : value || '' ,
229
233
errors,
230
234
warnings,
231
235
resolveDir : http . test ( file . path )
0 commit comments