@@ -559,8 +559,6 @@ class TerserPlugin {
559559 `${ name } from Terser plugin\nMinimizer doesn't return result` ,
560560 ) ,
561561 ) ;
562-
563- return ;
564562 }
565563
566564 if ( output . warnings && output . warnings . length > 0 ) {
@@ -615,82 +613,87 @@ class TerserPlugin {
615613 ) ;
616614 }
617615
618- if ( output . map ) {
619- output . source = new SourceMapSource (
620- output . code ,
621- name ,
622- output . map ,
623- input ,
624- /** @type {RawSourceMap } */
625- ( inputSourceMap ) ,
626- true ,
627- ) ;
628- } else {
629- output . source = new RawSource ( output . code ) ;
630- }
616+ if ( output . code ) {
617+ if ( output . map ) {
618+ output . source = new SourceMapSource (
619+ output . code ,
620+ name ,
621+ output . map ,
622+ input ,
623+ /** @type {RawSourceMap } */
624+ ( inputSourceMap ) ,
625+ true ,
626+ ) ;
627+ } else {
628+ output . source = new RawSource ( output . code ) ;
629+ }
631630
632- if ( output . extractedComments && output . extractedComments . length > 0 ) {
633- const commentsFilename =
634- /** @type {ExtractCommentsObject } */
635- ( this . options . extractComments ) . filename ||
636- "[file].LICENSE.txt[query]" ;
631+ if (
632+ output . extractedComments &&
633+ output . extractedComments . length > 0
634+ ) {
635+ const commentsFilename =
636+ /** @type {ExtractCommentsObject } */
637+ ( this . options . extractComments ) . filename ||
638+ "[file].LICENSE.txt[query]" ;
637639
638- let query = "" ;
639- let filename = name ;
640+ let query = "" ;
641+ let filename = name ;
640642
641- const querySplit = filename . indexOf ( "?" ) ;
643+ const querySplit = filename . indexOf ( "?" ) ;
642644
643- if ( querySplit >= 0 ) {
644- query = filename . slice ( querySplit ) ;
645- filename = filename . slice ( 0 , querySplit ) ;
646- }
645+ if ( querySplit >= 0 ) {
646+ query = filename . slice ( querySplit ) ;
647+ filename = filename . slice ( 0 , querySplit ) ;
648+ }
647649
648- const lastSlashIndex = filename . lastIndexOf ( "/" ) ;
649- const basename =
650- lastSlashIndex === - 1
651- ? filename
652- : filename . slice ( lastSlashIndex + 1 ) ;
653- const data = { filename, basename, query } ;
650+ const lastSlashIndex = filename . lastIndexOf ( "/" ) ;
651+ const basename =
652+ lastSlashIndex === - 1
653+ ? filename
654+ : filename . slice ( lastSlashIndex + 1 ) ;
655+ const data = { filename, basename, query } ;
654656
655- output . commentsFilename = compilation . getPath (
656- commentsFilename ,
657- data ,
658- ) ;
657+ output . commentsFilename = compilation . getPath (
658+ commentsFilename ,
659+ data ,
660+ ) ;
659661
660- let banner ;
662+ let banner ;
661663
662- // Add a banner to the original file
663- if (
664- /** @type {ExtractCommentsObject } */
665- ( this . options . extractComments ) . banner !== false
666- ) {
667- banner =
664+ // Add a banner to the original file
665+ if (
668666 /** @type {ExtractCommentsObject } */
669- ( this . options . extractComments ) . banner ||
670- `For license information please see ${ path
671- . relative ( path . dirname ( name ) , output . commentsFilename )
672- . replace ( / \\ / g, "/" ) } `;
673-
674- if ( typeof banner === "function" ) {
675- banner = banner ( output . commentsFilename ) ;
667+ ( this . options . extractComments ) . banner !== false
668+ ) {
669+ banner =
670+ /** @type {ExtractCommentsObject } */
671+ ( this . options . extractComments ) . banner ||
672+ `For license information please see ${ path
673+ . relative ( path . dirname ( name ) , output . commentsFilename )
674+ . replace ( / \\ / g, "/" ) } `;
675+
676+ if ( typeof banner === "function" ) {
677+ banner = banner ( output . commentsFilename ) ;
678+ }
679+
680+ if ( banner ) {
681+ output . source = new ConcatSource (
682+ shebang ? `${ shebang } \n` : "" ,
683+ `/*! ${ banner } */\n` ,
684+ output . source ,
685+ ) ;
686+ }
676687 }
677688
678- if ( banner ) {
679- output . source = new ConcatSource (
680- shebang ? `${ shebang } \n` : "" ,
681- `/*! ${ banner } */\n` ,
682- output . source ,
683- ) ;
684- }
685- }
689+ const extractedCommentsString = output . extractedComments
690+ . sort ( )
691+ . join ( "\n\n" ) ;
686692
687- const extractedCommentsString = output . extractedComments
688- . sort ( )
689- . join ( "\n\n" ) ;
690-
691- output . extractedCommentsSource = new RawSource (
692- `${ extractedCommentsString } \n` ,
693- ) ;
693+ output . extractedCommentsSource = new RawSource (
694+ `${ extractedCommentsString } \n` ,
695+ ) ;
696+ }
694697 }
695698
696699 await cacheItem . storePromise ( {
@@ -714,6 +717,10 @@ class TerserPlugin {
714717 }
715718 }
716719
720+ if ( ! output . source ) {
721+ return ;
722+ }
723+
717724 /** @type {AssetInfo } */
718725 const newInfo = { minimized : true } ;
719726 const { source, extractedCommentsSource } = output ;
0 commit comments