@@ -20,6 +20,10 @@ function byId(a, b) {
2020 return a . id - b . id ;
2121}
2222
23+ function byDebugId ( a , b ) {
24+ return a . debugId - b . debugId ;
25+ }
26+
2327let debugId = 1000 ;
2428
2529class Module extends DependenciesBlock {
@@ -39,6 +43,7 @@ class Module extends DependenciesBlock {
3943 this . providedExports = null ;
4044 this . _chunks = new Set ( ) ;
4145 this . _chunksIsSorted = true ;
46+ this . _chunksIsSortedByDebugId = true ;
4247 this . _chunksDebugIdent = undefined ;
4348 this . warnings = [ ] ;
4449 this . dependenciesWarnings = [ ] ;
@@ -60,7 +65,7 @@ class Module extends DependenciesBlock {
6065 this . providedExports = null ;
6166 this . _chunks . clear ( ) ;
6267 this . _chunksDebugIdent = undefined ;
63- this . _chunksIsSorted = false ;
68+ this . _chunksIsSorted = this . _chunksIsSortedByDebugId = false ;
6469 super . disconnect ( ) ;
6570 }
6671
@@ -72,14 +77,14 @@ class Module extends DependenciesBlock {
7277 this . depth = null ;
7378 this . _chunks . clear ( ) ;
7479 this . _chunksDebugIdent = undefined ;
75- this . _chunksIsSorted = false ;
80+ this . _chunksIsSorted = this . _chunksIsSortedByDebugId = false ;
7681 super . unseal ( ) ;
7782 }
7883
7984 addChunk ( chunk ) {
8085 this . _chunks . add ( chunk ) ;
8186 this . _chunksDebugIdent = undefined ;
82- this . _chunksIsSorted = false ;
87+ this . _chunksIsSorted = this . _chunksIsSortedByDebugId = false ;
8388 }
8489
8590 removeChunk ( chunk ) {
@@ -97,7 +102,7 @@ class Module extends DependenciesBlock {
97102
98103 getChunkIdsIdent ( ) {
99104 if ( this . _chunksDebugIdent !== undefined ) return this . _chunksDebugIdent ;
100- this . _ensureChunksSorted ( ) ;
105+ this . _ensureChunksSortedByDebugId ( ) ;
101106 const chunks = this . _chunks ;
102107 const list = [ ] ;
103108 for ( let chunk of chunks ) {
@@ -135,9 +140,17 @@ class Module extends DependenciesBlock {
135140 _ensureChunksSorted ( ) {
136141 if ( this . _chunksIsSorted ) return ;
137142 this . _chunks = new Set ( Array . from ( this . _chunks ) . sort ( byId ) ) ;
143+ this . _chunksIsSortedByDebugId = false ;
138144 this . _chunksIsSorted = true ;
139145 }
140146
147+ _ensureChunksSortedByDebugId ( ) {
148+ if ( this . _chunksIsSortedByDebugId ) return ;
149+ this . _chunks = new Set ( Array . from ( this . _chunks ) . sort ( byDebugId ) ) ;
150+ this . _chunksIsSorted = false ;
151+ this . _chunksIsSortedByDebugId = true ;
152+ }
153+
141154 addReason ( module , dependency ) {
142155 this . reasons . push ( new ModuleReason ( module , dependency ) ) ;
143156 }
@@ -211,9 +224,10 @@ class Module extends DependenciesBlock {
211224 super . updateHash ( hash ) ;
212225 }
213226
214- sortItems ( ) {
227+ sortItems ( sortChunks ) {
215228 super . sortItems ( ) ;
216- this . _ensureChunksSorted ( ) ;
229+ if ( sortChunks )
230+ this . _ensureChunksSorted ( ) ;
217231 this . reasons . sort ( ( a , b ) => byId ( a . module , b . module ) ) ;
218232 }
219233
0 commit comments