From af13334f6379ac53c4bb608c8e5d302fd5ad4e31 Mon Sep 17 00:00:00 2001 From: Kyle Truong Date: Mon, 19 Jun 2017 21:18:17 -0400 Subject: [PATCH] Issue #4099: ES6 Refactor for depdendencies/DepBlockHelpers.js --- lib/dependencies/DepBlockHelpers.js | 32 +++++++++++------------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/dependencies/DepBlockHelpers.js b/lib/dependencies/DepBlockHelpers.js index 9a89c6780a5..b6228bfc3d6 100644 --- a/lib/dependencies/DepBlockHelpers.js +++ b/lib/dependencies/DepBlockHelpers.js @@ -2,35 +2,27 @@ 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(); })"; @@ -38,5 +30,5 @@ DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestSh function asComment(str) { if(!str) return ""; - return "/* " + str + " */"; + return `/* ${str} */`; }