Skip to content

Commit 42cdfed

Browse files
authored
Merge pull request webpack#5098 from KTruong888/4099_es6_refactor_dep_depblockhelpers
Issue webpack#4099: ES6 Refactor for depdendencies/DepBlockHelpers.js
2 parents 53944e8 + 98951d1 commit 42cdfed

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

lib/dependencies/DepBlockHelpers.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,38 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var DepBlockHelpers = exports;
5+
"use strict";
66

7-
DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, requestShortener, name) {
8-
var promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
7+
const DepBlockHelpers = exports;
8+
9+
DepBlockHelpers.getLoadDepBlockWrapper = (depBlock, outputOptions, requestShortener, name) => {
10+
const promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
911
return [
1012
promiseCode + ".then(",
1113
").catch(",
1214
")"
1315
];
1416
};
1517

16-
DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestShortener, name) {
18+
DepBlockHelpers.getDepBlockPromise = (depBlock, outputOptions, requestShortener, name) => {
1719
if(depBlock.chunks) {
18-
var chunks = depBlock.chunks.filter(function(chunk) {
19-
return !chunk.hasRuntime() && chunk.id !== null;
20-
});
20+
const chunks = depBlock.chunks.filter(chunk => !chunk.hasRuntime() && chunk.id !== null);
21+
const pathChunkCheck = outputOptions.pathinfo && depBlock.chunkName;
22+
const shortChunkName = requestShortener.shorten(depBlock.chunkName);
23+
const chunkReason = asComment(depBlock.chunkReason);
24+
const requireChunkId = chunk => "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
25+
name = asComment(name);
2126
if(chunks.length === 1) {
22-
var chunk = chunks[0];
23-
return "__webpack_require__.e" + asComment(name) + "(" + JSON.stringify(chunk.id) + "" +
24-
(outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
25-
asComment(depBlock.chunkReason) + ")";
27+
const chunkId = JSON.stringify(chunks[0].id);
28+
return `__webpack_require__.e${name}(${chunkId}${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}${chunkReason})`;
2629
} else if(chunks.length > 0) {
27-
return "Promise.all" + asComment(name) + "(" +
28-
(outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
29-
"[" +
30-
chunks.map(function(chunk) {
31-
return "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
32-
}).join(", ") +
33-
"])";
30+
return `Promise.all${name}(${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}[${chunks.map(requireChunkId).join(", ")}])`;
3431
}
3532
}
3633
return "new Promise(function(resolve) { resolve(); })";
3734
};
3835

3936
function asComment(str) {
4037
if(!str) return "";
41-
return "/* " + str + " */";
38+
return `/* ${str} */`;
4239
}

0 commit comments

Comments
 (0)