File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ function byId(a, b) {
3232 return 0 ;
3333}
3434
35+ const byIndex = ( a , b ) => {
36+ if ( a . index < b . index ) return - 1 ;
37+ if ( a . index > b . index ) return 1 ;
38+ return 0 ;
39+ } ;
40+
3541function iterationBlockVariable ( variables , fn ) {
3642 for ( let indexVariable = 0 ; indexVariable < variables . length ; indexVariable ++ ) {
3743 const varDep = variables [ indexVariable ] . dependencies ;
@@ -682,7 +688,7 @@ class Compilation extends Tapable {
682688 }
683689
684690 sortModules ( modules ) {
685- modules . sort ( byId ) ;
691+ modules . sort ( byIndex ) ;
686692 }
687693
688694 reportDependencyErrorsAndWarnings ( module , blocks ) {
Original file line number Diff line number Diff line change 1+ /* globals describe, it */
2+ "use strict" ;
3+
4+ const should = require ( "should" ) ;
5+ const sinon = require ( "sinon" ) ;
6+
7+ const Compilation = require ( "../lib/Compilation" ) ;
8+
9+ describe ( "Compilation" , ( ) => {
10+ describe ( 'sortModules' , ( ) => {
11+ it ( 'should sort modules by index' , ( ) => {
12+ let modules = [
13+ { index : 5 } ,
14+ { index : 4 } ,
15+ { index : 8 } ,
16+ { index : 1 } ,
17+ ] ;
18+
19+ Compilation . prototype . sortModules ( modules ) ;
20+ modules . should . match ( [
21+ { index : 1 } ,
22+ { index : 4 } ,
23+ { index : 5 } ,
24+ { index : 8 } ,
25+ ] ) ;
26+ } ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments