Refactor: string concatenation to template literals

This commit is contained in:
Anatoliy Yastreb 2017-06-20 14:40:27 +09:00
parent cd2f022d43
commit ce24a7be67
1 changed files with 11 additions and 18 deletions

View File

@ -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)