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'
66
66
* Plugin.
67
67
*/
68
68
export function esbuild ( options ) {
69
- const { extnames, process} = createFormatAwareProcessors ( {
70
- ...options ,
71
- SourceMapGenerator
72
- } )
69
+ const settings = { ...options , SourceMapGenerator} ;
70
+ const { extnames, process} = createFormatAwareProcessors ( settings )
73
71
74
72
return { name, setup}
75
73
@@ -142,6 +140,7 @@ export function esbuild(options) {
142
140
return {
143
141
contents : value || '' ,
144
142
errors,
143
+ loader : settings . jsx ? 'jsx' : 'js' ,
145
144
resolveDir : path . resolve ( file . cwd , file . dirname ) ,
146
145
warnings
147
146
}
Original file line number Diff line number Diff line change @@ -570,6 +570,36 @@ test('@mdx-js/esbuild', async function (t) {
570
570
await fs . rm ( mdxUrl )
571
571
await fs . rm ( jsUrl )
572
572
} )
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
+ } )
573
603
} )
574
604
575
605
/**
You can’t perform that action at this time.
0 commit comments