Skip to content

Commit 074cff8

Browse files
authored
Merge pull request webpack#7216 from jordwest/webpack-3
Fix regression in Compilation.sortModules
2 parents 645400a + 552d05e commit 074cff8

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/Compilation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
3541
function 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) {

test/Compilation.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
});

0 commit comments

Comments
 (0)