File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed
Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ describe('transformCjsImport', () => {
7474 ) ,
7575 ) . toBe (
7676 'import __vite__cjsImport0_react from "./node_modules/.vite/deps/react.js"; ' +
77- `const react = (m => m?.__esModule ? m : { ...( typeof m === ' object' && !Array.isArray(m) ? m : {}) , default: m })(__vite__cjsImport0_react)` ,
77+ `const react = ((m) => m?.__esModule ? m : { ...typeof m === " object" && !Array.isArray(m) ? m : {}, default: m })(__vite__cjsImport0_react)` ,
7878 )
7979 } )
8080
Original file line number Diff line number Diff line change @@ -847,6 +847,8 @@ export function createParseErrorInfo(
847847 showCodeFrame : ! probablyBinary ,
848848 }
849849}
850+ // prettier-ignore
851+ const interopHelper = ( m : any ) => m ?. __esModule ? m : { ...( typeof m === 'object' && ! Array . isArray ( m ) ? m : { } ) , default : m }
850852
851853export function interopNamedImports (
852854 str : MagicString ,
@@ -870,7 +872,7 @@ export function interopNamedImports(
870872 str . overwrite (
871873 expStart ,
872874 expEnd ,
873- `import('${ rewrittenUrl } ').then(m => (m => m?.__esModule ? m : { ...(typeof m === 'object' && !Array.isArray(m) ? m : {}), default: m })(m.default))` +
875+ `import('${ rewrittenUrl } ').then(m => (${ interopHelper . toString ( ) } )(m.default))` +
874876 getLineBreaks ( exp ) ,
875877 { contentOnly : true } ,
876878 )
@@ -1007,7 +1009,7 @@ export function transformCjsImport(
10071009 importNames . forEach ( ( { importedName, localName } ) => {
10081010 if ( importedName === '*' ) {
10091011 lines . push (
1010- `const ${ localName } = (m => m?.__esModule ? m : { ...(typeof m === 'object' && !Array.isArray(m) ? m : {}), default: m })(${ cjsModuleName } )` ,
1012+ `const ${ localName } = (${ interopHelper . toString ( ) } )(${ cjsModuleName } )` ,
10111013 )
10121014 } else if ( importedName === 'default' ) {
10131015 lines . push (
You can’t perform that action at this time.
0 commit comments