@@ -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,8 @@ 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 || { } ;
304+
306305 const time = Date . now ( ) - start ;
307306 if ( ! module . profile . dependencies || time > module . profile . dependencies ) {
308307 module . profile . dependencies = time ;
@@ -572,124 +571,119 @@ class Compilation extends Tapable {
572571 }
573572
574573 seal ( callback ) {
575- const self = this ;
576- self . applyPlugins0 ( "seal" ) ;
577- self . nextFreeModuleIndex = 0 ;
578- self . nextFreeModuleIndex2 = 0 ;
579- self . preparedChunks . forEach ( preparedChunk => {
574+ this . applyPlugins0 ( "seal" ) ;
575+ this . nextFreeModuleIndex = 0 ;
576+ this . nextFreeModuleIndex2 = 0 ;
577+ this . preparedChunks . forEach ( preparedChunk => {
580578 const module = preparedChunk . module ;
581- const chunk = self . addChunk ( preparedChunk . name , module ) ;
582- const entrypoint = self . entrypoints [ chunk . name ] = new Entrypoint ( chunk . name ) ;
579+ const chunk = this . addChunk ( preparedChunk . name , module ) ;
580+ const entrypoint = this . entrypoints [ chunk . name ] = new Entrypoint ( chunk . name ) ;
583581 entrypoint . unshiftChunk ( chunk ) ;
584582
585583 chunk . addModule ( module ) ;
586584 module . addChunk ( chunk ) ;
587585 chunk . entryModule = module ;
588- self . assignIndex ( module ) ;
589- self . assignDepth ( module ) ;
586+ this . assignIndex ( module ) ;
587+ this . assignDepth ( module ) ;
590588 } ) ;
591- self . processDependenciesBlocksForChunks ( self . chunks . slice ( ) ) ;
592- self . sortModules ( self . modules ) ;
593- self . applyPlugins0 ( "optimize" ) ;
589+ this . processDependenciesBlocksForChunks ( this . chunks . slice ( ) ) ;
590+ this . sortModules ( this . modules ) ;
591+ this . applyPlugins0 ( "optimize" ) ;
594592
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 ) ;
593+ while ( this . applyPluginsBailResult1 ( "optimize-modules-basic" , this . modules ) ||
594+ this . applyPluginsBailResult1 ( "optimize-modules" , this . modules ) ||
595+ this . applyPluginsBailResult1 ( "optimize-modules-advanced" , this . modules ) ) { /* empty */ }
596+ this . applyPlugins1 ( "after-optimize-modules" , this . modules ) ;
599597
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 ) ;
598+ while ( this . applyPluginsBailResult1 ( "optimize-chunks-basic" , this . chunks ) ||
599+ this . applyPluginsBailResult1 ( "optimize-chunks" , this . chunks ) ||
600+ this . applyPluginsBailResult1 ( "optimize-chunks-advanced" , this . chunks ) ) { /* empty */ }
601+ this . applyPlugins1 ( "after-optimize-chunks" , this . chunks ) ;
604602
605- self . applyPluginsAsyncSeries ( "optimize-tree" , self . chunks , self . modules , function sealPart2 ( err ) {
603+ this . applyPluginsAsyncSeries ( "optimize-tree" , this . chunks , this . modules , ( err ) => {
606604 if ( err ) {
607605 return callback ( err ) ;
608606 }
609607
610- self . applyPlugins2 ( "after-optimize-tree" , self . chunks , self . modules ) ;
608+ this . applyPlugins2 ( "after-optimize-tree" , this . chunks , this . modules ) ;
611609
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 ) ;
610+ while ( this . applyPluginsBailResult ( "optimize-chunk-modules-basic" , this . chunks , this . modules ) ||
611+ this . applyPluginsBailResult ( "optimize-chunk-modules" , this . chunks , this . modules ) ||
612+ this . applyPluginsBailResult ( "optimize-chunk-modules-advanced" , this . chunks , this . modules ) ) { /* empty */ }
613+ this . applyPlugins2 ( "after-optimize-chunk-modules" , this . chunks , this . modules ) ;
616614
617- const shouldRecord = self . applyPluginsBailResult ( "should-record" ) !== false ;
615+ const shouldRecord = this . applyPluginsBailResult ( "should-record" ) !== false ;
618616
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 ) ;
617+ this . applyPlugins2 ( "revive-modules" , this . modules , this . records ) ;
618+ this . applyPlugins1 ( "optimize-module-order" , this . modules ) ;
619+ this . applyPlugins1 ( "advanced-optimize-module-order" , this . modules ) ;
620+ this . applyPlugins1 ( "before-module-ids" , this . modules ) ;
621+ this . applyPlugins1 ( "module-ids" , this . modules ) ;
622+ this . applyModuleIds ( ) ;
623+ this . applyPlugins1 ( "optimize-module-ids" , this . modules ) ;
624+ this . applyPlugins1 ( "after-optimize-module-ids" , this . modules ) ;
627625
628- self . sortItemsWithModuleIds ( ) ;
626+ this . sortItemsWithModuleIds ( ) ;
629627
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 ) ;
628+ this . applyPlugins2 ( "revive-chunks" , this . chunks , this . records ) ;
629+ this . applyPlugins1 ( "optimize-chunk-order" , this . chunks ) ;
630+ this . applyPlugins1 ( "before-chunk-ids" , this . chunks ) ;
631+ this . applyChunkIds ( ) ;
632+ this . applyPlugins1 ( "optimize-chunk-ids" , this . chunks ) ;
633+ this . applyPlugins1 ( "after-optimize-chunk-ids" , this . chunks ) ;
636634
637- self . sortItemsWithChunkIds ( ) ;
635+ this . sortItemsWithChunkIds ( ) ;
638636
639637 if ( shouldRecord )
640- self . applyPlugins2 ( "record-modules" , self . modules , self . records ) ;
638+ this . applyPlugins2 ( "record-modules" , this . modules , this . records ) ;
641639 if ( shouldRecord )
642- self . applyPlugins2 ( "record-chunks" , self . chunks , self . records ) ;
640+ this . applyPlugins2 ( "record-chunks" , this . chunks , this . records ) ;
643641
644- self . applyPlugins0 ( "before-hash" ) ;
645- self . createHash ( ) ;
646- self . applyPlugins0 ( "after-hash" ) ;
642+ this . applyPlugins0 ( "before-hash" ) ;
643+ this . createHash ( ) ;
644+ this . applyPlugins0 ( "after-hash" ) ;
647645
648646 if ( shouldRecord )
649- self . applyPlugins1 ( "record-hash" , self . records ) ;
647+ this . applyPlugins1 ( "record-hash" , this . records ) ;
650648
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 ( ) ;
649+ this . applyPlugins0 ( "before-module-assets" ) ;
650+ this . createModuleAssets ( ) ;
651+ if ( this . applyPluginsBailResult ( "should-generate-chunk-assets" ) !== false ) {
652+ this . applyPlugins0 ( "before-chunk-assets" ) ;
653+ this . createChunkAssets ( ) ;
656654 }
657- self . applyPlugins1 ( "additional-chunk-assets" , self . chunks ) ;
658- self . summarizeDependencies ( ) ;
655+ this . applyPlugins1 ( "additional-chunk-assets" , this . chunks ) ;
656+ this . summarizeDependencies ( ) ;
659657 if ( shouldRecord )
660- self . applyPlugins2 ( "record" , self , self . records ) ;
658+ this . applyPlugins2 ( "record" , this , this . records ) ;
661659
662- self . applyPluginsAsync ( "additional-assets" , err => {
660+ this . applyPluginsAsync ( "additional-assets" , err => {
663661 if ( err ) {
664662 return callback ( err ) ;
665663 }
666- self . applyPluginsAsync ( "optimize-chunk-assets" , self . chunks , err => {
664+ this . applyPluginsAsync ( "optimize-chunk-assets" , this . chunks , err => {
667665 if ( err ) {
668666 return callback ( err ) ;
669667 }
670- self . applyPlugins1 ( "after-optimize-chunk-assets" , self . chunks ) ;
671- self . applyPluginsAsync ( "optimize-assets" , self . assets , err => {
668+ this . applyPlugins1 ( "after-optimize-chunk-assets" , this . chunks ) ;
669+ this . applyPluginsAsync ( "optimize-assets" , this . assets , err => {
672670 if ( err ) {
673671 return callback ( err ) ;
674672 }
675- self . applyPlugins1 ( "after-optimize-assets" , self . assets ) ;
676- if ( self . applyPluginsBailResult ( "need-additional-seal" ) ) {
677- self . unseal ( ) ;
678- return self . seal ( callback ) ;
673+ this . applyPlugins1 ( "after-optimize-assets" , this . assets ) ;
674+ if ( this . applyPluginsBailResult ( "need-additional-seal" ) ) {
675+ this . unseal ( ) ;
676+ return this . seal ( callback ) ;
679677 }
680- return self . applyPluginsAsync ( "after-seal" , callback ) ;
678+ return this . applyPluginsAsync ( "after-seal" , callback ) ;
681679 } ) ;
682680 } ) ;
683681 } ) ;
684682 } ) ;
685683 }
686684
687685 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- } ) ;
686+ modules . sort ( byId ) ;
693687 }
694688
695689 reportDependencyErrorsAndWarnings ( module , blocks ) {
@@ -1097,9 +1091,9 @@ class Compilation extends Tapable {
10971091 }
10981092
10991093 applyModuleIds ( ) {
1100- let unusedIds = [ ] ;
1094+ const unusedIds = [ ] ;
11011095 let nextFreeModuleId = 0 ;
1102- let usedIds = [ ] ;
1096+ const usedIds = [ ] ;
11031097 // TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
11041098 const usedIdMap = Object . create ( null ) ;
11051099 if ( this . usedModuleIds ) {
@@ -1218,14 +1212,12 @@ class Compilation extends Tapable {
12181212 sortItemsWithChunkIds ( ) {
12191213 this . chunks . sort ( byId ) ;
12201214
1221- const modules = this . modules ;
1222- for ( let indexModule = 0 ; indexModule < modules . length ; indexModule ++ ) {
1223- modules [ indexModule ] . sortItems ( true ) ;
1215+ for ( let indexModule = 0 ; indexModule < this . modules . length ; indexModule ++ ) {
1216+ this . modules [ indexModule ] . sortItems ( true ) ;
12241217 }
12251218
1226- const chunks = this . chunks ;
1227- for ( let indexChunk = 0 ; indexChunk < chunks . length ; indexChunk ++ ) {
1228- chunks [ indexChunk ] . sortItems ( ) ;
1219+ for ( let indexChunk = 0 ; indexChunk < this . chunks . length ; indexChunk ++ ) {
1220+ this . chunks [ indexChunk ] . sortItems ( ) ;
12291221 }
12301222
12311223 const byMessage = ( a , b ) => {
@@ -1253,18 +1245,16 @@ class Compilation extends Tapable {
12531245 this . contextDependencies = [ ] ;
12541246 this . missingDependencies = [ ] ;
12551247
1256- const children = this . children ;
1257- for ( let indexChildren = 0 ; indexChildren < children . length ; indexChildren ++ ) {
1258- const child = children [ indexChildren ] ;
1248+ for ( let indexChildren = 0 ; indexChildren < this . children . length ; indexChildren ++ ) {
1249+ const child = this . children [ indexChildren ] ;
12591250
12601251 this . fileDependencies = this . fileDependencies . concat ( child . fileDependencies ) ;
12611252 this . contextDependencies = this . contextDependencies . concat ( child . contextDependencies ) ;
12621253 this . missingDependencies = this . missingDependencies . concat ( child . missingDependencies ) ;
12631254 }
12641255
1265- const modules = this . modules ;
1266- for ( let indexModule = 0 ; indexModule < modules . length ; indexModule ++ ) {
1267- const module = modules [ indexModule ] ;
1256+ for ( let indexModule = 0 ; indexModule < this . modules . length ; indexModule ++ ) {
1257+ const module = this . modules [ indexModule ] ;
12681258
12691259 if ( module . fileDependencies ) {
12701260 const fileDependencies = module . fileDependencies ;
0 commit comments