Skip to content

Commit

Permalink
Issue #4099: ES6 Refactor for depdendencies/DepBlockHelpers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KTruong008 authored and Kyle Truong committed Jul 1, 2017
1 parent 6199454 commit af13334
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lib/dependencies/DepBlockHelpers.js
Expand Up @@ -2,41 +2,33 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var DepBlockHelpers = exports;
"use strict";

DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, requestShortener, name) {
var promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
const DepBlockHelpers = exports;

DepBlockHelpers.getLoadDepBlockWrapper = (depBlock, outputOptions, requestShortener, name) => {
const promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
return [
promiseCode + ".then(",
`${promiseCode}.then(`,
").catch(",
")"
];
};

DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestShortener, name) {
DepBlockHelpers.getDepBlockPromise = (depBlock, outputOptions, requestShortener, name) => {
if(depBlock.chunks) {
var chunks = depBlock.chunks.filter(function(chunk) {
return !chunk.hasRuntime() && chunk.id !== null;
});
const chunks = depBlock.chunks.filter(chunk => !chunk.hasRuntime() && chunk.id !== null);
if(chunks.length === 1) {
var chunk = chunks[0];
return "__webpack_require__.e" + asComment(name) + "(" + JSON.stringify(chunk.id) + "" +
(outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
asComment(depBlock.chunkReason) + ")";
const chunk = chunks[0];
return `__webpack_require__.e${asComment(name)}(${JSON.stringify(chunk.id)}${outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : ""}${asComment(depBlock.chunkReason)})`;
} else if(chunks.length > 0) {
return "Promise.all" + asComment(name) + "(" +
(outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
"[" +
chunks.map(function(chunk) {
return "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
}).join(", ") +
"])";
return `Promise.all${asComment(name)}(${outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : ""}[${chunks.map(chunk => "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")").join(", ")}])`;
}
}
return "new Promise(function(resolve) { resolve(); })";
};

function asComment(str) {
if(!str) return "";
return "/* " + str + " */";
return `/* ${str} */`;
}

0 comments on commit af13334

Please sign in to comment.