Skip to content

Commit 7f1d60d

Browse files
committed
Refactor: string concatenation to template literals
1 parent c84aa45 commit 7f1d60d

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

lib/node/NodeMainTemplatePlugin.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = class NodeMainTemplatePlugin {
2121
"// object to store loaded chunks",
2222
"// \"0\" means \"already loaded\"",
2323
"var installedChunks = {",
24-
this.indent(chunk.ids.map((id) => id + ": 0").join(",\n")),
24+
this.indent(chunk.ids.map((id) => `${id}: 0`).join(",\n")),
2525
"};"
2626
]);
2727
}
@@ -33,7 +33,7 @@ module.exports = class NodeMainTemplatePlugin {
3333
source,
3434
"",
3535
"// uncatched error handler for webpack runtime",
36-
this.requireFn + ".oe = function(err) {",
36+
`${this.requireFn}.oe = function(err) {`,
3737
this.indent([
3838
"process.nextTick(function() {",
3939
this.indent("throw err; // catch this error by using System.import().catch()"),
@@ -69,21 +69,21 @@ module.exports = class NodeMainTemplatePlugin {
6969
"var promise = new Promise(function(resolve, reject) {",
7070
this.indent([
7171
"installedChunks[chunkId] = [resolve, reject];",
72-
"var filename = __dirname + " + this.applyPluginsWaterfall("asset-path", JSON.stringify("/" + chunkFilename), {
73-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
74-
hashWithLength: (length) => "\" + " + this.renderCurrentHashCode(hash, length) + " + \"",
72+
"var filename = __dirname + " + this.applyPluginsWaterfall("asset-path", JSON.stringify(`/${chunkFilename}`), {
73+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
74+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + \"`,
7575
chunk: {
7676
id: "\" + chunkId + \"",
77-
hash: "\" + " + JSON.stringify(chunkMaps.hash) + "[chunkId] + \"",
77+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
7878
hashWithLength: (length) => {
7979
const shortChunkHashMap = {};
8080
Object.keys(chunkMaps.hash).forEach((chunkId) => {
8181
if(typeof chunkMaps.hash[chunkId] === "string")
8282
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
8383
});
84-
return "\" + " + JSON.stringify(shortChunkHashMap) + "[chunkId] + \"";
84+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
8585
},
86-
name: "\" + (" + JSON.stringify(chunkMaps.name) + "[chunkId]||chunkId) + \""
86+
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
8787
}
8888
}) + ";",
8989
"require('fs').readFile(filename, 'utf-8', function(err, content) {",
@@ -112,28 +112,28 @@ module.exports = class NodeMainTemplatePlugin {
112112
"return installedChunks[chunkId][2] = promise;"
113113
]);
114114
} else {
115-
const request = this.applyPluginsWaterfall("asset-path", JSON.stringify("./" + chunkFilename), {
116-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
117-
hashWithLength: (length) => "\" + " + this.renderCurrentHashCode(hash, length) + " + \"",
115+
const request = this.applyPluginsWaterfall("asset-path", JSON.stringify(`./${chunkFilename}`), {
116+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
117+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + \"`,
118118
chunk: {
119119
id: "\" + chunkId + \"",
120-
hash: "\" + " + JSON.stringify(chunkMaps.hash) + "[chunkId] + \"",
120+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
121121
hashWithLength: (length) => {
122122
const shortChunkHashMap = {};
123123
Object.keys(chunkMaps.hash).forEach((chunkId) => {
124124
if(typeof chunkMaps.hash[chunkId] === "string")
125125
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
126126
});
127-
return "\" + " + JSON.stringify(shortChunkHashMap) + "[chunkId] + \"";
127+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
128128
},
129-
name: "\" + (" + JSON.stringify(chunkMaps.name) + "[chunkId]||chunkId) + \""
129+
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
130130
}
131131
});
132132
return this.asString([
133133
"// \"0\" is the signal for \"already loaded\"",
134134
"if(installedChunks[chunkId] !== 0) {",
135135
this.indent([
136-
"var chunk = require(" + request + ");"
136+
`var chunk = require(${request});`
137137
].concat(insertMoreModules).concat([
138138
"for(var i = 0; i < chunkIds.length; i++)",
139139
this.indent("installedChunks[chunkIds[i]] = 0;")
@@ -148,25 +148,25 @@ module.exports = class NodeMainTemplatePlugin {
148148
const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
149149
const chunkMaps = chunk.getChunkMaps();
150150
const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
151-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
152-
hashWithLength: (length) => "\" + " + this.renderCurrentHashCode(hash, length) + " + \"",
151+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
152+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + \"`,
153153
chunk: {
154154
id: "\" + chunkId + \"",
155-
hash: "\" + " + JSON.stringify(chunkMaps.hash) + "[chunkId] + \"",
155+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
156156
hashWithLength: (length) => {
157157
const shortChunkHashMap = {};
158158
Object.keys(chunkMaps.hash).forEach((chunkId) => {
159159
if(typeof chunkMaps.hash[chunkId] === "string")
160160
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
161161
});
162-
return "\" + " + JSON.stringify(shortChunkHashMap) + "[chunkId] + \"";
162+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
163163
},
164-
name: "\" + (" + JSON.stringify(chunkMaps.name) + "[chunkId]||chunkId) + \""
164+
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
165165
}
166166
});
167167
const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
168-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
169-
hashWithLength: (length) => "\" + " + this.renderCurrentHashCode(hash, length) + " + \""
168+
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
169+
hashWithLength: (length) => `" + ${this.renderCurrentHashCode(hash, length)} + "`
170170
});
171171
return Template.getFunctionContent(asyncChunkLoading ? require("./NodeMainTemplateAsync.runtime.js") : require("./NodeMainTemplate.runtime.js"))
172172
.replace(/\$require\$/g, this.requireFn)

0 commit comments

Comments
 (0)