Skip to content

Commit

Permalink
Refactor: string concatenation to template literals
Browse files Browse the repository at this point in the history
  • Loading branch information
ayastreb committed Jun 20, 2017
1 parent cd2f022 commit ce24a7b
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/webworker/WebWorkerMainTemplatePlugin.js
Expand Up @@ -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")
),
"};"
]);
Expand All @@ -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 + \""
}
Expand All @@ -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]")),
Expand All @@ -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)
Expand Down

0 comments on commit ce24a7b

Please sign in to comment.