Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/AbstractMethodError.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
* @param {string=} method method name
* @returns {string} message
*/
function createMessage(method) {
return `Abstract method${method ? ` ${method}` : ""}. Must be overridden.`;
}
const createMessage = (method) =>
`Abstract method${method ? ` ${method}` : ""}. Must be overridden.`;

/**
* @constructor
Expand Down
4 changes: 2 additions & 2 deletions lib/DefinePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class RuntimeValue {
* @param {DestructuringAssignmentProperties | undefined} properties properties
* @returns {Set<string> | undefined} used keys
*/
function getObjKeys(properties) {
const getObjKeys = (properties) => {
if (!properties) return;
return new Set([...properties].map((p) => p.id));
}
};

/** @typedef {Set<string> | null} ObjKeys */
/** @typedef {boolean | undefined | null} AsiSafe */
Expand Down
4 changes: 1 addition & 3 deletions lib/RuntimeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ class RuntimeTemplate {
forEach(variable, array, body) {
return this.supportsForOf()
? `for(const ${variable} of ${array}) {\n${Template.indent(body)}\n}`
: `${array}.forEach(function(${variable}) {\n${Template.indent(
body
)}\n});`;
: `${array}.forEach((${variable}) => {\n${Template.indent(body)}\n});`;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/async-modules/AwaitDependenciesInitFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class AwaitDependenciesInitFragment extends InitFragment {
const asyncModuleValues = [...this.dependencies.values()].join(", ");

const templateInput = [
`var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${asyncModuleValues}]);`
`const __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${asyncModuleValues}]);`
];

if (
this.dependencies.size === 1 ||
!runtimeTemplate.supportsDestructuring()
) {
templateInput.push(
"var __webpack_async_dependencies_result__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);"
"const __webpack_async_dependencies_result__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);"
);
for (const [index, importVar] of importVars.entries()) {
templateInput.push(
Expand Down
2 changes: 1 addition & 1 deletion lib/container/ContainerEntryModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ContainerEntryModule extends Module {
`var init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
`if (!${RuntimeGlobals.shareScopeMap}) return;`,
`var name = ${JSON.stringify(this._shareScope)}`,
`var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
`const oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
'if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");',
`${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
`return ${RuntimeGlobals.initializeSharing}(name, initScope);`
Expand Down
10 changes: 5 additions & 5 deletions lib/container/FallbackModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class FallbackModule extends Module {
chunkGraph.getModuleId(/** @type {Module} */ (moduleGraph.getModule(dep)))
);
const code = Template.asString([
`var ids = ${JSON.stringify(ids)};`,
"var error, result, i = 0;",
`var loop = ${runtimeTemplate.basicFunction("next", [
`const ids = ${JSON.stringify(ids)};`,
"let error, result, i = 0;",
`const loop = ${runtimeTemplate.basicFunction("next", [
"while(i < ids.length) {",
Template.indent([
`try { next = ${RuntimeGlobals.require}(ids[i++]); } catch(e) { return handleError(e); }`,
Expand All @@ -145,11 +145,11 @@ class FallbackModule extends Module {
"}",
"if(error) throw error;"
])}`,
`var handleResult = ${runtimeTemplate.basicFunction("result", [
`const handleResult = ${runtimeTemplate.basicFunction("result", [
"if(result) return result;",
"return loop();"
])};`,
`var handleError = ${runtimeTemplate.basicFunction("e", [
`const handleError = ${runtimeTemplate.basicFunction("e", [
"error = e;",
"return loop();"
])};`,
Expand Down
8 changes: 4 additions & 4 deletions lib/container/RemoteRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class RemoteRuntimeModule extends RuntimeModule {
`if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,
Template.indent([
`chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction("id", [
`var getScope = ${RuntimeGlobals.currentRemoteGetScope};`,
`let getScope = ${RuntimeGlobals.currentRemoteGetScope};`,
"if(!getScope) getScope = [];",
"var data = idToExternalAndNameMapping[id];",
"const data = idToExternalAndNameMapping[id];",
"if(getScope.indexOf(data) >= 0) return;",
"getScope.push(data);",
"if(data.p) return promises.push(data.p);",
Expand All @@ -98,10 +98,10 @@ class RemoteRuntimeModule extends RuntimeModule {
[
"try {",
Template.indent([
"var promise = fn(arg1, arg2);",
"const promise = fn(arg1, arg2);",
"if(promise && promise.then) {",
Template.indent([
`var p = promise.then(${runtimeTemplate.returningFunction(
`const p = promise.then(${runtimeTemplate.returningFunction(
"next(result, d)",
"result"
)}, onError);`,
Expand Down
48 changes: 24 additions & 24 deletions lib/css/CssLoadingRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: "// data-webpack is not used as build has no uniqueName",
withLoading || withHmr
? Template.asString([
'var loadingAttribute = "data-webpack-loading";',
'const loadingAttribute = "data-webpack-loading";',
`var loadStylesheet = ${runtimeTemplate.basicFunction(
`chunkId, url, done${
withFetchPriority ? ", fetchPriority" : ""
}${withHmr ? ", hmr" : ""}`,
[
'var link, needAttach, key = "chunk-" + chunkId;',
'let link, needAttach; const key = "chunk-" + chunkId;',
withHmr ? "if(!hmr) {" : "",
'var links = document.getElementsByTagName("link");',
"for(var i = 0; i < links.length; i++) {",
'const links = document.getElementsByTagName("link");',
"for(let i = 0; i < links.length; i++) {",
Template.indent([
"var l = links[i];",
"const l = links[i];",
`if(l.rel == "stylesheet" && (${
withHmr
? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
Expand Down Expand Up @@ -235,7 +235,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
)};`,
"if(link.getAttribute(loadingAttribute)) {",
Template.indent([
`var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
`const timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
"link.onerror = onLinkComplete.bind(null, link.onerror);",
"link.onload = onLinkComplete.bind(null, link.onload);"
]),
Expand All @@ -256,7 +256,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
`chunkId, promises${withFetchPriority ? " , fetchPriority" : ""}`,
[
"// css chunk loading",
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
`let installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
'if(installedChunkData !== 0) { // 0 means "already installed".',
Template.indent([
"",
Expand All @@ -270,17 +270,17 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: `if(${hasCssMatcher("chunkId")}) {`,
Template.indent([
"// setup Promise in chunk cache",
`var promise = new Promise(${runtimeTemplate.expressionFunction(
`const promise = new Promise(${runtimeTemplate.expressionFunction(
"installedChunkData = installedChunks[chunkId] = [resolve, reject]",
"resolve, reject"
)});`,
"promises.push(installedChunkData[2] = promise);",
"",
"// start chunk loading",
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
`const url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
"// create error before stack unwound to get useful stacktrace later",
"var error = new Error();",
`var loadingEnded = ${runtimeTemplate.basicFunction(
"const error = new Error();",
`const loadingEnded = ${runtimeTemplate.basicFunction(
"event",
[
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
Expand All @@ -291,8 +291,8 @@ class CssLoadingRuntimeModule extends RuntimeModule {
Template.indent([
'if(event.type !== "load") {',
Template.indent([
"var errorType = event && event.type;",
"var realHref = event && event.target && event.target.href;",
"const errorType = event && event.type;",
"const realHref = event && event.target && event.target.href;",
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
Expand Down Expand Up @@ -349,7 +349,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: "",
linkPrefetch.call(
Template.asString([
"var link = document.createElement('link');",
"const link = document.createElement('link');",
charset ? "link.charset = 'utf-8';" : "",
crossOriginLoading
? `link.crossOrigin = ${JSON.stringify(
Expand Down Expand Up @@ -389,7 +389,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: "",
linkPreload.call(
Template.asString([
"var link = document.createElement('link');",
"const link = document.createElement('link');",
charset ? "link.charset = 'utf-8';" : "",
`if (${RuntimeGlobals.scriptNonce}) {`,
Template.indent(
Expand Down Expand Up @@ -422,20 +422,20 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: "// no preloaded",
withHmr
? Template.asString([
"var oldTags = [];",
"var newTags = [];",
"const oldTags = [];",
"const newTags = [];",
`var applyHandler = ${runtimeTemplate.basicFunction("options", [
`return { dispose: ${runtimeTemplate.basicFunction("", [
"while(oldTags.length) {",
Template.indent([
"var oldTag = oldTags.pop();",
"const oldTag = oldTags.pop();",
"if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
]),
"}"
])}, apply: ${runtimeTemplate.basicFunction("", [
"while(newTags.length) {",
Template.indent([
"var newTag = newTags.pop();",
"const newTag = newTags.pop();",
"newTag.sheet.disabled = false"
]),
"}"
Expand All @@ -458,9 +458,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
: "",
"applyHandlers.push(applyHandler);",
`chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
`var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
`var url = ${RuntimeGlobals.publicPath} + filename;`,
"var oldTag = loadStylesheet(chunkId, url);",
`const filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
`const url = ${RuntimeGlobals.publicPath} + filename;`,
"const oldTag = loadStylesheet(chunkId, url);",
"if(!oldTag) return;",
`promises.push(new Promise(${runtimeTemplate.basicFunction(
"resolve, reject",
Expand All @@ -470,8 +470,8 @@ class CssLoadingRuntimeModule extends RuntimeModule {
[
'if(event.type !== "load") {',
Template.indent([
"var errorType = event && event.type;",
"var realHref = event && event.target && event.target.href;",
"const errorType = event && event.type;",
"const realHref = event && event.target && event.target.href;",
"error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
Expand Down
2 changes: 1 addition & 1 deletion lib/css/CssModulesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class CssModulesPlugin {

const hmrCode = Template.asString([
"",
`var __webpack_css_exports__ = ${stringifiedExports};`,
`const __webpack_css_exports__ = ${stringifiedExports};`,
"// only invalidate when locals change",
"if (module.hot.data && module.hot.data.__webpack_css_exports__ && module.hot.data.__webpack_css_exports__ != __webpack_css_exports__) {",
Template.indent("module.hot.invalidate();"),
Expand Down
14 changes: 7 additions & 7 deletions lib/esm/ModuleChunkLoadingRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
hasJsMatcher !== false
? Template.indent([
"// import() chunk loading for javascript",
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
`const installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
'if(installedChunkData !== 0) { // 0 means "already installed".',
Template.indent([
"",
Expand Down Expand Up @@ -269,7 +269,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
"installedChunks[chunkId] = null;",
linkPrefetch.call(
Template.asString([
"var link = document.createElement('link');",
"const link = document.createElement('link');",
charset ? "link.charset = 'utf-8';" : "",
crossOriginLoading
? `link.crossOrigin = ${JSON.stringify(
Expand Down Expand Up @@ -309,7 +309,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
"installedChunks[chunkId] = null;",
linkPreload.call(
Template.asString([
"var link = document.createElement('link');",
"const link = document.createElement('link');",
charset ? "link.charset = 'utf-8';" : "",
`if (${RuntimeGlobals.scriptNonce}) {`,
Template.indent(
Expand Down Expand Up @@ -364,10 +364,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
"resolve, reject",
[
"// start update chunk loading",
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`,
`const url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`,
`var onResolve = ${runtimeTemplate.basicFunction("obj", [
`var updatedModules = obj.${RuntimeGlobals.esmModules};`,
`var updatedRuntime = obj.${RuntimeGlobals.esmRuntime};`,
`const updatedModules = obj.${RuntimeGlobals.esmModules};`,
`const updatedRuntime = obj.${RuntimeGlobals.esmRuntime};`,
"if(updatedRuntime) currentUpdateRuntime.push(updatedRuntime);",
"for(var moduleId in updatedModules) {",
Template.indent([
Expand All @@ -382,7 +382,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
"resolve(obj);"
])};`,
`var onReject = ${runtimeTemplate.basicFunction("error", [
"var errorMsg = error.message || 'unknown reason';",
"const errorMsg = error.message || 'unknown reason';",
"error.message = 'Loading hot update chunk ' + chunkId + ' failed.\\n(' + errorMsg + ')';",
"error.name = 'ChunkLoadError';",
"reject(error);"
Expand Down
8 changes: 4 additions & 4 deletions lib/hmr/LazyCompilationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class LazyCompilationProxyModule extends Module {
request: clientDep.userRequest,
runtimeRequirements
})}`,
`var data = ${JSON.stringify(this.data)};`
`const data = ${JSON.stringify(this.data)};`
]);
const keepActive = Template.asString([
`var dispose = client.keepAlive({ data: data, active: ${JSON.stringify(
`const dispose = client.keepAlive({ data: data, active: ${JSON.stringify(
Boolean(block)
)}, module: module, onError: onError });`
]);
Expand Down Expand Up @@ -277,8 +277,8 @@ class LazyCompilationProxyModule extends Module {
} else {
source = Template.asString([
client,
"var resolveSelf, onError;",
"module.exports = new Promise(function(resolve, reject) { resolveSelf = resolve; onError = reject; });",
"let resolveSelf, onError;",
"module.exports = new Promise((resolve, reject) => { resolveSelf = resolve; onError = reject; });",
"if (module.hot) {",
Template.indent([
"module.hot.accept();",
Expand Down
4 changes: 2 additions & 2 deletions lib/javascript/CommonJsChunkFormatPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class CommonJsChunkFormatPlugin {
runtimeTemplate.supportsArrowFunction() ? "() => " : "function() "
}{\n`
);
entrySource.add("var exports = {};\n");
entrySource.add("const exports = {};\n");
entrySource.add(source);
entrySource.add(";\n\n// load runtime\n");
entrySource.add(
`var ${RuntimeGlobals.require} = require(${JSON.stringify(
`const ${RuntimeGlobals.require} = require(${JSON.stringify(
runtimePath
)});\n`
);
Expand Down
2 changes: 1 addition & 1 deletion lib/javascript/JavascriptModulesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ class JavascriptModulesPlugin {
)
? Template.asString([
`var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
`${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
`${RuntimeGlobals.interceptModuleExecution}.forEach((handler) => { handler(execOptions); });`,
"module = execOptions.module;",
"execOptions.factory.call(module.exports, module, module.exports, execOptions.require);"
])
Expand Down
Loading