Skip to content

Commit 68c76b3

Browse files
authored
Merge pull request webpack#3850 from ritikrishu/refactor-AsyncDependenciesBlock-to-es6-syntax
refactor AsyncDependenciesBlock to es6 syntax
2 parents 5b47228 + 486ffb8 commit 68c76b3

1 file changed

Lines changed: 47 additions & 56 deletions

File tree

‎lib/AsyncDependenciesBlock.js‎

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,52 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var DependenciesBlock = require("./DependenciesBlock");
6-
7-
function AsyncDependenciesBlock(name, module, loc) {
8-
DependenciesBlock.call(this);
9-
this.chunkName = name;
10-
this.chunks = null;
11-
this.module = module;
12-
this.loc = loc;
13-
14-
Object.defineProperty(this, "chunk", {
15-
get: function() {
16-
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
17-
},
18-
set: function() {
19-
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
5+
"use strict";
6+
const DependenciesBlock = require("./DependenciesBlock");
7+
8+
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
9+
constructor(name, module, loc) {
10+
super();
11+
this.chunkName = name;
12+
this.chunks = null;
13+
this.module = module;
14+
this.loc = loc;
15+
}
16+
get chunk() {
17+
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
18+
}
19+
set chunk(chunk) {
20+
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
21+
}
22+
updateHash(hash) {
23+
hash.update(this.chunkName || "");
24+
hash.update(this.chunks && this.chunks.map((chunk) => {
25+
return typeof chunk.id === "number" ? chunk.id : "";
26+
}).join(",") || "");
27+
super.updateHash(hash);
28+
}
29+
disconnect() {
30+
this.chunks = null;
31+
super.disconnect();
32+
}
33+
unseal() {
34+
this.chunks = null;
35+
super.unseal();
36+
}
37+
sortItems() {
38+
super.sortItems();
39+
if(this.chunks) {
40+
this.chunks.sort((a, b) => {
41+
let i = 0;
42+
while(true) { // eslint-disable-line no-constant-condition
43+
if(!a.modules[i] && !b.modules[i]) return 0;
44+
if(!a.modules[i]) return -1;
45+
if(!b.modules[i]) return 1;
46+
if(a.modules[i].id > b.modules[i].id) return 1;
47+
if(a.modules[i].id < b.modules[i].id) return -1;
48+
i++;
49+
}
50+
});
2051
}
21-
});
22-
23-
}
24-
module.exports = AsyncDependenciesBlock;
25-
26-
AsyncDependenciesBlock.prototype = Object.create(DependenciesBlock.prototype);
27-
AsyncDependenciesBlock.prototype.constructor = AsyncDependenciesBlock;
28-
29-
AsyncDependenciesBlock.prototype.updateHash = function updateHash(hash) {
30-
hash.update(this.chunkName || "");
31-
hash.update(this.chunks && this.chunks.map(function(chunk) {
32-
return typeof chunk.id === "number" ? chunk.id : "";
33-
}).join(",") || "");
34-
DependenciesBlock.prototype.updateHash.call(this, hash);
35-
};
36-
37-
AsyncDependenciesBlock.prototype.disconnect = function() {
38-
this.chunks = null;
39-
DependenciesBlock.prototype.disconnect.call(this);
40-
};
41-
42-
AsyncDependenciesBlock.prototype.unseal = function() {
43-
this.chunks = null;
44-
DependenciesBlock.prototype.unseal.call(this);
45-
};
46-
47-
AsyncDependenciesBlock.prototype.sortItems = function() {
48-
DependenciesBlock.prototype.sortItems.call(this);
49-
if(this.chunks) {
50-
this.chunks.sort(function(a, b) {
51-
var i = 0;
52-
while(true) { // eslint-disable-line no-constant-condition
53-
if(!a.modules[i] && !b.modules[i]) return 0;
54-
if(!a.modules[i]) return -1;
55-
if(!b.modules[i]) return 1;
56-
if(a.modules[i].id > b.modules[i].id) return 1;
57-
if(a.modules[i].id < b.modules[i].id) return -1;
58-
i++;
59-
}
60-
});
6152
}
62-
};
53+
}

0 commit comments

Comments
 (0)