@@ -34,7 +34,7 @@ function byId(a, b) {
3434
3535function iterationBlockVariable ( variables , fn ) {
3636 for ( let indexVariable = 0 ; indexVariable < variables . length ; indexVariable ++ ) {
37- let varDep = variables [ indexVariable ] . dependencies ;
37+ const varDep = variables [ indexVariable ] . dependencies ;
3838 for ( let indexVDep = 0 ; indexVDep < varDep . length ; indexVDep ++ ) {
3939 fn ( varDep [ indexVDep ] ) ;
4040 }
@@ -116,8 +116,8 @@ class Compilation extends Tapable {
116116 cacheModule . disconnect ( ) ;
117117 this . _modules [ identifier ] = cacheModule ;
118118 this . modules . push ( cacheModule ) ;
119- cacheModule . errors . forEach ( err => this . errors . push ( err ) , this ) ;
120- cacheModule . warnings . forEach ( err => this . warnings . push ( err ) , this ) ;
119+ cacheModule . errors . forEach ( err => this . errors . push ( err ) ) ;
120+ cacheModule . warnings . forEach ( err => this . warnings . push ( err ) ) ;
121121 return cacheModule ;
122122 }
123123 }
@@ -300,9 +300,7 @@ class Compilation extends Tapable {
300300 iterationDependencies ( dependencies ) ;
301301
302302 if ( _this . profile ) {
303- if ( ! module . profile ) {
304- module . profile = { } ;
305- }
303+ module . profile = module . profile || { } ;
306304 const time = Date . now ( ) - start ;
307305 if ( ! module . profile . dependencies || time > module . profile . dependencies ) {
308306 module . profile . dependencies = time ;
@@ -572,124 +570,119 @@ class Compilation extends Tapable {
572570 }
573571
574572 seal ( callback ) {
575- const self = this ;
576- self . applyPlugins0 ( "seal" ) ;
577- self . nextFreeModuleIndex = 0 ;
578- self . nextFreeModuleIndex2 = 0 ;
579- self . preparedChunks . forEach ( preparedChunk => {
573+ this . applyPlugins0 ( "seal" ) ;
574+ this . nextFreeModuleIndex = 0 ;
575+ this . nextFreeModuleIndex2 = 0 ;
576+ this . preparedChunks . forEach ( preparedChunk => {
580577 const module = preparedChunk . module ;
581- const chunk = self . addChunk ( preparedChunk . name , module ) ;
582- const entrypoint = self . entrypoints [ chunk . name ] = new Entrypoint ( chunk . name ) ;
578+ const chunk = this . addChunk ( preparedChunk . name , module ) ;
579+ const entrypoint = this . entrypoints [ chunk . name ] = new Entrypoint ( chunk . name ) ;
583580 entrypoint . unshiftChunk ( chunk ) ;
584581
585582 chunk . addModule ( module ) ;
586583 module . addChunk ( chunk ) ;
587584 chunk . entryModule = module ;
588- self . assignIndex ( module ) ;
589- self . assignDepth ( module ) ;
585+ this . assignIndex ( module ) ;
586+ this . assignDepth ( module ) ;
590587 } ) ;
591- self . processDependenciesBlocksForChunks ( self . chunks . slice ( ) ) ;
592- self . sortModules ( self . modules ) ;
593- self . applyPlugins0 ( "optimize" ) ;
588+ this . processDependenciesBlocksForChunks ( this . chunks . slice ( ) ) ;
589+ this . sortModules ( this . modules ) ;
590+ this . applyPlugins0 ( "optimize" ) ;
594591
595- while ( self . applyPluginsBailResult1 ( "optimize-modules-basic" , self . modules ) ||
596- self . applyPluginsBailResult1 ( "optimize-modules" , self . modules ) ||
597- self . applyPluginsBailResult1 ( "optimize-modules-advanced" , self . modules ) ) { /* empty */ }
598- self . applyPlugins1 ( "after-optimize-modules" , self . modules ) ;
592+ while ( this . applyPluginsBailResult1 ( "optimize-modules-basic" , this . modules ) ||
593+ this . applyPluginsBailResult1 ( "optimize-modules" , this . modules ) ||
594+ this . applyPluginsBailResult1 ( "optimize-modules-advanced" , this . modules ) ) { /* empty */ }
595+ this . applyPlugins1 ( "after-optimize-modules" , this . modules ) ;
599596
600- while ( self . applyPluginsBailResult1 ( "optimize-chunks-basic" , self . chunks ) ||
601- self . applyPluginsBailResult1 ( "optimize-chunks" , self . chunks ) ||
602- self . applyPluginsBailResult1 ( "optimize-chunks-advanced" , self . chunks ) ) { /* empty */ }
603- self . applyPlugins1 ( "after-optimize-chunks" , self . chunks ) ;
597+ while ( this . applyPluginsBailResult1 ( "optimize-chunks-basic" , this . chunks ) ||
598+ this . applyPluginsBailResult1 ( "optimize-chunks" , this . chunks ) ||
599+ this . applyPluginsBailResult1 ( "optimize-chunks-advanced" , this . chunks ) ) { /* empty */ }
600+ this . applyPlugins1 ( "after-optimize-chunks" , this . chunks ) ;
604601
605- self . applyPluginsAsyncSeries ( "optimize-tree" , self . chunks , self . modules , function sealPart2 ( err ) {
602+ this . applyPluginsAsyncSeries ( "optimize-tree" , this . chunks , this . modules , ( err ) => {
606603 if ( err ) {
607604 return callback ( err ) ;
608605 }
609606
610- self . applyPlugins2 ( "after-optimize-tree" , self . chunks , self . modules ) ;
607+ this . applyPlugins2 ( "after-optimize-tree" , this . chunks , this . modules ) ;
611608
612- while ( self . applyPluginsBailResult ( "optimize-chunk-modules-basic" , self . chunks , self . modules ) ||
613- self . applyPluginsBailResult ( "optimize-chunk-modules" , self . chunks , self . modules ) ||
614- self . applyPluginsBailResult ( "optimize-chunk-modules-advanced" , self . chunks , self . modules ) ) { /* empty */ }
615- self . applyPlugins2 ( "after-optimize-chunk-modules" , self . chunks , self . modules ) ;
609+ while ( this . applyPluginsBailResult ( "optimize-chunk-modules-basic" , this . chunks , this . modules ) ||
610+ this . applyPluginsBailResult ( "optimize-chunk-modules" , this . chunks , this . modules ) ||
611+ this . applyPluginsBailResult ( "optimize-chunk-modules-advanced" , this . chunks , this . modules ) ) { /* empty */ }
612+ this . applyPlugins2 ( "after-optimize-chunk-modules" , this . chunks , this . modules ) ;
616613
617- const shouldRecord = self . applyPluginsBailResult ( "should-record" ) !== false ;
614+ const shouldRecord = this . applyPluginsBailResult ( "should-record" ) !== false ;
618615
619- self . applyPlugins2 ( "revive-modules" , self . modules , self . records ) ;
620- self . applyPlugins1 ( "optimize-module-order" , self . modules ) ;
621- self . applyPlugins1 ( "advanced-optimize-module-order" , self . modules ) ;
622- self . applyPlugins1 ( "before-module-ids" , self . modules ) ;
623- self . applyPlugins1 ( "module-ids" , self . modules ) ;
624- self . applyModuleIds ( ) ;
625- self . applyPlugins1 ( "optimize-module-ids" , self . modules ) ;
626- self . applyPlugins1 ( "after-optimize-module-ids" , self . modules ) ;
616+ this . applyPlugins2 ( "revive-modules" , this . modules , this . records ) ;
617+ this . applyPlugins1 ( "optimize-module-order" , this . modules ) ;
618+ this . applyPlugins1 ( "advanced-optimize-module-order" , this . modules ) ;
619+ this . applyPlugins1 ( "before-module-ids" , this . modules ) ;
620+ this . applyPlugins1 ( "module-ids" , this . modules ) ;
621+ this . applyModuleIds ( ) ;
622+ this . applyPlugins1 ( "optimize-module-ids" , this . modules ) ;
623+ this . applyPlugins1 ( "after-optimize-module-ids" , this . modules ) ;
627624
628- self . sortItemsWithModuleIds ( ) ;
625+ this . sortItemsWithModuleIds ( ) ;
629626
630- self . applyPlugins2 ( "revive-chunks" , self . chunks , self . records ) ;
631- self . applyPlugins1 ( "optimize-chunk-order" , self . chunks ) ;
632- self . applyPlugins1 ( "before-chunk-ids" , self . chunks ) ;
633- self . applyChunkIds ( ) ;
634- self . applyPlugins1 ( "optimize-chunk-ids" , self . chunks ) ;
635- self . applyPlugins1 ( "after-optimize-chunk-ids" , self . chunks ) ;
627+ this . applyPlugins2 ( "revive-chunks" , this . chunks , this . records ) ;
628+ this . applyPlugins1 ( "optimize-chunk-order" , this . chunks ) ;
629+ this . applyPlugins1 ( "before-chunk-ids" , this . chunks ) ;
630+ this . applyChunkIds ( ) ;
631+ this . applyPlugins1 ( "optimize-chunk-ids" , this . chunks ) ;
632+ this . applyPlugins1 ( "after-optimize-chunk-ids" , this . chunks ) ;
636633
637- self . sortItemsWithChunkIds ( ) ;
634+ this . sortItemsWithChunkIds ( ) ;
638635
639636 if ( shouldRecord )
640- self . applyPlugins2 ( "record-modules" , self . modules , self . records ) ;
637+ this . applyPlugins2 ( "record-modules" , this . modules , this . records ) ;
641638 if ( shouldRecord )
642- self . applyPlugins2 ( "record-chunks" , self . chunks , self . records ) ;
639+ this . applyPlugins2 ( "record-chunks" , this . chunks , this . records ) ;
643640
644- self . applyPlugins0 ( "before-hash" ) ;
645- self . createHash ( ) ;
646- self . applyPlugins0 ( "after-hash" ) ;
641+ this . applyPlugins0 ( "before-hash" ) ;
642+ this . createHash ( ) ;
643+ this . applyPlugins0 ( "after-hash" ) ;
647644
648645 if ( shouldRecord )
649- self . applyPlugins1 ( "record-hash" , self . records ) ;
646+ this . applyPlugins1 ( "record-hash" , this . records ) ;
650647
651- self . applyPlugins0 ( "before-module-assets" ) ;
652- self . createModuleAssets ( ) ;
653- if ( self . applyPluginsBailResult ( "should-generate-chunk-assets" ) !== false ) {
654- self . applyPlugins0 ( "before-chunk-assets" ) ;
655- self . createChunkAssets ( ) ;
648+ this . applyPlugins0 ( "before-module-assets" ) ;
649+ this . createModuleAssets ( ) ;
650+ if ( this . applyPluginsBailResult ( "should-generate-chunk-assets" ) !== false ) {
651+ this . applyPlugins0 ( "before-chunk-assets" ) ;
652+ this . createChunkAssets ( ) ;
656653 }
657- self . applyPlugins1 ( "additional-chunk-assets" , self . chunks ) ;
658- self . summarizeDependencies ( ) ;
654+ this . applyPlugins1 ( "additional-chunk-assets" , this . chunks ) ;
655+ this . summarizeDependencies ( ) ;
659656 if ( shouldRecord )
660- self . applyPlugins2 ( "record" , self , self . records ) ;
657+ this . applyPlugins2 ( "record" , this , this . records ) ;
661658
662- self . applyPluginsAsync ( "additional-assets" , err => {
659+ this . applyPluginsAsync ( "additional-assets" , err => {
663660 if ( err ) {
664661 return callback ( err ) ;
665662 }
666- self . applyPluginsAsync ( "optimize-chunk-assets" , self . chunks , err => {
663+ this . applyPluginsAsync ( "optimize-chunk-assets" , this . chunks , err => {
667664 if ( err ) {
668665 return callback ( err ) ;
669666 }
670- self . applyPlugins1 ( "after-optimize-chunk-assets" , self . chunks ) ;
671- self . applyPluginsAsync ( "optimize-assets" , self . assets , err => {
667+ this . applyPlugins1 ( "after-optimize-chunk-assets" , this . chunks ) ;
668+ this . applyPluginsAsync ( "optimize-assets" , this . assets , err => {
672669 if ( err ) {
673670 return callback ( err ) ;
674671 }
675- self . applyPlugins1 ( "after-optimize-assets" , self . assets ) ;
676- if ( self . applyPluginsBailResult ( "need-additional-seal" ) ) {
677- self . unseal ( ) ;
678- return self . seal ( callback ) ;
672+ this . applyPlugins1 ( "after-optimize-assets" , this . assets ) ;
673+ if ( this . applyPluginsBailResult ( "need-additional-seal" ) ) {
674+ this . unseal ( ) ;
675+ return this . seal ( callback ) ;
679676 }
680- return self . applyPluginsAsync ( "after-seal" , callback ) ;
677+ return this . applyPluginsAsync ( "after-seal" , callback ) ;
681678 } ) ;
682679 } ) ;
683680 } ) ;
684681 } ) ;
685682 }
686683
687684 sortModules ( modules ) {
688- modules . sort ( ( a , b ) => {
689- if ( a . index < b . index ) return - 1 ;
690- if ( a . index > b . index ) return 1 ;
691- return 0 ;
692- } ) ;
685+ modules . sort ( byId ) ;
693686 }
694687
695688 reportDependencyErrorsAndWarnings ( module , blocks ) {
@@ -1097,9 +1090,9 @@ class Compilation extends Tapable {
10971090 }
10981091
10991092 applyModuleIds ( ) {
1100- let unusedIds = [ ] ;
1093+ const unusedIds = [ ] ;
11011094 let nextFreeModuleId = 0 ;
1102- let usedIds = [ ] ;
1095+ const usedIds = [ ] ;
11031096 // TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
11041097 const usedIdMap = Object . create ( null ) ;
11051098 if ( this . usedModuleIds ) {
@@ -1218,14 +1211,12 @@ class Compilation extends Tapable {
12181211 sortItemsWithChunkIds ( ) {
12191212 this . chunks . sort ( byId ) ;
12201213
1221- const modules = this . modules ;
1222- for ( let indexModule = 0 ; indexModule < modules . length ; indexModule ++ ) {
1223- modules [ indexModule ] . sortItems ( true ) ;
1214+ for ( let indexModule = 0 ; indexModule < this . modules . length ; indexModule ++ ) {
1215+ this . modules [ indexModule ] . sortItems ( true ) ;
12241216 }
12251217
1226- const chunks = this . chunks ;
1227- for ( let indexChunk = 0 ; indexChunk < chunks . length ; indexChunk ++ ) {
1228- chunks [ indexChunk ] . sortItems ( ) ;
1218+ for ( let indexChunk = 0 ; indexChunk < this . chunks . length ; indexChunk ++ ) {
1219+ this . chunks [ indexChunk ] . sortItems ( ) ;
12291220 }
12301221
12311222 const byMessage = ( a , b ) => {
@@ -1253,18 +1244,16 @@ class Compilation extends Tapable {
12531244 this . contextDependencies = [ ] ;
12541245 this . missingDependencies = [ ] ;
12551246
1256- const children = this . children ;
1257- for ( let indexChildren = 0 ; indexChildren < children . length ; indexChildren ++ ) {
1258- const child = children [ indexChildren ] ;
1247+ for ( let indexChildren = 0 ; indexChildren < this . children . length ; indexChildren ++ ) {
1248+ const child = this . children [ indexChildren ] ;
12591249
12601250 this . fileDependencies = this . fileDependencies . concat ( child . fileDependencies ) ;
12611251 this . contextDependencies = this . contextDependencies . concat ( child . contextDependencies ) ;
12621252 this . missingDependencies = this . missingDependencies . concat ( child . missingDependencies ) ;
12631253 }
12641254
1265- const modules = this . modules ;
1266- for ( let indexModule = 0 ; indexModule < modules . length ; indexModule ++ ) {
1267- const module = modules [ indexModule ] ;
1255+ for ( let indexModule = 0 ; indexModule < this . modules . length ; indexModule ++ ) {
1256+ const module = this . modules [ indexModule ] ;
12681257
12691258 if ( module . fileDependencies ) {
12701259 const fileDependencies = module . fileDependencies ;
0 commit comments