@@ -321,7 +321,7 @@ describe('sourcemapTool', () => {
321321 expect ( sourceMap ) . toBe ( 'console.log("test");' ) ;
322322 } ) ;
323323
324- it ( 'should skip source map assets without a source' , async ( ) => {
324+ it ( 'should fall back to AST parsing when a related source map has no source' , async ( ) => {
325325 const plugin = createMockPluginInstance ( ) ;
326326 const compilation = {
327327 compiler : { rspack : { } } ,
@@ -331,6 +331,18 @@ describe('sourcemapTool', () => {
331331 } ,
332332 } ,
333333 getAssets : ( ) => [
334+ {
335+ name : 'main.js' ,
336+ source : {
337+ source : ( ) => 'console.log("test");\n' ,
338+ name : 'main.js' ,
339+ sourceAndMap : ( ) => ( {
340+ source : 'console.log("test");\n' ,
341+ map : mockJsMap ,
342+ } ) ,
343+ } ,
344+ info : { } ,
345+ } ,
334346 {
335347 name : 'worker.abc123.js' ,
336348 source : {
@@ -355,7 +367,66 @@ describe('sourcemapTool', () => {
355367 } as any ;
356368
357369 await handleAfterEmitAssets ( compilation , plugin ) ;
358- expect ( plugin . sourceMapSets . size ) . toBe ( 0 ) ;
370+ expect ( plugin . sourceMapSets . size ) . toBe ( 1 ) ;
371+ expect ( plugin . assetsWithoutSourceMap ) . toEqual (
372+ new Set ( [ 'worker.abc123.js' ] ) ,
373+ ) ;
374+ } ) ;
375+
376+ it ( 'should fall back to AST parsing when a related source map is invalid' , async ( ) => {
377+ const plugin = createMockPluginInstance ( ) ;
378+ const compilation = {
379+ compiler : { rspack : { } } ,
380+ options : {
381+ output : {
382+ filename : '[name].[contenthash].js' ,
383+ } ,
384+ } ,
385+ getAssets : ( ) => [
386+ {
387+ name : 'main.js' ,
388+ source : {
389+ source : ( ) => 'console.log("test");\n' ,
390+ name : 'main.js' ,
391+ sourceAndMap : ( ) => ( {
392+ source : 'console.log("test");\n' ,
393+ map : mockJsMap ,
394+ } ) ,
395+ } ,
396+ info : { } ,
397+ } ,
398+ {
399+ name : 'worker.abc123.js' ,
400+ source : {
401+ source : ( ) => 'console.log("worker");\n' ,
402+ name : 'worker.abc123.js' ,
403+ sourceAndMap : ( ) => ( {
404+ source : 'console.log("worker");\n' ,
405+ map : null ,
406+ } ) ,
407+ } ,
408+ info : {
409+ related : {
410+ sourceMap : 'worker.abc123.js.map' ,
411+ } ,
412+ } ,
413+ } ,
414+ {
415+ name : 'worker.abc123.js.map' ,
416+ source : {
417+ source : ( ) => '{}' ,
418+ name : 'worker.abc123.js.map' ,
419+ } ,
420+ info : { } ,
421+ } ,
422+ ] ,
423+ } as any ;
424+
425+ await handleAfterEmitAssets ( compilation , plugin ) ;
426+ expect ( plugin . sourceMapSets . size ) . toBe ( 1 ) ;
427+ expect ( plugin . assetsWithoutSourceMap ) . toEqual (
428+ new Set ( [ 'worker.abc123.js' ] ) ,
429+ ) ;
359430 } ) ;
360431
361432 it ( 'should find source map by base name without hash when exact match fails' , async ( ) => {
0 commit comments