Skip to content

Commit b0e03f4

Browse files
authored
Merge pull request webpack#4256 from jescalan/master
Template strings in MainTemplate file
2 parents 7a1a439 + b660b64 commit b0e03f4

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

‎lib/MainTemplate.js‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ module.exports = class MainTemplate extends Template {
3030
const buf = [];
3131
if(chunk.entryModule) {
3232
buf.push("// Load entry module and return exports");
33-
buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id)) +
34-
"(" + this.requireFn + ".s = " + JSON.stringify(chunk.entryModule.id) + ");");
33+
buf.push(`return ${this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id))}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`);
3534
}
3635
return this.asString(buf);
3736
});
@@ -71,7 +70,7 @@ module.exports = class MainTemplate extends Template {
7170
"var threw = true;",
7271
"try {",
7372
this.indent([
74-
"modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
73+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
7574
"threw = false;"
7675
]),
7776
"} finally {",
@@ -81,7 +80,7 @@ module.exports = class MainTemplate extends Template {
8180
"}"
8281
] : [
8382
"// Execute the module function",
84-
"modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
83+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
8584
]),
8685
"",
8786
"// Flag the module as loaded",
@@ -103,27 +102,27 @@ module.exports = class MainTemplate extends Template {
103102
if(chunk.chunks.length > 0) {
104103
buf.push("// This file contains only the entry chunk.");
105104
buf.push("// The chunk loading function for additional chunks");
106-
buf.push(this.requireFn + ".e = function requireEnsure(chunkId) {");
105+
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
107106
buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
108107
buf.push("};");
109108
}
110109
buf.push("");
111110
buf.push("// expose the modules object (__webpack_modules__)");
112-
buf.push(this.requireFn + ".m = modules;");
111+
buf.push(`${this.requireFn}.m = modules;`);
113112

114113
buf.push("");
115114
buf.push("// expose the module cache");
116-
buf.push(this.requireFn + ".c = installedModules;");
115+
buf.push(`${this.requireFn}.c = installedModules;`);
117116

118117
buf.push("");
119118
buf.push("// identity function for calling harmony imports with the correct context");
120-
buf.push(this.requireFn + ".i = function(value) { return value; };");
119+
buf.push(`${this.requireFn}.i = function(value) { return value; };`);
121120

122121
buf.push("");
123122
buf.push("// define getter function for harmony exports");
124-
buf.push(this.requireFn + ".d = function(exports, name, getter) {");
123+
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
125124
buf.push(this.indent([
126-
"if(!" + this.requireFn + ".o(exports, name)) {",
125+
`if(!${this.requireFn}.o(exports, name)) {`,
127126
this.indent([
128127
"Object.defineProperty(exports, name, {",
129128
this.indent([
@@ -146,21 +145,21 @@ module.exports = class MainTemplate extends Template {
146145
"function getDefault() { return module['default']; } :",
147146
"function getModuleExports() { return module; };"
148147
]),
149-
this.requireFn + ".d(getter, 'a', getter);",
148+
`${this.requireFn}.d(getter, 'a', getter);`,
150149
"return getter;"
151150
]));
152151
buf.push("};");
153152

154153
buf.push("");
155154
buf.push("// Object.prototype.hasOwnProperty.call");
156-
buf.push(this.requireFn + ".o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };");
155+
buf.push(`${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`);
157156

158157
const publicPath = this.getPublicPath({
159158
hash: hash
160159
});
161160
buf.push("");
162161
buf.push("// __webpack_public_path__");
163-
buf.push(this.requireFn + ".p = " + JSON.stringify(publicPath) + ";");
162+
buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
164163
return this.asString(buf);
165164
});
166165

@@ -173,14 +172,14 @@ module.exports = class MainTemplate extends Template {
173172
buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
174173
buf.push("");
175174
buf.push("// The require function");
176-
buf.push("function " + this.requireFn + "(moduleId) {");
175+
buf.push(`function ${this.requireFn}(moduleId) {`);
177176
buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
178177
buf.push("}");
179178
buf.push("");
180179
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
181180
buf.push("");
182181
buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
183-
let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
182+
let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
184183
if(chunk.hasEntryModule()) {
185184
source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
186185
}
@@ -194,7 +193,7 @@ module.exports = class MainTemplate extends Template {
194193
}
195194

196195
renderAddModule(hash, chunk, varModuleId, varModule) {
197-
return this.applyPluginsWaterfall("add-module", "modules[" + varModuleId + "] = " + varModule + ";", chunk, hash, varModuleId, varModule);
196+
return this.applyPluginsWaterfall("add-module", `modules[${varModuleId}] = ${varModule};`, chunk, hash, varModuleId, varModule);
198197
}
199198

200199
renderCurrentHashCode(hash, length) {

0 commit comments

Comments
 (0)