File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,8 @@ const name = '@mdx-js/esbuild'
6666 * Plugin.
6767 */
6868export function esbuild ( options ) {
69- const { extnames, process} = createFormatAwareProcessors ( {
70- ...options ,
71- SourceMapGenerator
72- } )
69+ const settings = { ...options , SourceMapGenerator} ;
70+ const { extnames, process} = createFormatAwareProcessors ( settings )
7371
7472 return { name, setup}
7573
@@ -142,6 +140,7 @@ export function esbuild(options) {
142140 return {
143141 contents : value || '' ,
144142 errors,
143+ loader : settings . jsx ? 'jsx' : 'js' ,
145144 resolveDir : path . resolve ( file . cwd , file . dirname ) ,
146145 warnings
147146 }
Original file line number Diff line number Diff line change @@ -570,6 +570,36 @@ test('@mdx-js/esbuild', async function (t) {
570570 await fs . rm ( mdxUrl )
571571 await fs . rm ( jsUrl )
572572 } )
573+
574+ await t . test ( 'should use esbuild "jsx" loader for JSX output' , async ( ) => {
575+ const mdxUrl = new URL ( 'esbuild.mdx' , import . meta. url )
576+ const jsUrl = new URL ( 'esbuild.js' , import . meta. url )
577+ await fs . writeFile (
578+ mdxUrl ,
579+ 'export function Message() { return <>World!</> }\n\n# Hello, <Message />'
580+ )
581+
582+ await esbuild . build ( {
583+ entryPoints : [ fileURLToPath ( mdxUrl ) ] ,
584+ outfile : fileURLToPath ( jsUrl ) ,
585+ plugins : [ esbuildMdx ( { jsx : true } ) ] ,
586+ define : { 'process.env.NODE_ENV' : '"development"' } ,
587+ format : 'esm' ,
588+ bundle : true
589+ } )
590+
591+ /** @type {MDXModule } */
592+ const result = await import ( jsUrl . href + '#' + Math . random ( ) )
593+ const Content = result . default
594+
595+ assert . equal (
596+ renderToStaticMarkup ( React . createElement ( Content ) ) ,
597+ '<h1>Hello, World!</h1>'
598+ )
599+
600+ await fs . rm ( mdxUrl )
601+ await fs . rm ( jsUrl )
602+ } )
573603} )
574604
575605/**
You can’t perform that action at this time.
0 commit comments