@@ -392,9 +392,16 @@ class NormalModule extends Module {
392392 * These will contain the variable name and its expression.
393393 * The name will be added as a paramter in a IIFE the expression as its value.
394394 */
395- const vars = block . variables . map ( ( variable ) => this . sourceVariables (
396- variable , availableVars , dependencyTemplates , outputOptions , requestShortener ) )
397- . filter ( Boolean ) ;
395+ const vars = block . variables . reduce ( ( result , value ) => {
396+ const variable = this . sourceVariables (
397+ value , availableVars , dependencyTemplates , outputOptions , requestShortener ) ;
398+
399+ if ( variable ) {
400+ result . push ( variable ) ;
401+ }
402+
403+ return result ;
404+ } , [ ] ) ;
398405
399406 /**
400407 * if we actually have variables
@@ -420,15 +427,22 @@ class NormalModule extends Module {
420427 const injectionVariableChunks = this . splitVariablesInUniqueNamedChunks ( vars ) ;
421428
422429 // create all the beginnings of IIFEs
423- const functionWrapperStarts = injectionVariableChunks . map ( ( variableChunk ) => variableChunk . map ( variable => variable . name ) )
424- . map ( names => this . variableInjectionFunctionWrapperStartCode ( names ) ) ;
430+ const functionWrapperStarts = injectionVariableChunks . map ( ( variableChunk ) => {
431+ return this . variableInjectionFunctionWrapperStartCode (
432+ variableChunk . map ( variable => variable . name )
433+ ) ;
434+ } ) ;
425435
426436 // and all the ends
427- const functionWrapperEnds = injectionVariableChunks . map ( ( variableChunk ) => variableChunk . map ( variable => variable . expression ) )
428- . map ( expressions => this . variableInjectionFunctionWrapperEndCode ( expressions , block ) ) ;
437+ const functionWrapperEnds = injectionVariableChunks . map ( ( variableChunk ) => {
438+ return this . variableInjectionFunctionWrapperEndCode (
439+ variableChunk . map ( variable => variable . expression ) , block
440+ ) ;
441+ } ) ;
429442
430443 // join them to one big string
431444 const varStartCode = functionWrapperStarts . join ( "" ) ;
445+
432446 // reverse the ends first before joining them, as the last added must be the inner most
433447 const varEndCode = functionWrapperEnds . reverse ( ) . join ( "" ) ;
434448
@@ -440,8 +454,17 @@ class NormalModule extends Module {
440454 source . insert ( end + 0.5 , "\n/* WEBPACK VAR INJECTION */" + varEndCode ) ;
441455 }
442456 }
443- block . blocks . forEach ( ( block ) => this . sourceBlock (
444- block , availableVars . concat ( vars ) , dependencyTemplates , source , outputOptions , requestShortener ) ) ;
457+
458+ block . blocks . forEach ( ( block ) =>
459+ this . sourceBlock (
460+ block ,
461+ availableVars . concat ( vars ) ,
462+ dependencyTemplates ,
463+ source ,
464+ outputOptions ,
465+ requestShortener
466+ )
467+ ) ;
445468 }
446469
447470 source ( dependencyTemplates , outputOptions , requestShortener ) {
0 commit comments