File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-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+ function 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+ } ,
15+ {
16+ index : 4
17+ } ,
18+ {
19+ index : 8
20+ } ,
21+ {
22+ index : 1
23+ } ,
24+ ] ;
25+
26+ Compilation . prototype . sortModules ( modules ) ;
27+ modules . should . match ( [ {
28+ index : 1
29+ } ,
30+ {
31+ index : 4
32+ } ,
33+ {
34+ index : 5
35+ } ,
36+ {
37+ index : 8
38+ } ,
39+ ] ) ;
40+ } ) ;
41+ } ) ;
42+ } ) ;
You can’t perform that action at this time.
0 commit comments