@@ -747,6 +747,30 @@ describe('Loader hooks', { concurrency: true }, () => {
747747 assert . strictEqual ( signal , null ) ;
748748 } ) ;
749749
750+ it ( 'should support source maps in commonjs translator' , async ( ) => {
751+ const readFile = async ( ) => { } ;
752+ const fileURLToPath = ( ) => { } ;
753+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
754+ '--no-warnings' ,
755+ '--enable-source-maps' ,
756+ '--experimental-loader' ,
757+ `data:text/javascript,import{readFile}from"node:fs/promises";import{fileURLToPath}from"node:url";export ${
758+ async function load ( u , c , n ) {
759+ const r = await n ( u , c ) ;
760+ if ( c . format === 'commonjs' ) {
761+ r . source = await readFile ( new URL ( u ) ) ;
762+ }
763+ return r ;
764+ } } `,
765+ fixtures . path ( 'source-map/throw-on-require.js' ) ,
766+ ] ) ;
767+
768+ assert . strictEqual ( stdout , '' ) ;
769+ assert . match ( stderr , / t h r o w - o n - r e q u i r e \. t s : 9 : 9 / ) ;
770+ assert . strictEqual ( code , 1 ) ;
771+ assert . strictEqual ( signal , null ) ;
772+ } ) ;
773+
750774 it ( 'should handle mixed of opt-in modules and non-opt-in ones' , async ( ) => {
751775 const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
752776 '--no-warnings' ,
0 commit comments