File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
packages/plugin-rsc/src/transforms Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,8 @@ if (true) {
5757`
5858 expect ( await testTransform ( input ) ) . toMatchInlineSnapshot ( `
5959 "const exports = {}; const module = { exports };
60- const __cjs_to_esm_hoist_1 = await import("react-dom");
6160 const __cjs_to_esm_hoist_0 = await import("react");
61+ const __cjs_to_esm_hoist_1 = await import("react-dom");
6262 "production" !== process.env.NODE_ENV && (function() {
6363 var React = __cjs_to_esm_hoist_0;
6464 var ReactDOM = __cjs_to_esm_hoist_1;
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ export function transformCjsToEsm(
1010 const output = new MagicString ( code )
1111 const analyzed = analyze ( ast )
1212
13- let parentNodes : Node [ ] = [ ]
13+ const parentNodes : Node [ ] = [ ]
14+ const hoistedCodes : string [ ] = [ ]
1415 let hoistIndex = 0
1516 walk ( ast , {
1617 enter ( node ) {
@@ -49,7 +50,7 @@ export function transformCjsToEsm(
4950 node . arguments [ 0 ] ! . start ,
5051 node . arguments [ 0 ] ! . end ,
5152 )
52- output . prepend ( `const ${ hoisted } = await import(${ importee } );\n` )
53+ hoistedCodes . push ( `const ${ hoisted } = await import(${ importee } );\n` )
5354 output . update ( node . start , node . end , hoisted )
5455 hoistIndex ++
5556 }
@@ -59,6 +60,9 @@ export function transformCjsToEsm(
5960 parentNodes . pop ( ) !
6061 } ,
6162 } )
63+ for ( const hoisted of hoistedCodes . reverse ( ) ) {
64+ output . prepend ( hoisted )
65+ }
6266 output . prepend ( `const exports = {}; const module = { exports };\n` )
6367 return { output }
6468}
You can’t perform that action at this time.
0 commit comments