@@ -2,18 +2,16 @@ import fs from 'node:fs/promises'
22import { fileURLToPath } from 'node:url'
33import { transform } from 'esbuild'
44
5- // To do: remove Node 16 version.
6- const { getFormat, load, transformSource} = createLoader ( )
5+ const { load} = createLoader ( )
76
8- export { getFormat , load , transformSource }
7+ export { load }
98
109/**
1110 * A tiny JSX loader.
1211 */
1312export function createLoader ( ) {
14- return { getFormat , load, transformSource }
13+ return { load}
1514
16- // Node version 17.
1715 /**
1816 * @param {string } href
1917 * URL.
@@ -48,58 +46,4 @@ export function createLoader() {
4846
4947 return { format : 'module' , shortCircuit : true , source : code }
5048 }
51-
52- // Pre version 17.
53- /**
54- * @param {string } href
55- * URL.
56- * @param {unknown } context
57- * Context.
58- * @param {Function } defaultGetFormat
59- * Default `getFormat`.
60- * @returns
61- * Result.
62- */
63- function getFormat ( href , context , defaultGetFormat ) {
64- const url = new URL ( href )
65-
66- return url . pathname . endsWith ( '.jsx' )
67- ? { format : 'module' }
68- : defaultGetFormat ( href , context , defaultGetFormat )
69- }
70-
71- /**
72- * @param {Buffer } value
73- * Code.
74- * @param {{url: string, [x: string]: unknown} } context
75- * Context.
76- * @param {Function } defaultTransformSource
77- * Default `transformSource`.
78- * @returns
79- * Result.
80- */
81- async function transformSource ( value , context , defaultTransformSource ) {
82- const url = new URL ( context . url )
83-
84- if ( ! url . pathname . endsWith ( '.jsx' ) ) {
85- return defaultTransformSource ( value , context , defaultTransformSource )
86- }
87-
88- const { code, warnings} = await transform ( String ( value ) , {
89- format : context . format === 'module' ? 'esm' : 'cjs' ,
90- loader : 'jsx' ,
91- sourcefile : fileURLToPath ( url ) ,
92- sourcemap : 'both' ,
93- target : 'esnext'
94- } )
95-
96- if ( warnings ) {
97- for ( const warning of warnings ) {
98- console . log ( warning . location )
99- console . log ( warning . text )
100- }
101- }
102-
103- return { source : code }
104- }
10549}
0 commit comments