From ce24a7be67cbcc2781796f43498a4bd3f1f398f1 Mon Sep 17 00:00:00 2001 From: Anatoliy Yastreb Date: Tue, 20 Jun 2017 14:40:27 +0900 Subject: [PATCH] Refactor: string concatenation to template literals --- lib/webworker/WebWorkerMainTemplatePlugin.js | 29 ++++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/webworker/WebWorkerMainTemplatePlugin.js b/lib/webworker/WebWorkerMainTemplatePlugin.js index a794745d4c6..ce9615569c6 100644 --- a/lib/webworker/WebWorkerMainTemplatePlugin.js +++ b/lib/webworker/WebWorkerMainTemplatePlugin.js @@ -17,9 +17,7 @@ class WebWorkerMainTemplatePlugin { "// \"1\" means \"already loaded\"", "var installedChunks = {", this.indent( - chunk.ids.map(function(id) { - return id + ": 1"; - }).join(",\n") + chunk.ids.map((id) => `${id}: 1`).join(",\n") ), "};" ]); @@ -36,10 +34,8 @@ class WebWorkerMainTemplatePlugin { this.indent([ "importScripts(" + this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), { - hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", - hashWithLength: function(length) { - return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; - }.bind(this), + hash: `" + ${this.renderCurrentHashCode(hash)} + "`, + hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`, chunk: { id: "\" + chunkId + \"" } @@ -56,7 +52,7 @@ class WebWorkerMainTemplatePlugin { const chunkCallbackName = this.outputOptions.chunkCallbackName || Template.toIdentifier("webpackChunk" + (this.outputOptions.library || "")); return this.asString([ source, - "this[" + JSON.stringify(chunkCallbackName) + "] = function webpackChunkCallback(chunkIds, moreModules) {", + `this[${JSON.stringify(chunkCallbackName)}] = function webpackChunkCallback(chunkIds, moreModules) {`, this.indent([ "for(var moduleId in moreModules) {", this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")), @@ -74,24 +70,21 @@ class WebWorkerMainTemplatePlugin { const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename; const hotUpdateFunction = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || "")); const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), { - hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", - hashWithLength: function(length) { - return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; - }.bind(this), + hash: `" + ${this.renderCurrentHashCode(hash)} + "`, + hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`, chunk: { id: "\" + chunkId + \"" } }); const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), { - hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", - hashWithLength: function(length) { - return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; - }.bind(this) + hash: `" + ${this.renderCurrentHashCode(hash)} + "`, + hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`, }); return source + "\n" + - "var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" + - "this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js")) + `var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];\n` + + `this[${JSON.stringify(hotUpdateFunction)}] = ` + + Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js")) .replace(/\/\/\$semicolon/g, ";") .replace(/\$require\$/g, this.requireFn) .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)