Skip to content

Commit 6993e14

Browse files
refactor(MultiModule): upgrade to ES6
1 parent 5dd1d0c commit 6993e14

1 file changed

Lines changed: 61 additions & 60 deletions

File tree

‎lib/MultiModule.js‎

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,74 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var Module = require("./Module");
6-
var RawSource = require("webpack-sources").RawSource;
5+
"use strict";
76

8-
function MultiModule(context, dependencies, name) {
9-
Module.call(this);
10-
this.context = context;
11-
this.dependencies = dependencies;
12-
this.name = name;
13-
this.built = false;
14-
this.cacheable = true;
15-
}
16-
module.exports = MultiModule;
7+
const Module = require("./Module");
8+
const RawSource = require("webpack-sources").RawSource;
9+
10+
class MultiModule extends Module {
1711

18-
MultiModule.prototype = Object.create(Module.prototype);
19-
MultiModule.prototype.constructor = MultiModule;
12+
constructor(context, dependencies, name) {
13+
super();
14+
this.context = context;
15+
this.dependencies = dependencies;
16+
this.name = name;
17+
this.built = false;
18+
this.cacheable = true;
19+
}
2020

21-
MultiModule.prototype.identifier = function() {
22-
return "multi " + this.dependencies.map((d) => d.request).join(" ");
23-
};
21+
identifier() {
22+
return `multi ${this.dependencies.map((d) => d.request).join(" ")}`;
23+
}
2424

25-
MultiModule.prototype.readableIdentifier = function(requestShortener) {
26-
return "multi " + this.dependencies.map((d) => {
27-
return requestShortener.shorten(d.request);
28-
}).join(" ");
29-
};
25+
readableIdentifier(requestShortener) {
26+
return `multi ${this.dependencies.map((d) => requestShortener.shorten(d.request)).join(" ")}`;
27+
}
3028

31-
MultiModule.prototype.disconnect = function disconnect() {
32-
this.built = false;
33-
Module.prototype.disconnect.call(this);
34-
};
29+
disconnect() {
30+
this.built = false;
31+
super.disconnect();
32+
}
3533

36-
MultiModule.prototype.build = function build(options, compilation, resolver, fs, callback) {
37-
this.built = true;
38-
return callback();
39-
};
34+
build(options, compilation, resolver, fs, callback) {
35+
this.built = true;
36+
return callback();
37+
}
4038

41-
MultiModule.prototype.source = function(dependencyTemplates, outputOptions) {
42-
var str = [];
43-
this.dependencies.forEach(function(dep, idx) {
44-
if(dep.module) {
45-
if(idx === this.dependencies.length - 1)
46-
str.push("module.exports = ");
47-
str.push("__webpack_require__(");
48-
if(outputOptions.pathinfo)
49-
str.push("/*! " + dep.request + " */");
50-
str.push("" + JSON.stringify(dep.module.id));
51-
str.push(")");
52-
} else {
53-
str.push("(function webpackMissingModule() { throw new Error(");
54-
str.push(JSON.stringify("Cannot find module \"" + dep.request + "\""));
55-
str.push("); }())");
56-
}
57-
str.push(";\n");
58-
}, this);
59-
return new RawSource(str.join(""));
60-
};
39+
needRebuild() {
40+
return false;
41+
}
6142

62-
MultiModule.prototype.needRebuild = function needRebuild() {
63-
return false;
64-
};
43+
size() {
44+
return 16 + this.dependencies.length * 12;
45+
}
6546

66-
MultiModule.prototype.size = function() {
67-
return 16 + this.dependencies.length * 12;
68-
};
47+
updateHash(hash) {
48+
hash.update("multi module");
49+
hash.update(this.name || "");
50+
super.updateHash(hash);
51+
}
6952

70-
MultiModule.prototype.updateHash = function(hash) {
71-
hash.update("multi module");
72-
hash.update(this.name || "");
73-
Module.prototype.updateHash.call(this, hash);
74-
};
53+
source(dependencyTemplates, outputOptions) {
54+
const str = [];
55+
this.dependencies.forEach(function(dep, idx) {
56+
if(dep.module) {
57+
if(idx === this.dependencies.length - 1)
58+
str.push("module.exports = ");
59+
str.push("__webpack_require__(");
60+
if(outputOptions.pathinfo)
61+
str.push(`/*! ${dep.request} */`);
62+
str.push(`${JSON.stringify(dep.module.id)}`);
63+
str.push(")");
64+
} else {
65+
str.push("(function webpackMissingModule() { throw new Error(");
66+
str.push(JSON.stringify(`Cannot find module "${dep.request}"`));
67+
str.push("); }())");
68+
}
69+
str.push(";\n");
70+
}, this);
71+
return new RawSource(str.join(""));
72+
}
73+
}
74+
75+
module.exports = MultiModule;

0 commit comments

Comments
 (0)