Skip to content

Commit 1e906f1

Browse files
committed
apply review changes
1 parent c29f324 commit 1e906f1

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

lib/ContextModule.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const RawSource = require("webpack-sources").RawSource;
1010
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
1111

1212
class ContextModule extends Module {
13-
constructor(resolveDependencies, context, recursive, regExp, addon, async) {
13+
constructor(resolveDependencies, context, recursive, regExp, addon, isAsync) {
1414
super();
1515
this.resolveDependencies = resolveDependencies;
1616
this.context = context;
1717
this.recursive = recursive;
1818
this.regExp = regExp;
1919
this.addon = addon;
20-
this.async = !!async;
20+
this.async = !!isAsync;
2121
this.cacheable = true;
2222
this.contextDependencies = [context];
2323
this.built = false;
@@ -30,7 +30,7 @@ class ContextModule extends Module {
3030
}
3131

3232
contextify(context, request) {
33-
return request.split("!").map(function(subrequest) {
33+
return request.split("!").map(subrequest => {
3434
let rp = path.relative(context, subrequest);
3535
if(path.sep === "\\")
3636
rp = rp.replace(/\\/g, "/");
@@ -147,14 +147,14 @@ class ContextModule extends Module {
147147
}).reduce(function(map, dep) {
148148
map[dep.userRequest] = dep.module.id;
149149
return map;
150-
}, {});
150+
}, Object.create(null));
151151
return `var map = ${JSON.stringify(map, null, "\t")};
152152
function webpackContext(req) {
153153
return __webpack_require__(webpackContextResolve(req));
154154
};
155155
function webpackContextResolve(req) {
156156
var id = map[req];
157-
if(!(id + 1)) // check for number
157+
if(!(id + 1)) // check for number or string
158158
throw new Error("Cannot find module '" + req + "'.");
159159
return id;
160160
};
@@ -170,16 +170,14 @@ webpackContext.id = ${JSON.stringify(id)};`;
170170
let hasMultipleOrNoChunks = false;
171171
const map = blocks
172172
.filter(block => block.dependencies[0].module)
173-
.map(function(block) {
174-
return {
175-
dependency: block.dependencies[0],
176-
block: block,
177-
userRequest: block.dependencies[0].userRequest
178-
};
179-
}).sort(function(a, b) {
173+
.map((block) => ({
174+
dependency: block.dependencies[0],
175+
block: block,
176+
userRequest: block.dependencies[0].userRequest
177+
})).sort((a, b) => {
180178
if(a.userRequest === b.userRequest) return 0;
181179
return a.userRequest < b.userRequest ? -1 : 1;
182-
}).reduce(function(map, item) {
180+
}).reduce((map, item) => {
183181
const chunks = item.block.chunks || [];
184182
if(chunks.length !== 1) {
185183
hasMultipleOrNoChunks = true;
@@ -188,7 +186,7 @@ webpackContext.id = ${JSON.stringify(id)};`;
188186
.concat(chunks.map(chunk => chunk.id));
189187

190188
return map;
191-
}, {});
189+
}, Object.create(null));
192190

193191
const requestPrefix = hasMultipleOrNoChunks ?
194192
"Promise.all(ids.slice(1).map(__webpack_require__.e))" :
@@ -247,11 +245,11 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`;
247245

248246
size() {
249247
// base penalty
250-
let count = 160;
248+
const initialCount = 160;
251249

252250
// if we dont have dependencies we stop here.
253251
return this.dependencies
254-
.reduce((count, dependency) => count + 5 + dependency.userRequest.length, count);
252+
.reduce((count, dependency) => count + 5 + dependency.userRequest.length, initialCount);
255253
}
256254
}
257255

0 commit comments

Comments
 (0)