File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,13 @@ function interopDefault(mod: any): any {
124124 return true ;
125125 }
126126 if ( prop === "default" ) {
127- return defIsNil ? mod : def ;
127+ if ( defIsNil ) {
128+ return mod ;
129+ }
130+ if ( typeof def ?. default === "function" && mod . __esModule ) {
131+ return def . default ; // #396
132+ }
133+ return def ;
128134 }
129135 if ( Reflect . has ( target , prop ) ) {
130136 return Reflect . get ( target , prop , receiver ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ exports[`fixtures > async > stdout 1`] = `"works"`;
44
55exports [` fixtures > circular > stdout 1` ] = ` "a b c"` ;
66
7+ exports [` fixtures > cjs-interop > stdout 1` ] = ` "CJS function default interop test passed"` ;
8+
79exports [` fixtures > data-uri > stdout 1` ] = ` ""` ;
810
911exports [` fixtures > deps > stdout 1` ] = `
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ __esModule : true ,
3+ default : function myPlugin ( ) {
4+ return "ok" ;
5+ } ,
6+ } ;
Original file line number Diff line number Diff line change 1+ const { createJiti } = require ( "../../../lib/jiti.cjs" ) ;
2+ const path = require ( "node:path" ) ;
3+
4+ async function main ( ) {
5+ const jiti = createJiti ( __filename ) ;
6+ const modPath = path . resolve ( __dirname , "./function-default.cjs" ) ;
7+
8+ const loaded = await jiti . import ( modPath , { default : true } ) ;
9+
10+ if ( typeof loaded === "function" ) {
11+ console . log ( "CJS function default interop test passed" ) ;
12+ } else {
13+ console . log ( "CJS function default interop test failed" ) ;
14+ }
15+ }
16+
17+ main ( ) . catch ( ( error_ ) => {
18+ console . error ( "Error:" , error_ ) ;
19+ } ) ;
You can’t perform that action at this time.
0 commit comments