Skip to content

Commit 2c32b08

Browse files
author
Ritik Rishu
committed
refactor AsyncDependenciesBlock to es6 syntax
1 parent 0607fc1 commit 2c32b08

1 file changed

Lines changed: 49 additions & 55 deletions

File tree

‎lib/AsyncDependenciesBlock.js‎

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,55 @@
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");
20-
}
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++;
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+
Object.defineProperty(this, "chunk", {
17+
get: function() {
18+
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
19+
},
20+
set: function() {
21+
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
5922
}
6023
});
6124
}
62-
};
25+
updateHash(hash) {
26+
hash.update(this.chunkName || "");
27+
hash.update(this.chunks && this.chunks.map((chunk) => {
28+
return typeof chunk.id === "number" ? chunk.id : "";
29+
}).join(",").replace(/,\s*$/, "") || "");
30+
super.updateHash(hash);
31+
}
32+
disconnect() {
33+
this.chunks = null;
34+
super.disconnect();
35+
}
36+
unseal() {
37+
this.chunks = null;
38+
super.unseal();
39+
}
40+
sortItems() {
41+
super.sortItems();
42+
if(this.chunks) {
43+
this.chunks.sort((a, b) => {
44+
let i = 0;
45+
while(true) { // eslint-disable-line no-constant-condition
46+
if(!a.modules[i] && !b.modules[i]) return 0;
47+
if(!a.modules[i]) return -1;
48+
if(!b.modules[i]) return 1;
49+
if(a.modules[i].id > b.modules[i].id) return 1;
50+
if(a.modules[i].id < b.modules[i].id) return -1;
51+
i++;
52+
}
53+
});
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)