@@ -178,13 +178,58 @@ describe("route chunks", () => {
178178 "import { shared } from "./shared";
179179 export const chunk = shared("chunk");"
180180 ` ) ;
181- expect ( getChunkedExport ( code , "main" , { } , ...cache ) ?. code )
181+ expect ( omitChunkedExports ( code , [ "chunk" ] , { } , ...cache ) ?. code )
182182 . toMatchInlineSnapshot ( `
183183 "import { shared } from "./shared";
184184 export const main = shared("main");"
185185 ` ) ;
186186 } ) ;
187187
188+ test ( "shared imports across chunks but not main chunk" , ( ) => {
189+ const code = dedent `
190+ import { shared } from "./shared";
191+ export const chunk1 = shared("chunk1");
192+ export const chunk2 = shared("chunk2");
193+ export const main = "main";
194+ ` ;
195+ expect ( hasChunkableExport ( code , "chunk1" , ...cache ) ) . toBe ( true ) ;
196+ expect ( hasChunkableExport ( code , "chunk2" , ...cache ) ) . toBe ( true ) ;
197+ expect ( hasChunkableExport ( code , "main" , ...cache ) ) . toBe ( true ) ;
198+ expect ( getChunkedExport ( code , "chunk1" , { } , ...cache ) ?. code )
199+ . toMatchInlineSnapshot ( `
200+ "import { shared } from "./shared";
201+ export const chunk1 = shared("chunk1");"
202+ ` ) ;
203+ expect ( getChunkedExport ( code , "chunk2" , { } , ...cache ) ?. code )
204+ . toMatchInlineSnapshot ( `
205+ "import { shared } from "./shared";
206+ export const chunk2 = shared("chunk2");"
207+ ` ) ;
208+ expect (
209+ omitChunkedExports ( code , [ "chunk1" , "chunk2" ] , { } , ...cache ) ?. code
210+ ) . toMatchInlineSnapshot ( `"export const main = "main";"` ) ;
211+ } ) ;
212+
213+ test ( "import with side effect usage" , ( ) => {
214+ const code = dedent `
215+ import { sideEffect } from "./side-effect";
216+ sideEffect();
217+ export const chunk = "chunk";
218+ export const main = "main";
219+ ` ;
220+ expect ( hasChunkableExport ( code , "chunk" , ...cache ) ) . toBe ( true ) ;
221+ expect ( hasChunkableExport ( code , "main" , ...cache ) ) . toBe ( true ) ;
222+ expect (
223+ getChunkedExport ( code , "chunk" , { } , ...cache ) ?. code
224+ ) . toMatchInlineSnapshot ( `"export const chunk = "chunk";"` ) ;
225+ expect ( omitChunkedExports ( code , [ "chunk" ] , { } , ...cache ) ?. code )
226+ . toMatchInlineSnapshot ( `
227+ "import { sideEffect } from "./side-effect";
228+ sideEffect();
229+ export const main = "main";"
230+ ` ) ;
231+ } ) ;
232+
188233 test ( "re-exports using shared statement" , ( ) => {
189234 const code = dedent `
190235 export { chunk1, chunk2, main } from "./shared";
@@ -927,6 +972,29 @@ describe("route chunks", () => {
927972 export const main = getMainMessage();"
928973 ` ) ;
929974 } ) ;
975+
976+ test ( "shared imports across chunks but not main chunk with shared side effect usage" , ( ) => {
977+ const code = dedent `
978+ import { shared } from "./shared";
979+ shared("side-effect");
980+ export const chunk1 = shared("chunk1");
981+ export const chunk2 = shared("chunk2");
982+ export const main = "main";
983+ ` ;
984+ expect ( hasChunkableExport ( code , "chunk1" , ...cache ) ) . toBe ( false ) ;
985+ expect ( hasChunkableExport ( code , "chunk2" , ...cache ) ) . toBe ( false ) ;
986+ expect ( hasChunkableExport ( code , "main" , ...cache ) ) . toBe ( true ) ;
987+ expect ( getChunkedExport ( code , "chunk1" , { } , ...cache ) ) . toBeUndefined ( ) ;
988+ expect ( getChunkedExport ( code , "chunk2" , { } , ...cache ) ) . toBeUndefined ( ) ;
989+ expect ( omitChunkedExports ( code , [ "chunk1" , "chunk2" ] , { } , ...cache ) ?. code )
990+ . toMatchInlineSnapshot ( `
991+ "import { shared } from "./shared";
992+ shared("side-effect");
993+ export const chunk1 = shared("chunk1");
994+ export const chunk2 = shared("chunk2");
995+ export const main = "main";"
996+ ` ) ;
997+ } ) ;
930998 } ) ;
931999
9321000 describe ( "export dependency analysis" , ( ) => {
0 commit comments