@@ -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 ) {
@@ -598,99 +596,104 @@ class TerserPlugin {
598596 ) ;
599597 }
600598
601- let shebang ;
602-
603- if (
604- /** @type {ExtractCommentsObject } */
605- ( this . options . extractComments ) . banner !== false &&
606- output . extractedComments &&
607- output . extractedComments . length > 0 &&
608- output . code . startsWith ( "#!" )
609- ) {
610- const firstNewlinePosition = output . code . indexOf ( "\n" ) ;
611-
612- shebang = output . code . slice ( 0 , Math . max ( 0 , firstNewlinePosition ) ) ;
613- output . code = output . code . slice (
614- Math . max ( 0 , firstNewlinePosition + 1 ) ,
615- ) ;
616- }
599+ if ( output . code ) {
600+ let shebang ;
617601
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- }
631-
632- if ( output . extractedComments && output . extractedComments . length > 0 ) {
633- const commentsFilename =
602+ if (
634603 /** @type {ExtractCommentsObject } */
635- ( this . options . extractComments ) . filename ||
636- "[file].LICENSE.txt[query]" ;
637-
638- let query = "" ;
639- let filename = name ;
640-
641- const querySplit = filename . indexOf ( "?" ) ;
604+ ( this . options . extractComments ) . banner !== false &&
605+ output . extractedComments &&
606+ output . extractedComments . length > 0 &&
607+ output . code . startsWith ( "#!" )
608+ ) {
609+ const firstNewlinePosition = output . code . indexOf ( "\n" ) ;
642610
643- if ( querySplit >= 0 ) {
644- query = filename . slice ( querySplit ) ;
645- filename = filename . slice ( 0 , querySplit ) ;
611+ shebang = output . code . slice ( 0 , Math . max ( 0 , firstNewlinePosition ) ) ;
612+ output . code = output . code . slice (
613+ Math . max ( 0 , firstNewlinePosition + 1 ) ,
614+ ) ;
646615 }
647616
648- const lastSlashIndex = filename . lastIndexOf ( "/" ) ;
649- const basename =
650- lastSlashIndex === - 1
651- ? filename
652- : filename . slice ( lastSlashIndex + 1 ) ;
653- const data = { filename , basename , query } ;
654-
655- output . commentsFilename = compilation . getPath (
656- commentsFilename ,
657- data ,
658- ) ;
659-
660- let banner ;
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+ }
661630
662- // Add a banner to the original file
663631 if (
664- /** @type { ExtractCommentsObject } */
665- ( this . options . extractComments ) . banner !== false
632+ output . extractedComments &&
633+ output . extractedComments . length > 0
666634 ) {
667- banner =
635+ const commentsFilename =
668636 /** @type {ExtractCommentsObject } */
669- ( this . options . extractComments ) . banner ||
670- `For license information please see ${ path
671- . relative ( path . dirname ( name ) , output . commentsFilename )
672- . replace ( / \\ / g, "/" ) } `;
637+ ( this . options . extractComments ) . filename ||
638+ "[file].LICENSE.txt[query]" ;
673639
674- if ( typeof banner === "function" ) {
675- banner = banner ( output . commentsFilename ) ;
640+ let query = "" ;
641+ let filename = name ;
642+
643+ const querySplit = filename . indexOf ( "?" ) ;
644+
645+ if ( querySplit >= 0 ) {
646+ query = filename . slice ( querySplit ) ;
647+ filename = filename . slice ( 0 , querySplit ) ;
676648 }
677649
678- if ( banner ) {
679- output . source = new ConcatSource (
680- shebang ? `${ shebang } \n` : "" ,
681- `/*! ${ banner } */\n` ,
682- output . source ,
683- ) ;
650+ const lastSlashIndex = filename . lastIndexOf ( "/" ) ;
651+ const basename =
652+ lastSlashIndex === - 1
653+ ? filename
654+ : filename . slice ( lastSlashIndex + 1 ) ;
655+ const data = { filename, basename, query } ;
656+
657+ output . commentsFilename = compilation . getPath (
658+ commentsFilename ,
659+ data ,
660+ ) ;
661+
662+ let banner ;
663+
664+ // Add a banner to the original file
665+ if (
666+ /** @type {ExtractCommentsObject } */
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+ }
684687 }
685- }
686688
687- const extractedCommentsString = output . extractedComments
688- . sort ( )
689- . join ( "\n\n" ) ;
689+ const extractedCommentsString = output . extractedComments
690+ . sort ( )
691+ . join ( "\n\n" ) ;
690692
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