Skip to content

Commit ce24a7b

Browse files
committed
Refactor: string concatenation to template literals
1 parent cd2f022 commit ce24a7b

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

‎lib/webworker/WebWorkerMainTemplatePlugin.js‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class WebWorkerMainTemplatePlugin {
1717
"// \"1\" means \"already loaded\"",
1818
"var installedChunks = {",
1919
this.indent(
20-
chunk.ids.map(function(id) {
21-
return id + ": 1";
22-
}).join(",\n")
20+
chunk.ids.map((id) => `${id}: 1`).join(",\n")
2321
),
2422
"};"
2523
]);
@@ -36,10 +34,8 @@ class WebWorkerMainTemplatePlugin {
3634
this.indent([
3735
"importScripts(" +
3836
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
39-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
40-
hashWithLength: function(length) {
41-
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
42-
}.bind(this),
37+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
38+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
4339
chunk: {
4440
id: "\" + chunkId + \""
4541
}
@@ -56,7 +52,7 @@ class WebWorkerMainTemplatePlugin {
5652
const chunkCallbackName = this.outputOptions.chunkCallbackName || Template.toIdentifier("webpackChunk" + (this.outputOptions.library || ""));
5753
return this.asString([
5854
source,
59-
"this[" + JSON.stringify(chunkCallbackName) + "] = function webpackChunkCallback(chunkIds, moreModules) {",
55+
`this[${JSON.stringify(chunkCallbackName)}] = function webpackChunkCallback(chunkIds, moreModules) {`,
6056
this.indent([
6157
"for(var moduleId in moreModules) {",
6258
this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
@@ -74,24 +70,21 @@ class WebWorkerMainTemplatePlugin {
7470
const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
7571
const hotUpdateFunction = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || ""));
7672
const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
77-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
78-
hashWithLength: function(length) {
79-
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
80-
}.bind(this),
73+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
74+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
8175
chunk: {
8276
id: "\" + chunkId + \""
8377
}
8478
});
8579
const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
86-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
87-
hashWithLength: function(length) {
88-
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
89-
}.bind(this)
80+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
81+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
9082
});
9183

9284
return source + "\n" +
93-
"var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" +
94-
"this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js"))
85+
`var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];\n` +
86+
`this[${JSON.stringify(hotUpdateFunction)}] = ` +
87+
Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js"))
9588
.replace(/\/\/\$semicolon/g, ";")
9689
.replace(/\$require\$/g, this.requireFn)
9790
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)

0 commit comments

Comments
 (0)