@@ -192,6 +192,27 @@ const toSearchCodeSplitting = {
192
192
out : 'out.ts' ,
193
193
}
194
194
195
+ const testCaseCodeSplittingEmptyFile = {
196
+ 'entry1.ts' : `
197
+ import './a.ts'
198
+ import './empty.ts'
199
+ import './b.ts'
200
+ ` ,
201
+ 'entry2.ts' : `
202
+ import './a.ts'
203
+ import './empty.ts'
204
+ import './b.ts'
205
+ ` ,
206
+ 'a.ts' : `'foo'.print()` ,
207
+ 'empty.ts' : `//! @preserve` ,
208
+ 'b.ts' : `'bar'.print()` ,
209
+ }
210
+
211
+ const toSearchCodeSplittingEmptyFile = {
212
+ foo : 'a.ts' ,
213
+ bar : 'b.ts' ,
214
+ }
215
+
195
216
const testCaseUnicode = {
196
217
'entry.js' : `
197
218
import './a'
@@ -430,7 +451,7 @@ const toSearchNullSourcesContent = {
430
451
bar : 'bar.ts' ,
431
452
}
432
453
433
- async function check ( kind , testCase , toSearch , { ext, flags, entryPoints, crlf, followUpFlags = [ ] } ) {
454
+ async function check ( kind , testCase , toSearch , { ext, flags, entryPoints, crlf, followUpFlags = [ ] , checkChunk } ) {
434
455
let failed = 0
435
456
436
457
try {
@@ -470,6 +491,18 @@ async function check(kind, testCase, toSearch, { ext, flags, entryPoints, crlf,
470
491
471
492
let outCode
472
493
let outCodeMap
494
+ let outPrefix = 'out'
495
+
496
+ // Optionally check the first chunk when splitting
497
+ if ( checkChunk && flags . includes ( '--splitting' ) ) {
498
+ const entries = await fs . readdir ( tempDir )
499
+ for ( const entry of entries . sort ( ) ) {
500
+ if ( entry . startsWith ( 'chunk-' ) ) {
501
+ outPrefix = entry . slice ( 0 , entry . indexOf ( '.' ) )
502
+ break
503
+ }
504
+ }
505
+ }
473
506
474
507
if ( isStdin ) {
475
508
outCode = stdout
@@ -478,9 +511,9 @@ async function check(kind, testCase, toSearch, { ext, flags, entryPoints, crlf,
478
511
}
479
512
480
513
else {
481
- outCode = await fs . readFile ( path . join ( tempDir , `out .${ ext } ` ) , 'utf8' )
482
- recordCheck ( outCode . includes ( `# sourceMappingURL=out .${ ext } .map` ) , `.${ ext } file must link to .${ ext } .map` )
483
- outCodeMap = await fs . readFile ( path . join ( tempDir , `out .${ ext } .map` ) , 'utf8' )
514
+ outCode = await fs . readFile ( path . join ( tempDir , `${ outPrefix } .${ ext } ` ) , 'utf8' )
515
+ recordCheck ( outCode . includes ( `# sourceMappingURL=${ outPrefix } .${ ext } .map` ) , `.${ ext } file must link to .${ ext } .map` )
516
+ outCodeMap = await fs . readFile ( path . join ( tempDir , `${ outPrefix } .${ ext } .map` ) , 'utf8' )
484
517
}
485
518
486
519
// Check the mapping of various key locations back to the original source
@@ -558,7 +591,7 @@ async function check(kind, testCase, toSearch, { ext, flags, entryPoints, crlf,
558
591
559
592
// Bundle again to test nested source map chaining
560
593
for ( let order of [ 0 , 1 , 2 ] ) {
561
- const fileToTest = isStdin ? `stdout.${ ext } ` : `out .${ ext } `
594
+ const fileToTest = isStdin ? `stdout.${ ext } ` : `${ outPrefix } .${ ext } `
562
595
const nestedEntry = path . join ( tempDir , `nested-entry.${ ext } ` )
563
596
if ( isStdin ) await fs . writeFile ( path . join ( tempDir , fileToTest ) , outCode )
564
597
await fs . writeFile ( path . join ( tempDir , `extra.${ ext } ` ) , `console.log('extra')` )
@@ -572,6 +605,7 @@ async function check(kind, testCase, toSearch, { ext, flags, entryPoints, crlf,
572
605
'--bundle' ,
573
606
'--outfile=' + path . join ( tempDir , `out2.${ ext } ` ) ,
574
607
'--sourcemap' ,
608
+ '--format=esm' ,
575
609
] . concat ( followUpFlags ) , { cwd : testDir } )
576
610
577
611
const out2Code = await fs . readFile ( path . join ( tempDir , `out2.${ ext } ` ) , 'utf8' )
@@ -892,6 +926,15 @@ async function main() {
892
926
entryPoints : [ 'foo.js' ] ,
893
927
crlf,
894
928
} ) ,
929
+
930
+ // This checks for issues with files in a bundle that don't emit source maps
931
+ check ( 'splitting-empty' + suffix , testCaseCodeSplittingEmptyFile , toSearchCodeSplittingEmptyFile , {
932
+ ext : 'js' ,
933
+ flags : flags . concat ( '--outdir=.' , '--bundle' , '--splitting' , '--format=esm' ) ,
934
+ entryPoints : [ 'entry1.ts' , 'entry2.ts' ] ,
935
+ crlf,
936
+ checkChunk : true ,
937
+ } )
895
938
)
896
939
}
897
940
}
0 commit comments