mirror of https://github.com/webpack/webpack.git
refactor: code
This commit is contained in:
parent
b84d7956b5
commit
93743d233a
|
@ -214,24 +214,20 @@ module.exports = [
|
||||||
"unicorn/prefer-includes": "error",
|
"unicorn/prefer-includes": "error",
|
||||||
"unicorn/no-zero-fractions": "error",
|
"unicorn/no-zero-fractions": "error",
|
||||||
"unicorn/prefer-string-starts-ends-with": "error",
|
"unicorn/prefer-string-starts-ends-with": "error",
|
||||||
|
"unicorn/prefer-default-parameters": "error",
|
||||||
|
"unicorn/prefer-negative-index": "error",
|
||||||
|
"unicorn/prefer-ternary": ["error", "only-single-line"],
|
||||||
|
"unicorn/prefer-array-find": "error",
|
||||||
|
"unicorn/prefer-string-slice": "error",
|
||||||
|
"unicorn/no-lonely-if": "error",
|
||||||
|
"unicorn/no-hex-escape": "error",
|
||||||
|
"unicorn/escape-case": "error",
|
||||||
|
"unicorn/no-array-for-each": "error",
|
||||||
|
"unicorn/prefer-number-properties": "error",
|
||||||
|
"unicorn/prefer-regexp-test": "error",
|
||||||
|
"unicorn/prefer-native-coercion-functions": "error",
|
||||||
// TODO Enable
|
// TODO Enable
|
||||||
"unicorn/prefer-spread": "off",
|
"unicorn/prefer-spread": "off"
|
||||||
"unicorn/prefer-string-slice": "off",
|
|
||||||
"unicorn/explicit-length-check": "off",
|
|
||||||
"unicorn/no-lonely-if": "off",
|
|
||||||
"unicorn/prefer-ternary": "off",
|
|
||||||
"unicorn/no-useless-undefined": "off",
|
|
||||||
"unicorn/no-hex-escape": "off",
|
|
||||||
"unicorn/escape-case": "off",
|
|
||||||
"unicorn/prefer-negative-index": "off",
|
|
||||||
"unicorn/no-array-for-each": "off",
|
|
||||||
"unicorn/prefer-number-properties": "off",
|
|
||||||
"unicorn/prefer-default-parameters": "off",
|
|
||||||
"unicorn/prefer-regexp-test": "off",
|
|
||||||
"unicorn/prefer-math-trunc": "off",
|
|
||||||
"unicorn/prefer-array-find": "off",
|
|
||||||
"unicorn/prefer-native-coercion-functions": "off",
|
|
||||||
"unicorn/no-useless-switch-case": "off"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -362,7 +358,9 @@ module.exports = [
|
||||||
"prefer-template": "off",
|
"prefer-template": "off",
|
||||||
"no-implicit-coercion": "off",
|
"no-implicit-coercion": "off",
|
||||||
"func-style": "off",
|
"func-style": "off",
|
||||||
"unicorn/prefer-includes": "off"
|
"unicorn/prefer-includes": "off",
|
||||||
|
"unicorn/no-useless-undefined": "off",
|
||||||
|
"unicorn/no-array-for-each": "off"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -214,7 +214,7 @@ class APIPlugin {
|
||||||
* @param {JavascriptParser} parser the parser
|
* @param {JavascriptParser} parser the parser
|
||||||
*/
|
*/
|
||||||
const handler = parser => {
|
const handler = parser => {
|
||||||
Object.keys(REPLACEMENTS).forEach(key => {
|
for (const key of Object.keys(REPLACEMENTS)) {
|
||||||
const info = REPLACEMENTS[key];
|
const info = REPLACEMENTS[key];
|
||||||
parser.hooks.expression.for(key).tap(PLUGIN_NAME, expression => {
|
parser.hooks.expression.for(key).tap(PLUGIN_NAME, expression => {
|
||||||
const dep = toConstantDependency(parser, info.expr, info.req);
|
const dep = toConstantDependency(parser, info.expr, info.req);
|
||||||
|
@ -238,7 +238,7 @@ class APIPlugin {
|
||||||
.for(key)
|
.for(key)
|
||||||
.tap(PLUGIN_NAME, evaluateToString(info.type));
|
.tap(PLUGIN_NAME, evaluateToString(info.type));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
parser.hooks.expression
|
parser.hooks.expression
|
||||||
.for("__webpack_layer__")
|
.for("__webpack_layer__")
|
||||||
|
|
|
@ -45,6 +45,7 @@ class AutomaticPrefetchPlugin {
|
||||||
"AutomaticPrefetchPlugin",
|
"AutomaticPrefetchPlugin",
|
||||||
(compilation, callback) => {
|
(compilation, callback) => {
|
||||||
if (!lastModules) return callback();
|
if (!lastModules) return callback();
|
||||||
|
// eslint-disable-next-line unicorn/no-array-for-each
|
||||||
asyncLib.forEach(
|
asyncLib.forEach(
|
||||||
lastModules,
|
lastModules,
|
||||||
(m, callback) => {
|
(m, callback) => {
|
||||||
|
|
|
@ -37,7 +37,7 @@ const createModulesListMessage = (modules, moduleGraph) =>
|
||||||
let message = `* ${m.identifier()}`;
|
let message = `* ${m.identifier()}`;
|
||||||
const validReasons = Array.from(
|
const validReasons = Array.from(
|
||||||
moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
|
moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
|
||||||
).filter(x => x);
|
).filter(Boolean);
|
||||||
|
|
||||||
if (validReasons.length > 0) {
|
if (validReasons.length > 0) {
|
||||||
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
||||||
|
|
|
@ -766,7 +766,7 @@ class Chunk {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list.length === 0) return undefined;
|
if (list.length === 0) return;
|
||||||
list.sort((a, b) => {
|
list.sort((a, b) => {
|
||||||
const cmp =
|
const cmp =
|
||||||
/** @type {number} */ (b.order) - /** @type {number} */ (a.order);
|
/** @type {number} */ (b.order) - /** @type {number} */ (a.order);
|
||||||
|
|
|
@ -700,7 +700,7 @@ class ChunkGraph {
|
||||||
const modulesWithSourceType = cgc.modules
|
const modulesWithSourceType = cgc.modules
|
||||||
.getFromUnorderedCache(cgc._modulesBySourceType)
|
.getFromUnorderedCache(cgc._modulesBySourceType)
|
||||||
.get(sourceType);
|
.get(sourceType);
|
||||||
if (modulesWithSourceType === undefined) return undefined;
|
if (modulesWithSourceType === undefined) return;
|
||||||
modulesWithSourceType.sortWith(comparator);
|
modulesWithSourceType.sortWith(comparator);
|
||||||
return modulesWithSourceType;
|
return modulesWithSourceType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,7 +570,7 @@ class Compilation {
|
||||||
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
|
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
|
||||||
*/
|
*/
|
||||||
const createProcessAssetsHook = (name, stage, getArgs, code) => {
|
const createProcessAssetsHook = (name, stage, getArgs, code) => {
|
||||||
if (!this._backCompat && code) return undefined;
|
if (!this._backCompat && code) return;
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
||||||
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
||||||
|
@ -1208,10 +1208,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
||||||
trace
|
trace
|
||||||
};
|
};
|
||||||
if (this.hooks.log.call(name, logEntry) === undefined) {
|
if (this.hooks.log.call(name, logEntry) === undefined) {
|
||||||
if (logEntry.type === LogType.profileEnd) {
|
if (
|
||||||
if (typeof console.profileEnd === "function") {
|
logEntry.type === LogType.profileEnd &&
|
||||||
console.profileEnd(`[${name}] ${logEntry.args[0]}`);
|
typeof console.profileEnd === "function"
|
||||||
}
|
) {
|
||||||
|
console.profileEnd(`[${name}] ${logEntry.args[0]}`);
|
||||||
}
|
}
|
||||||
if (logEntries === undefined) {
|
if (logEntries === undefined) {
|
||||||
logEntries = this.logging.get(name);
|
logEntries = this.logging.get(name);
|
||||||
|
@ -1221,10 +1222,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logEntries.push(logEntry);
|
logEntries.push(logEntry);
|
||||||
if (logEntry.type === LogType.profile) {
|
if (
|
||||||
if (typeof console.profile === "function") {
|
logEntry.type === LogType.profile &&
|
||||||
console.profile(`[${name}] ${logEntry.args[0]}`);
|
typeof console.profile === "function"
|
||||||
}
|
) {
|
||||||
|
console.profile(`[${name}] ${logEntry.args[0]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1921,14 +1923,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
||||||
module,
|
module,
|
||||||
originModule !== undefined ? originModule : null
|
originModule !== undefined ? originModule : null
|
||||||
);
|
);
|
||||||
if (module !== newModule) {
|
if (module !== newModule && currentProfile !== undefined) {
|
||||||
if (currentProfile !== undefined) {
|
const otherProfile = moduleGraph.getProfile(module);
|
||||||
const otherProfile = moduleGraph.getProfile(module);
|
if (otherProfile !== undefined) {
|
||||||
if (otherProfile !== undefined) {
|
currentProfile.mergeInto(otherProfile);
|
||||||
currentProfile.mergeInto(otherProfile);
|
} else {
|
||||||
} else {
|
moduleGraph.setProfile(module, currentProfile);
|
||||||
moduleGraph.setProfile(module, currentProfile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3340,9 +3340,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
||||||
(job, callback) => {
|
(job, callback) => {
|
||||||
const { module } = job;
|
const { module } = job;
|
||||||
const { codeGenerationDependencies } = module;
|
const { codeGenerationDependencies } = module;
|
||||||
if (codeGenerationDependencies !== undefined) {
|
if (
|
||||||
if (
|
codeGenerationDependencies !== undefined &&
|
||||||
notCodeGeneratedModules === undefined ||
|
(notCodeGeneratedModules === undefined ||
|
||||||
codeGenerationDependencies.some(dep => {
|
codeGenerationDependencies.some(dep => {
|
||||||
const referencedModule = /** @type {Module} */ (
|
const referencedModule = /** @type {Module} */ (
|
||||||
moduleGraph.getModule(dep)
|
moduleGraph.getModule(dep)
|
||||||
|
@ -3350,12 +3350,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
||||||
return /** @type {NotCodeGeneratedModules} */ (
|
return /** @type {NotCodeGeneratedModules} */ (
|
||||||
notCodeGeneratedModules
|
notCodeGeneratedModules
|
||||||
).has(referencedModule);
|
).has(referencedModule);
|
||||||
})
|
}))
|
||||||
) {
|
) {
|
||||||
delayedJobs.push(job);
|
delayedJobs.push(job);
|
||||||
delayedModules.add(module);
|
delayedModules.add(module);
|
||||||
return callback();
|
return callback();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const { hash, runtime, runtimes } = job;
|
const { hash, runtime, runtimes } = job;
|
||||||
this._codeGenerationModule(
|
this._codeGenerationModule(
|
||||||
|
@ -3923,11 +3922,12 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
||||||
if (!module.hasReasons(this.moduleGraph, chunk.runtime)) {
|
if (!module.hasReasons(this.moduleGraph, chunk.runtime)) {
|
||||||
this.removeReasonsOfDependencyBlock(module, module);
|
this.removeReasonsOfDependencyBlock(module, module);
|
||||||
}
|
}
|
||||||
if (!module.hasReasonForChunk(chunk, this.moduleGraph, this.chunkGraph)) {
|
if (
|
||||||
if (this.chunkGraph.isModuleInChunk(module, chunk)) {
|
!module.hasReasonForChunk(chunk, this.moduleGraph, this.chunkGraph) &&
|
||||||
this.chunkGraph.disconnectChunkAndModule(chunk, module);
|
this.chunkGraph.isModuleInChunk(module, chunk)
|
||||||
this.removeChunkFromDependencies(module, chunk);
|
) {
|
||||||
}
|
this.chunkGraph.disconnectChunkAndModule(chunk, module);
|
||||||
|
this.removeChunkFromDependencies(module, chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4335,7 +4335,7 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
}
|
}
|
||||||
this.logger.timeAggregate("hashing: hash chunks");
|
this.logger.timeAggregate("hashing: hash chunks");
|
||||||
};
|
};
|
||||||
otherChunks.forEach(processChunk);
|
for (const chunk of otherChunks) processChunk(chunk);
|
||||||
for (const chunk of runtimeChunks) processChunk(chunk);
|
for (const chunk of runtimeChunks) processChunk(chunk);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
|
errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
|
||||||
|
@ -4445,7 +4445,9 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
};
|
};
|
||||||
const entry = oldRelated[key];
|
const entry = oldRelated[key];
|
||||||
if (Array.isArray(entry)) {
|
if (Array.isArray(entry)) {
|
||||||
entry.forEach(remove);
|
for (const name of entry) {
|
||||||
|
remove(name);
|
||||||
|
}
|
||||||
} else if (entry) {
|
} else if (entry) {
|
||||||
remove(entry);
|
remove(entry);
|
||||||
}
|
}
|
||||||
|
@ -4469,7 +4471,9 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
};
|
};
|
||||||
const entry = newRelated[key];
|
const entry = newRelated[key];
|
||||||
if (Array.isArray(entry)) {
|
if (Array.isArray(entry)) {
|
||||||
entry.forEach(add);
|
for (const name of entry) {
|
||||||
|
add(name);
|
||||||
|
}
|
||||||
} else if (entry) {
|
} else if (entry) {
|
||||||
add(entry);
|
add(entry);
|
||||||
}
|
}
|
||||||
|
@ -4492,11 +4496,10 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
`Called Compilation.updateAsset for not existing filename ${file}`
|
`Called Compilation.updateAsset for not existing filename ${file}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (typeof newSourceOrFunction === "function") {
|
this.assets[file] =
|
||||||
this.assets[file] = newSourceOrFunction(this.assets[file]);
|
typeof newSourceOrFunction === "function"
|
||||||
} else {
|
? newSourceOrFunction(this.assets[file])
|
||||||
this.assets[file] = newSourceOrFunction;
|
: newSourceOrFunction;
|
||||||
}
|
|
||||||
if (assetInfoUpdateOrFunction !== undefined) {
|
if (assetInfoUpdateOrFunction !== undefined) {
|
||||||
const oldInfo = this.assetsInfo.get(file) || EMPTY_ASSET_INFO;
|
const oldInfo = this.assetsInfo.get(file) || EMPTY_ASSET_INFO;
|
||||||
if (typeof assetInfoUpdateOrFunction === "function") {
|
if (typeof assetInfoUpdateOrFunction === "function") {
|
||||||
|
@ -4522,14 +4525,12 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
`Called Compilation.renameAsset for not existing filename ${file}`
|
`Called Compilation.renameAsset for not existing filename ${file}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (this.assets[newFile]) {
|
if (this.assets[newFile] && !isSourceEqual(this.assets[file], source)) {
|
||||||
if (!isSourceEqual(this.assets[file], source)) {
|
this.errors.push(
|
||||||
this.errors.push(
|
new WebpackError(
|
||||||
new WebpackError(
|
`Conflict: Called Compilation.renameAsset for already existing filename ${newFile} with different content`
|
||||||
`Conflict: Called Compilation.renameAsset for already existing filename ${newFile} with different content`
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const assetInfo = this.assetsInfo.get(file);
|
const assetInfo = this.assetsInfo.get(file);
|
||||||
// Update related in all other assets
|
// Update related in all other assets
|
||||||
|
@ -4593,6 +4594,9 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
const related = assetInfo && assetInfo.related;
|
const related = assetInfo && assetInfo.related;
|
||||||
if (related) {
|
if (related) {
|
||||||
for (const key of Object.keys(related)) {
|
for (const key of Object.keys(related)) {
|
||||||
|
/**
|
||||||
|
* @param {string} file file
|
||||||
|
*/
|
||||||
const checkUsedAndDelete = file => {
|
const checkUsedAndDelete = file => {
|
||||||
if (!this._assetsRelatedIn.has(file)) {
|
if (!this._assetsRelatedIn.has(file)) {
|
||||||
this.deleteAsset(file);
|
this.deleteAsset(file);
|
||||||
|
@ -4600,7 +4604,9 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
};
|
};
|
||||||
const items = related[key];
|
const items = related[key];
|
||||||
if (Array.isArray(items)) {
|
if (Array.isArray(items)) {
|
||||||
items.forEach(checkUsedAndDelete);
|
for (const file of items) {
|
||||||
|
checkUsedAndDelete(file);
|
||||||
|
}
|
||||||
} else if (items) {
|
} else if (items) {
|
||||||
checkUsedAndDelete(items);
|
checkUsedAndDelete(items);
|
||||||
}
|
}
|
||||||
|
@ -4634,8 +4640,7 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
* @returns {Readonly<Asset> | undefined} the asset or undefined when not found
|
* @returns {Readonly<Asset> | undefined} the asset or undefined when not found
|
||||||
*/
|
*/
|
||||||
getAsset(name) {
|
getAsset(name) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(this.assets, name))
|
if (!Object.prototype.hasOwnProperty.call(this.assets, name)) return;
|
||||||
return undefined;
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
source: this.assets[name],
|
source: this.assets[name],
|
||||||
|
@ -4718,6 +4723,7 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
);
|
);
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line unicorn/no-array-for-each
|
||||||
asyncLib.forEach(
|
asyncLib.forEach(
|
||||||
manifest,
|
manifest,
|
||||||
(fileManifest, callback) => {
|
(fileManifest, callback) => {
|
||||||
|
@ -5220,9 +5226,9 @@ This prevents using hashes of each other and should be avoided.`);
|
||||||
},
|
},
|
||||||
require: __webpack_require__
|
require: __webpack_require__
|
||||||
};
|
};
|
||||||
interceptModuleExecution.forEach(handler =>
|
for (const handler of interceptModuleExecution) {
|
||||||
handler(execOptions)
|
handler(execOptions);
|
||||||
);
|
}
|
||||||
const module = moduleArgument.module;
|
const module = moduleArgument.module;
|
||||||
this.buildTimeExecutedModules.add(module);
|
this.buildTimeExecutedModules.add(module);
|
||||||
const moduleObject = execOptions.module;
|
const moduleObject = execOptions.module;
|
||||||
|
|
|
@ -353,10 +353,11 @@ class Compiler {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
|
if (
|
||||||
if (this.infrastructureLogger !== undefined) {
|
this.hooks.infrastructureLog.call(name, type, args) === undefined &&
|
||||||
this.infrastructureLogger(name, type, args);
|
this.infrastructureLogger !== undefined
|
||||||
}
|
) {
|
||||||
|
this.infrastructureLogger(name, type, args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
childName => {
|
childName => {
|
||||||
|
@ -977,7 +978,7 @@ ${other}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (targetFile.match(/\/|\\/)) {
|
if (/\/|\\/.test(targetFile)) {
|
||||||
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
||||||
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
||||||
mkdirp(fs, dir, writeOut);
|
mkdirp(fs, dir, writeOut);
|
||||||
|
@ -1220,11 +1221,10 @@ ${other}`);
|
||||||
"invalid",
|
"invalid",
|
||||||
"done",
|
"done",
|
||||||
"thisCompilation"
|
"thisCompilation"
|
||||||
].includes(name)
|
].includes(name) &&
|
||||||
|
childCompiler.hooks[name]
|
||||||
) {
|
) {
|
||||||
if (childCompiler.hooks[name]) {
|
childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
|
||||||
childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,21 +207,13 @@ class ConstPlugin {
|
||||||
// NOTE: When code runs in strict mode, `var` declarations
|
// NOTE: When code runs in strict mode, `var` declarations
|
||||||
// are hoisted but `function` declarations don't.
|
// are hoisted but `function` declarations don't.
|
||||||
//
|
//
|
||||||
let declarations;
|
const declarations = parser.scope.isStrict
|
||||||
if (parser.scope.isStrict) {
|
? getHoistedDeclarations(branchToRemove, false)
|
||||||
// If the code runs in strict mode, variable declarations
|
: getHoistedDeclarations(branchToRemove, true);
|
||||||
// using `var` must be hoisted.
|
const replacement =
|
||||||
declarations = getHoistedDeclarations(branchToRemove, false);
|
declarations.length > 0
|
||||||
} else {
|
? `{ var ${declarations.join(", ")}; }`
|
||||||
// Otherwise, collect all hoisted declaration.
|
: "{}";
|
||||||
declarations = getHoistedDeclarations(branchToRemove, true);
|
|
||||||
}
|
|
||||||
let replacement;
|
|
||||||
if (declarations.length > 0) {
|
|
||||||
replacement = `{ var ${declarations.join(", ")}; }`;
|
|
||||||
} else {
|
|
||||||
replacement = "{}";
|
|
||||||
}
|
|
||||||
const dep = new ConstDependency(
|
const dep = new ConstDependency(
|
||||||
replacement,
|
replacement,
|
||||||
/** @type {Range} */ (branchToRemove.range)
|
/** @type {Range} */ (branchToRemove.range)
|
||||||
|
|
|
@ -1124,10 +1124,12 @@ module.exports = webpackEmptyAsyncContext;`;
|
||||||
}
|
}
|
||||||
return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
|
return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
|
||||||
}
|
}
|
||||||
if (asyncMode === "weak") {
|
if (
|
||||||
if (this.dependencies && this.dependencies.length > 0) {
|
asyncMode === "weak" &&
|
||||||
return this.getWeakSyncSource(this.dependencies, id, chunkGraph);
|
this.dependencies &&
|
||||||
}
|
this.dependencies.length > 0
|
||||||
|
) {
|
||||||
|
return this.getWeakSyncSource(this.dependencies, id, chunkGraph);
|
||||||
}
|
}
|
||||||
if (this.dependencies && this.dependencies.length > 0) {
|
if (this.dependencies && this.dependencies.length > 0) {
|
||||||
return this.getSyncSource(this.dependencies, id, chunkGraph);
|
return this.getSyncSource(this.dependencies, id, chunkGraph);
|
||||||
|
|
|
@ -142,11 +142,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
||||||
.slice(i)
|
.slice(i)
|
||||||
.replace(/!+$/, "")
|
.replace(/!+$/, "")
|
||||||
.replace(/!!+/g, "!");
|
.replace(/!!+/g, "!");
|
||||||
if (loadersRequest === "") {
|
loaders = loadersRequest === "" ? [] : loadersRequest.split("!");
|
||||||
loaders = [];
|
|
||||||
} else {
|
|
||||||
loaders = loadersRequest.split("!");
|
|
||||||
}
|
|
||||||
resource = request.slice(idx + 1);
|
resource = request.slice(idx + 1);
|
||||||
} else {
|
} else {
|
||||||
loaders = [];
|
loaders = [];
|
||||||
|
|
|
@ -120,7 +120,7 @@ class RuntimeValue {
|
||||||
* @returns {Set<string> | undefined} used keys
|
* @returns {Set<string> | undefined} used keys
|
||||||
*/
|
*/
|
||||||
function getObjKeys(properties) {
|
function getObjKeys(properties) {
|
||||||
if (!properties) return undefined;
|
if (!properties) return;
|
||||||
return new Set([...properties].map(p => p.id));
|
return new Set([...properties].map(p => p.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +166,7 @@ const stringifyObj = (
|
||||||
} else {
|
} else {
|
||||||
let keys = Object.keys(obj);
|
let keys = Object.keys(obj);
|
||||||
if (objKeys) {
|
if (objKeys) {
|
||||||
if (objKeys.size === 0) keys = [];
|
keys = objKeys.size === 0 ? [] : keys.filter(k => objKeys.has(k));
|
||||||
else keys = keys.filter(k => objKeys.has(k));
|
|
||||||
}
|
}
|
||||||
code = `{${keys
|
code = `{${keys
|
||||||
.map(key => {
|
.map(key => {
|
||||||
|
@ -301,7 +300,7 @@ const toCacheVersion = code => {
|
||||||
key,
|
key,
|
||||||
value: toCacheVersion(/** @type {Record<string, any>} */ (code)[key])
|
value: toCacheVersion(/** @type {Record<string, any>} */ (code)[key])
|
||||||
}));
|
}));
|
||||||
if (items.some(({ value }) => value === undefined)) return undefined;
|
if (items.some(({ value }) => value === undefined)) return;
|
||||||
return `{${items.map(({ key, value }) => `${key}: ${value}`).join(", ")}}`;
|
return `{${items.map(({ key, value }) => `${key}: ${value}`).join(", ")}}`;
|
||||||
}
|
}
|
||||||
if (typeof code === "bigint") {
|
if (typeof code === "bigint") {
|
||||||
|
@ -404,7 +403,7 @@ class DefinePlugin {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const walkDefinitions = (definitions, prefix) => {
|
const walkDefinitions = (definitions, prefix) => {
|
||||||
Object.keys(definitions).forEach(key => {
|
for (const key of Object.keys(definitions)) {
|
||||||
const code = definitions[key];
|
const code = definitions[key];
|
||||||
if (
|
if (
|
||||||
code &&
|
code &&
|
||||||
|
@ -417,11 +416,11 @@ class DefinePlugin {
|
||||||
`${prefix + key}.`
|
`${prefix + key}.`
|
||||||
);
|
);
|
||||||
applyObjectDefine(prefix + key, code);
|
applyObjectDefine(prefix + key, code);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
applyDefineKey(prefix, key);
|
applyDefineKey(prefix, key);
|
||||||
applyDefine(prefix + key, code);
|
applyDefine(prefix + key, code);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,13 +431,13 @@ class DefinePlugin {
|
||||||
*/
|
*/
|
||||||
const applyDefineKey = (prefix, key) => {
|
const applyDefineKey = (prefix, key) => {
|
||||||
const splittedKey = key.split(".");
|
const splittedKey = key.split(".");
|
||||||
splittedKey.slice(1).forEach((_, i) => {
|
for (const [i, _] of splittedKey.slice(1).entries()) {
|
||||||
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
|
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
|
||||||
parser.hooks.canRename.for(fullKey).tap(PLUGIN_NAME, () => {
|
parser.hooks.canRename.for(fullKey).tap(PLUGIN_NAME, () => {
|
||||||
addValueDependency(key);
|
addValueDependency(key);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -647,7 +646,7 @@ class DefinePlugin {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const walkDefinitionsForValues = (definitions, prefix) => {
|
const walkDefinitionsForValues = (definitions, prefix) => {
|
||||||
Object.keys(definitions).forEach(key => {
|
for (const key of Object.keys(definitions)) {
|
||||||
const code = definitions[key];
|
const code = definitions[key];
|
||||||
const version = toCacheVersion(code);
|
const version = toCacheVersion(code);
|
||||||
const name = VALUE_DEP_PREFIX + prefix + key;
|
const name = VALUE_DEP_PREFIX + prefix + key;
|
||||||
|
@ -674,7 +673,7 @@ class DefinePlugin {
|
||||||
`${prefix + key}.`
|
`${prefix + key}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
walkDefinitionsForValues(definitions, "");
|
walkDefinitionsForValues(definitions, "");
|
||||||
|
|
|
@ -76,17 +76,15 @@ class DelegatedModuleFactoryPlugin {
|
||||||
"DelegatedModuleFactoryPlugin",
|
"DelegatedModuleFactoryPlugin",
|
||||||
module => {
|
module => {
|
||||||
const request = module.libIdent(this.options);
|
const request = module.libIdent(this.options);
|
||||||
if (request) {
|
if (request && request in this.options.content) {
|
||||||
if (request in this.options.content) {
|
const resolved = this.options.content[request];
|
||||||
const resolved = this.options.content[request];
|
return new DelegatedModule(
|
||||||
return new DelegatedModule(
|
this.options.source,
|
||||||
this.options.source,
|
resolved,
|
||||||
resolved,
|
this.options.type,
|
||||||
this.options.type,
|
request,
|
||||||
request,
|
module
|
||||||
module
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,16 +163,8 @@ class Dependency {
|
||||||
this._locEL = 0;
|
this._locEL = 0;
|
||||||
this._locEC = 0;
|
this._locEC = 0;
|
||||||
}
|
}
|
||||||
if ("index" in loc) {
|
this._locI = "index" in loc ? loc.index : undefined;
|
||||||
this._locI = loc.index;
|
this._locN = "name" in loc ? loc.name : undefined;
|
||||||
} else {
|
|
||||||
this._locI = undefined;
|
|
||||||
}
|
|
||||||
if ("name" in loc) {
|
|
||||||
this._locN = loc.name;
|
|
||||||
} else {
|
|
||||||
this._locN = undefined;
|
|
||||||
}
|
|
||||||
this._loc = loc;
|
this._loc = loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,9 @@ const cutOffMultilineMessage = (stack, message) => {
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
stackSplitByLines.forEach((line, idx) => {
|
for (const [idx, line] of stackSplitByLines.entries()) {
|
||||||
if (!line.includes(messageSplitByLines[idx])) result.push(line);
|
if (!line.includes(messageSplitByLines[idx])) result.push(line);
|
||||||
});
|
}
|
||||||
|
|
||||||
return result.join("\n");
|
return result.join("\n");
|
||||||
};
|
};
|
||||||
|
|
|
@ -261,7 +261,7 @@ class ExportsInfo {
|
||||||
getReadOnlyExportInfoRecursive(name) {
|
getReadOnlyExportInfoRecursive(name) {
|
||||||
const exportInfo = this.getReadOnlyExportInfo(name[0]);
|
const exportInfo = this.getReadOnlyExportInfo(name[0]);
|
||||||
if (name.length === 1) return exportInfo;
|
if (name.length === 1) return exportInfo;
|
||||||
if (!exportInfo.exportsInfo) return undefined;
|
if (!exportInfo.exportsInfo) return;
|
||||||
return exportInfo.exportsInfo.getReadOnlyExportInfoRecursive(name.slice(1));
|
return exportInfo.exportsInfo.getReadOnlyExportInfoRecursive(name.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ class ExportsInfo {
|
||||||
getNestedExportsInfo(name) {
|
getNestedExportsInfo(name) {
|
||||||
if (Array.isArray(name) && name.length > 0) {
|
if (Array.isArray(name) && name.length > 0) {
|
||||||
const info = this.getReadOnlyExportInfo(name[0]);
|
const info = this.getReadOnlyExportInfo(name[0]);
|
||||||
if (!info.exportsInfo) return undefined;
|
if (!info.exportsInfo) return;
|
||||||
return info.exportsInfo.getNestedExportsInfo(name.slice(1));
|
return info.exportsInfo.getNestedExportsInfo(name.slice(1));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -1170,14 +1170,13 @@ class ExportInfo {
|
||||||
if (!this._usedInRuntime.has(runtime)) {
|
if (!this._usedInRuntime.has(runtime)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (runtime !== undefined) {
|
} else if (
|
||||||
if (
|
runtime !== undefined &&
|
||||||
Array.from(runtime).every(
|
Array.from(runtime).every(
|
||||||
runtime => !this._usedInRuntime.has(runtime)
|
runtime => !this._usedInRuntime.has(runtime)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1208,7 @@ class ExportInfo {
|
||||||
getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
||||||
if (this.terminalBinding) return this;
|
if (this.terminalBinding) return this;
|
||||||
const target = this.getTarget(moduleGraph, resolveTargetFilter);
|
const target = this.getTarget(moduleGraph, resolveTargetFilter);
|
||||||
if (!target) return undefined;
|
if (!target) return;
|
||||||
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
||||||
if (!target.export) return exportsInfo;
|
if (!target.export) return exportsInfo;
|
||||||
return exportsInfo.getReadOnlyExportInfoRecursive(target.export);
|
return exportsInfo.getReadOnlyExportInfoRecursive(target.export);
|
||||||
|
@ -1258,9 +1257,9 @@ class ExportInfo {
|
||||||
* @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
|
* @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
|
||||||
*/
|
*/
|
||||||
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
||||||
if (!this._target || this._target.size === 0) return undefined;
|
if (!this._target || this._target.size === 0) return;
|
||||||
const rawTarget = this._getMaxTarget().values().next().value;
|
const rawTarget = this._getMaxTarget().values().next().value;
|
||||||
if (!rawTarget) return undefined;
|
if (!rawTarget) return;
|
||||||
/** @type {{ module: Module, export: string[] | undefined }} */
|
/** @type {{ module: Module, export: string[] | undefined }} */
|
||||||
let target = {
|
let target = {
|
||||||
module: rawTarget.connection.module,
|
module: rawTarget.connection.module,
|
||||||
|
@ -1297,7 +1296,7 @@ class ExportInfo {
|
||||||
*/
|
*/
|
||||||
getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
||||||
const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
||||||
if (result === CIRCULAR) return undefined;
|
if (result === CIRCULAR) return;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1363,26 +1362,26 @@ class ExportInfo {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this._target || this._target.size === 0) return undefined;
|
if (!this._target || this._target.size === 0) return;
|
||||||
if (alreadyVisited && alreadyVisited.has(this)) return CIRCULAR;
|
if (alreadyVisited && alreadyVisited.has(this)) return CIRCULAR;
|
||||||
const newAlreadyVisited = new Set(alreadyVisited);
|
const newAlreadyVisited = new Set(alreadyVisited);
|
||||||
newAlreadyVisited.add(this);
|
newAlreadyVisited.add(this);
|
||||||
const values = this._getMaxTarget().values();
|
const values = this._getMaxTarget().values();
|
||||||
const target = resolveTarget(values.next().value, newAlreadyVisited);
|
const target = resolveTarget(values.next().value, newAlreadyVisited);
|
||||||
if (target === CIRCULAR) return CIRCULAR;
|
if (target === CIRCULAR) return CIRCULAR;
|
||||||
if (target === null) return undefined;
|
if (target === null) return;
|
||||||
let result = values.next();
|
let result = values.next();
|
||||||
while (!result.done) {
|
while (!result.done) {
|
||||||
const t = resolveTarget(result.value, newAlreadyVisited);
|
const t = resolveTarget(result.value, newAlreadyVisited);
|
||||||
if (t === CIRCULAR) return CIRCULAR;
|
if (t === CIRCULAR) return CIRCULAR;
|
||||||
if (t === null) return undefined;
|
if (t === null) return;
|
||||||
if (t.module !== target.module) return undefined;
|
if (t.module !== target.module) return;
|
||||||
if (!t.export !== !target.export) return undefined;
|
if (!t.export !== !target.export) return;
|
||||||
if (
|
if (
|
||||||
target.export &&
|
target.export &&
|
||||||
!equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
|
!equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
|
||||||
)
|
)
|
||||||
return undefined;
|
return;
|
||||||
result = values.next();
|
result = values.next();
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
|
@ -1397,14 +1396,14 @@ class ExportInfo {
|
||||||
*/
|
*/
|
||||||
moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
|
moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
|
||||||
const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
||||||
if (target === CIRCULAR) return undefined;
|
if (target === CIRCULAR) return;
|
||||||
if (!target) return undefined;
|
if (!target) return;
|
||||||
const originalTarget = this._getMaxTarget().values().next().value;
|
const originalTarget = this._getMaxTarget().values().next().value;
|
||||||
if (
|
if (
|
||||||
originalTarget.connection === target.connection &&
|
originalTarget.connection === target.connection &&
|
||||||
originalTarget.export === target.export
|
originalTarget.export === target.export
|
||||||
) {
|
) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
this._target.clear();
|
this._target.clear();
|
||||||
this._target.set(undefined, {
|
this._target.set(undefined, {
|
||||||
|
|
|
@ -210,7 +210,7 @@ const getSourceForImportExternal = (
|
||||||
*/
|
*/
|
||||||
const importAssertionReplacer = (key, value) => {
|
const importAssertionReplacer = (key, value) => {
|
||||||
if (key === "_isLegacyAssert") {
|
if (key === "_isLegacyAssert") {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -84,12 +84,7 @@ class ExternalModuleFactoryPlugin {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
/** @type {string | string[] | Record<string, string|string[]>} */
|
/** @type {string | string[] | Record<string, string|string[]>} */
|
||||||
let externalConfig;
|
let externalConfig = value === true ? dependency.request : value;
|
||||||
if (value === true) {
|
|
||||||
externalConfig = dependency.request;
|
|
||||||
} else {
|
|
||||||
externalConfig = value;
|
|
||||||
}
|
|
||||||
// When no explicit type is specified, extract it from the externalConfig
|
// When no explicit type is specified, extract it from the externalConfig
|
||||||
if (type === undefined) {
|
if (type === undefined) {
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -523,7 +523,7 @@ class SnapshotOptimization {
|
||||||
|
|
||||||
getStatisticMessage() {
|
getStatisticMessage() {
|
||||||
const total = this._statItemsShared + this._statItemsUnshared;
|
const total = this._statItemsShared + this._statItemsUnshared;
|
||||||
if (total === 0) return undefined;
|
if (total === 0) return;
|
||||||
return `${
|
return `${
|
||||||
this._statItemsShared && Math.round((this._statItemsShared * 100) / total)
|
this._statItemsShared && Math.round((this._statItemsShared * 100) / total)
|
||||||
}% (${this._statItemsShared}/${total}) entries shared via ${
|
}% (${this._statItemsShared}/${total}) entries shared via ${
|
||||||
|
@ -553,7 +553,9 @@ class SnapshotOptimization {
|
||||||
*/
|
*/
|
||||||
const increaseSharedAndStoreOptimizationEntry = entry => {
|
const increaseSharedAndStoreOptimizationEntry = entry => {
|
||||||
if (entry.children !== undefined) {
|
if (entry.children !== undefined) {
|
||||||
entry.children.forEach(increaseSharedAndStoreOptimizationEntry);
|
for (const child of entry.children) {
|
||||||
|
increaseSharedAndStoreOptimizationEntry(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
entry.shared++;
|
entry.shared++;
|
||||||
storeOptimizationEntry(entry);
|
storeOptimizationEntry(entry);
|
||||||
|
@ -1573,7 +1575,7 @@ class FileSystemInfo {
|
||||||
case RBDT_RESOLVE_CJS: {
|
case RBDT_RESOLVE_CJS: {
|
||||||
const isDirectory = /[\\/]$/.test(path);
|
const isDirectory = /[\\/]$/.test(path);
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
resolveDirectory(path.slice(0, path.length - 1));
|
resolveDirectory(path.slice(0, -1));
|
||||||
} else {
|
} else {
|
||||||
resolveFile(path, "f", resolveCjs);
|
resolveFile(path, "f", resolveCjs);
|
||||||
}
|
}
|
||||||
|
@ -1582,7 +1584,7 @@ class FileSystemInfo {
|
||||||
case RBDT_RESOLVE_ESM: {
|
case RBDT_RESOLVE_ESM: {
|
||||||
const isDirectory = /[\\/]$/.test(path);
|
const isDirectory = /[\\/]$/.test(path);
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
resolveDirectory(path.slice(0, path.length - 1));
|
resolveDirectory(path.slice(0, -1));
|
||||||
} else {
|
} else {
|
||||||
resolveFile(path);
|
resolveFile(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,15 @@ class FlagDependencyExportsPlugin {
|
||||||
const exportsInfo = moduleGraph.getExportsInfo(module);
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
||||||
// If the module doesn't have an exportsType, it's a module
|
// If the module doesn't have an exportsType, it's a module
|
||||||
// without declared exports.
|
// without declared exports.
|
||||||
if (!module.buildMeta || !module.buildMeta.exportsType) {
|
if (
|
||||||
if (exportsInfo.otherExportsInfo.provided !== null) {
|
(!module.buildMeta || !module.buildMeta.exportsType) &&
|
||||||
// It's a module without declared exports
|
exportsInfo.otherExportsInfo.provided !== null
|
||||||
statNoExports++;
|
) {
|
||||||
exportsInfo.setHasProvideInfo();
|
// It's a module without declared exports
|
||||||
exportsInfo.setUnknownExportsProvided();
|
statNoExports++;
|
||||||
return callback();
|
exportsInfo.setHasProvideInfo();
|
||||||
}
|
exportsInfo.setUnknownExportsProvided();
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
// If the module has no hash, it's uncacheable
|
// If the module has no hash, it's uncacheable
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -130,8 +130,8 @@ class ByTypeGenerator extends Generator {
|
||||||
* @param {string=} type source type
|
* @param {string=} type source type
|
||||||
* @returns {number} estimate size of the module
|
* @returns {number} estimate size of the module
|
||||||
*/
|
*/
|
||||||
getSize(module, type) {
|
getSize(module, type = "javascript") {
|
||||||
const t = type || "javascript";
|
const t = type;
|
||||||
const generator = this.map[t];
|
const generator = this.map[t];
|
||||||
return generator ? generator.getSize(module, t) : 0;
|
return generator ? generator.getSize(module, t) : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ class HotModuleReplacementPlugin {
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const requests = [];
|
const requests = [];
|
||||||
if (params.length > 0) {
|
if (params.length > 0) {
|
||||||
params.forEach((param, idx) => {
|
for (const [idx, param] of params.entries()) {
|
||||||
const request = /** @type {string} */ (param.string);
|
const request = /** @type {string} */ (param.string);
|
||||||
const dep = new ParamDependency(
|
const dep = new ParamDependency(
|
||||||
request,
|
request,
|
||||||
|
@ -157,7 +157,7 @@ class HotModuleReplacementPlugin {
|
||||||
dep.loc.index = idx;
|
dep.loc.index = idx;
|
||||||
module.addDependency(dep);
|
module.addDependency(dep);
|
||||||
requests.push(request);
|
requests.push(request);
|
||||||
});
|
}
|
||||||
if (expr.arguments.length > 1) {
|
if (expr.arguments.length > 1) {
|
||||||
hotAcceptCallback.call(expr.arguments[1], requests);
|
hotAcceptCallback.call(expr.arguments[1], requests);
|
||||||
for (let i = 1; i < expr.arguments.length; i++) {
|
for (let i = 1; i < expr.arguments.length; i++) {
|
||||||
|
@ -201,7 +201,7 @@ class HotModuleReplacementPlugin {
|
||||||
/** @type {BasicEvaluatedExpression[]} */
|
/** @type {BasicEvaluatedExpression[]} */
|
||||||
(arg.items).filter(param => param.isString());
|
(arg.items).filter(param => param.isString());
|
||||||
}
|
}
|
||||||
params.forEach((param, idx) => {
|
for (const [idx, param] of params.entries()) {
|
||||||
const dep = new ParamDependency(
|
const dep = new ParamDependency(
|
||||||
/** @type {string} */ (param.string),
|
/** @type {string} */ (param.string),
|
||||||
/** @type {Range} */ (param.range)
|
/** @type {Range} */ (param.range)
|
||||||
|
@ -210,7 +210,7 @@ class HotModuleReplacementPlugin {
|
||||||
dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
|
dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
|
||||||
dep.loc.index = idx;
|
dep.loc.index = idx;
|
||||||
module.addDependency(dep);
|
module.addDependency(dep);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -649,12 +649,11 @@ class HotModuleReplacementPlugin {
|
||||||
for (const moduleRuntime of runtimes) {
|
for (const moduleRuntime of runtimes) {
|
||||||
if (typeof moduleRuntime === "string") {
|
if (typeof moduleRuntime === "string") {
|
||||||
if (moduleRuntime === runtime) return;
|
if (moduleRuntime === runtime) return;
|
||||||
} else if (moduleRuntime !== undefined) {
|
} else if (
|
||||||
if (
|
moduleRuntime !== undefined &&
|
||||||
moduleRuntime.has(/** @type {string} */ (runtime))
|
moduleRuntime.has(/** @type {string} */ (runtime))
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const item = hotUpdateMainContentByRuntime.get(
|
const item = hotUpdateMainContentByRuntime.get(
|
||||||
/** @type {string} */ (runtime)
|
/** @type {string} */ (runtime)
|
||||||
|
|
|
@ -55,6 +55,7 @@ class LibManifestPlugin {
|
||||||
const moduleGraph = compilation.moduleGraph;
|
const moduleGraph = compilation.moduleGraph;
|
||||||
// store used paths to detect issue and output an error. #18200
|
// store used paths to detect issue and output an error. #18200
|
||||||
const usedPaths = new Set();
|
const usedPaths = new Set();
|
||||||
|
// eslint-disable-next-line unicorn/no-array-for-each
|
||||||
asyncLib.forEach(
|
asyncLib.forEach(
|
||||||
Array.from(compilation.chunks),
|
Array.from(compilation.chunks),
|
||||||
(chunk, callback) => {
|
(chunk, callback) => {
|
||||||
|
|
|
@ -21,11 +21,7 @@ class ModuleBuildError extends WebpackError {
|
||||||
let message = "Module build failed";
|
let message = "Module build failed";
|
||||||
let details;
|
let details;
|
||||||
|
|
||||||
if (from) {
|
message += from ? ` (from ${from}):\n` : ": ";
|
||||||
message += ` (from ${from}):\n`;
|
|
||||||
} else {
|
|
||||||
message += ": ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err !== null && typeof err === "object") {
|
if (err !== null && typeof err === "object") {
|
||||||
if (typeof err.stack === "string" && err.stack) {
|
if (typeof err.stack === "string" && err.stack) {
|
||||||
|
@ -36,11 +32,8 @@ class ModuleBuildError extends WebpackError {
|
||||||
} else {
|
} else {
|
||||||
details = stack;
|
details = stack;
|
||||||
|
|
||||||
if (typeof err.message === "string" && err.message) {
|
message +=
|
||||||
message += err.message;
|
typeof err.message === "string" && err.message ? err.message : err;
|
||||||
} else {
|
|
||||||
message += err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (typeof err.message === "string" && err.message) {
|
} else if (typeof err.message === "string" && err.message) {
|
||||||
message += err.message;
|
message += err.message;
|
||||||
|
|
|
@ -20,11 +20,7 @@ class ModuleError extends WebpackError {
|
||||||
constructor(err, { from = null } = {}) {
|
constructor(err, { from = null } = {}) {
|
||||||
let message = "Module Error";
|
let message = "Module Error";
|
||||||
|
|
||||||
if (from) {
|
message += from ? ` (from ${from}):\n` : ": ";
|
||||||
message += ` (from ${from}):\n`;
|
|
||||||
} else {
|
|
||||||
message += ": ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err && typeof err === "object" && err.message) {
|
if (err && typeof err === "object" && err.message) {
|
||||||
message += err.message;
|
message += err.message;
|
||||||
|
|
|
@ -297,15 +297,15 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
||||||
const countMap = Object.create(null);
|
const countMap = Object.create(null);
|
||||||
const posMap = Object.create(null);
|
const posMap = Object.create(null);
|
||||||
|
|
||||||
array.forEach((item, idx) => {
|
for (const [idx, item] of array.entries()) {
|
||||||
countMap[item] = countMap[item] || [];
|
countMap[item] = countMap[item] || [];
|
||||||
countMap[item].push(idx);
|
countMap[item].push(idx);
|
||||||
posMap[item] = 0;
|
posMap[item] = 0;
|
||||||
});
|
}
|
||||||
if (comparator) {
|
if (comparator) {
|
||||||
Object.keys(countMap).forEach(item => {
|
for (const item of Object.keys(countMap)) {
|
||||||
countMap[item].sort(comparator);
|
countMap[item].sort(comparator);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
return array.map((item, i) => {
|
return array.map((item, i) => {
|
||||||
if (countMap[item].length > 1) {
|
if (countMap[item].length > 1) {
|
||||||
|
@ -370,20 +370,14 @@ ModuleFilenameHelpers.matchPart = (str, test) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
ModuleFilenameHelpers.matchObject = (obj, str) => {
|
ModuleFilenameHelpers.matchObject = (obj, str) => {
|
||||||
if (obj.test) {
|
if (obj.test && !ModuleFilenameHelpers.matchPart(str, obj.test)) {
|
||||||
if (!ModuleFilenameHelpers.matchPart(str, obj.test)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (obj.include) {
|
if (obj.include && !ModuleFilenameHelpers.matchPart(str, obj.include)) {
|
||||||
if (!ModuleFilenameHelpers.matchPart(str, obj.include)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (obj.exclude) {
|
if (obj.exclude && ModuleFilenameHelpers.matchPart(str, obj.exclude)) {
|
||||||
if (ModuleFilenameHelpers.matchPart(str, obj.exclude)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -445,7 +445,7 @@ class ModuleGraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._dependencyMap.set(dependency, null);
|
this._dependencyMap.set(dependency, null);
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
return connection === null ? undefined : connection;
|
return connection === null ? undefined : connection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,12 +234,8 @@ class ModuleInfoHeaderPlugin {
|
||||||
moduleGraph.getOptimizationBailout(module);
|
moduleGraph.getOptimizationBailout(module);
|
||||||
if (optimizationBailout) {
|
if (optimizationBailout) {
|
||||||
for (const text of optimizationBailout) {
|
for (const text of optimizationBailout) {
|
||||||
let code;
|
const code =
|
||||||
if (typeof text === "function") {
|
typeof text === "function" ? text(requestShortener) : text;
|
||||||
code = text(requestShortener);
|
|
||||||
} else {
|
|
||||||
code = text;
|
|
||||||
}
|
|
||||||
source.add(`${Template.toComment(`${code}`)}\n`);
|
source.add(`${Template.toComment(`${code}`)}\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,7 @@ class ModuleWarning extends WebpackError {
|
||||||
constructor(warning, { from = null } = {}) {
|
constructor(warning, { from = null } = {}) {
|
||||||
let message = "Module Warning";
|
let message = "Module Warning";
|
||||||
|
|
||||||
if (from) {
|
message += from ? ` (from ${from}):\n` : ": ";
|
||||||
message += ` (from ${from}):\n`;
|
|
||||||
} else {
|
|
||||||
message += ": ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warning && typeof warning === "object" && warning.message) {
|
if (warning && typeof warning === "object" && warning.message) {
|
||||||
message += warning.message;
|
message += warning.message;
|
||||||
|
|
|
@ -511,7 +511,7 @@ module.exports = class MultiCompiler {
|
||||||
|
|
||||||
/** @type {SetupResult[]} */
|
/** @type {SetupResult[]} */
|
||||||
const setupResults = [];
|
const setupResults = [];
|
||||||
nodes.forEach((node, i) => {
|
for (const [i, node] of nodes.entries()) {
|
||||||
setupResults.push(
|
setupResults.push(
|
||||||
(node.setupResult = setup(
|
(node.setupResult = setup(
|
||||||
node.compiler,
|
node.compiler,
|
||||||
|
@ -522,7 +522,7 @@ module.exports = class MultiCompiler {
|
||||||
() => nodeInvalid(node)
|
() => nodeInvalid(node)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
let processing = true;
|
let processing = true;
|
||||||
const processQueue = () => {
|
const processQueue = () => {
|
||||||
if (processing) return;
|
if (processing) return;
|
||||||
|
|
|
@ -62,6 +62,7 @@ class MultiWatching {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
close(callback) {
|
close(callback) {
|
||||||
|
// eslint-disable-next-line unicorn/no-array-for-each
|
||||||
asyncLib.forEach(
|
asyncLib.forEach(
|
||||||
this.watchings,
|
this.watchings,
|
||||||
(watching, finishedCallback) => {
|
(watching, finishedCallback) => {
|
||||||
|
|
|
@ -150,7 +150,7 @@ const needCalls = (times, callback) => err => {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
if (err && times > 0) {
|
if (err && times > 0) {
|
||||||
times = NaN;
|
times = Number.NaN;
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -171,11 +171,8 @@ const mergeGlobalOptions = (globalOptions, type, localOptions) => {
|
||||||
current = current ? `${current}/${part}` : part;
|
current = current ? `${current}/${part}` : part;
|
||||||
const options = globalOptions[current];
|
const options = globalOptions[current];
|
||||||
if (typeof options === "object") {
|
if (typeof options === "object") {
|
||||||
if (result === undefined) {
|
result =
|
||||||
result = options;
|
result === undefined ? options : cachedCleverMerge(result, options);
|
||||||
} else {
|
|
||||||
result = cachedCleverMerge(result, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
|
@ -1063,11 +1060,9 @@ Add the extension to the request.`
|
||||||
/(\.[^.]+)(\?|$)/,
|
/(\.[^.]+)(\?|$)/,
|
||||||
"$2"
|
"$2"
|
||||||
);
|
);
|
||||||
if (resolver.options.extensions.has(match[1])) {
|
hint = resolver.options.extensions.has(match[1])
|
||||||
hint = `Did you mean '${fixedRequest}'?`;
|
? `Did you mean '${fixedRequest}'?`
|
||||||
} else {
|
: `Did you mean '${fixedRequest}'? Also note that '${match[1]}' is not in 'resolve.extensions' yet and need to be added for this to work?`;
|
||||||
hint = `Did you mean '${fixedRequest}'? Also note that '${match[1]}' is not in 'resolve.extensions' yet and need to be added for this to work?`;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
hint =
|
hint =
|
||||||
"Did you mean to omit the extension or to remove 'resolve.enforceExtension'?";
|
"Did you mean to omit the extension or to remove 'resolve.enforceExtension'?";
|
||||||
|
|
|
@ -507,7 +507,7 @@ class ProgressPlugin {
|
||||||
afterSeal: "after seal"
|
afterSeal: "after seal"
|
||||||
};
|
};
|
||||||
const numberOfHooks = Object.keys(hooks).length;
|
const numberOfHooks = Object.keys(hooks).length;
|
||||||
Object.keys(hooks).forEach((name, idx) => {
|
for (const [idx, name] of Object.keys(hooks).entries()) {
|
||||||
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
||||||
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
||||||
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
||||||
|
@ -534,7 +534,7 @@ class ProgressPlugin {
|
||||||
handler(percentage, "sealing", title, tap.name);
|
handler(percentage, "sealing", title, tap.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
compiler.hooks.make.intercept({
|
compiler.hooks.make.intercept({
|
||||||
name: "ProgressPlugin",
|
name: "ProgressPlugin",
|
||||||
|
|
|
@ -58,16 +58,16 @@ class ProvidePlugin {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const handler = (parser, parserOptions) => {
|
const handler = (parser, parserOptions) => {
|
||||||
Object.keys(definitions).forEach(name => {
|
for (const name of Object.keys(definitions)) {
|
||||||
const request =
|
const request =
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
([]).concat(definitions[name]);
|
([]).concat(definitions[name]);
|
||||||
const splittedName = name.split(".");
|
const splittedName = name.split(".");
|
||||||
if (splittedName.length > 0) {
|
if (splittedName.length > 0) {
|
||||||
splittedName.slice(1).forEach((_, i) => {
|
for (const [i, _] of splittedName.slice(1).entries()) {
|
||||||
const name = splittedName.slice(0, i + 1).join(".");
|
const name = splittedName.slice(0, i + 1).join(".");
|
||||||
parser.hooks.canRename.for(name).tap(PLUGIN_NAME, approve);
|
parser.hooks.canRename.for(name).tap(PLUGIN_NAME, approve);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.hooks.expression.for(name).tap(PLUGIN_NAME, expr => {
|
parser.hooks.expression.for(name).tap(PLUGIN_NAME, expr => {
|
||||||
|
@ -100,7 +100,7 @@ class ProvidePlugin {
|
||||||
parser.walkExpressions(expr.arguments);
|
parser.walkExpressions(expr.arguments);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
normalModuleFactory.hooks.parser
|
normalModuleFactory.hooks.parser
|
||||||
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
||||||
|
|
|
@ -67,11 +67,11 @@ function getGlobalObject(definition) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
// identifier, we do not need real identifier regarding ECMAScript/Unicode
|
// identifier, we do not need real identifier regarding ECMAScript/Unicode
|
||||||
trimmed.match(/^[_\p{L}][_0-9\p{L}]*$/iu) ||
|
/^[_\p{L}][_0-9\p{L}]*$/iu.test(trimmed) ||
|
||||||
// iife
|
// iife
|
||||||
// call expression
|
// call expression
|
||||||
// expression in parentheses
|
// expression in parentheses
|
||||||
trimmed.match(/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu)
|
/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
|
||||||
)
|
)
|
||||||
return trimmed;
|
return trimmed;
|
||||||
|
|
||||||
|
|
|
@ -442,12 +442,9 @@ class SourceMapDevToolPlugin {
|
||||||
// If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
|
// If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
|
||||||
if (usesContentHash && task.assetInfo.contenthash) {
|
if (usesContentHash && task.assetInfo.contenthash) {
|
||||||
const contenthash = task.assetInfo.contenthash;
|
const contenthash = task.assetInfo.contenthash;
|
||||||
let pattern;
|
const pattern = Array.isArray(contenthash)
|
||||||
if (Array.isArray(contenthash)) {
|
? contenthash.map(quoteMeta).join("|")
|
||||||
pattern = contenthash.map(quoteMeta).join("|");
|
: quoteMeta(contenthash);
|
||||||
} else {
|
|
||||||
pattern = quoteMeta(contenthash);
|
|
||||||
}
|
|
||||||
sourceMap.file = sourceMap.file.replace(
|
sourceMap.file = sourceMap.file.replace(
|
||||||
new RegExp(pattern, "g"),
|
new RegExp(pattern, "g"),
|
||||||
m => "x".repeat(m.length)
|
m => "x".repeat(m.length)
|
||||||
|
|
|
@ -55,7 +55,7 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
|
||||||
/** @type {ReplacerFunction} */
|
/** @type {ReplacerFunction} */
|
||||||
const fn = (match, arg, input) => {
|
const fn = (match, arg, input) => {
|
||||||
let result;
|
let result;
|
||||||
const length = arg && parseInt(arg, 10);
|
const length = arg && Number.parseInt(arg, 10);
|
||||||
|
|
||||||
if (length && handler) {
|
if (length && handler) {
|
||||||
result = handler(length);
|
result = handler(length);
|
||||||
|
|
|
@ -155,28 +155,23 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
}).apply(compiler);
|
}).apply(compiler);
|
||||||
} else if (options.externalsPresets.node) {
|
} else if (options.externalsPresets.node && options.experiments.css) {
|
||||||
if (options.experiments.css) {
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
||||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
||||||
const ExternalsPlugin = require("./ExternalsPlugin");
|
new ExternalsPlugin("module", ({ request, dependencyType }, callback) => {
|
||||||
new ExternalsPlugin(
|
if (dependencyType === "url") {
|
||||||
"module",
|
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
||||||
({ request, dependencyType }, callback) => {
|
return callback(null, `asset ${request}`);
|
||||||
if (dependencyType === "url") {
|
} else if (dependencyType === "css-import") {
|
||||||
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
||||||
return callback(null, `asset ${request}`);
|
return callback(null, `css-import ${request}`);
|
||||||
} else if (dependencyType === "css-import") {
|
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
||||||
if (/^(\/\/|https?:\/\/|#)/.test(request))
|
if (/^\.css(\?|$)/.test(request))
|
||||||
return callback(null, `css-import ${request}`);
|
return callback(null, `css-import ${request}`);
|
||||||
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
|
return callback(null, `module ${request}`);
|
||||||
if (/^\.css(\?|$)/.test(request))
|
}
|
||||||
return callback(null, `css-import ${request}`);
|
callback();
|
||||||
return callback(null, `module ${request}`);
|
}).apply(compiler);
|
||||||
}
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
).apply(compiler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new ChunkPrefetchPreloadPlugin().apply(compiler);
|
new ChunkPrefetchPreloadPlugin().apply(compiler);
|
||||||
|
@ -606,7 +601,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const cacheOptions = options.cache;
|
const cacheOptions = options.cache;
|
||||||
switch (cacheOptions.type) {
|
switch (cacheOptions.type) {
|
||||||
case "memory": {
|
case "memory": {
|
||||||
if (isFinite(cacheOptions.maxGenerations)) {
|
if (Number.isFinite(cacheOptions.maxGenerations)) {
|
||||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
||||||
const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
|
const MemoryWithGcCachePlugin = require("./cache/MemoryWithGcCachePlugin");
|
||||||
new MemoryWithGcCachePlugin({
|
new MemoryWithGcCachePlugin({
|
||||||
|
@ -634,7 +629,7 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const list = cacheOptions.buildDependencies[key];
|
const list = cacheOptions.buildDependencies[key];
|
||||||
new AddBuildDependenciesPlugin(list).apply(compiler);
|
new AddBuildDependenciesPlugin(list).apply(compiler);
|
||||||
}
|
}
|
||||||
if (!isFinite(cacheOptions.maxMemoryGenerations)) {
|
if (!Number.isFinite(cacheOptions.maxMemoryGenerations)) {
|
||||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
||||||
const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
||||||
new MemoryCachePlugin().apply(compiler);
|
new MemoryCachePlugin().apply(compiler);
|
||||||
|
|
|
@ -255,13 +255,12 @@ class AssetGenerator extends Generator {
|
||||||
} else {
|
} else {
|
||||||
/** @type {string | false | undefined} */
|
/** @type {string | false | undefined} */
|
||||||
let encoding = this.dataUrlOptions.encoding;
|
let encoding = this.dataUrlOptions.encoding;
|
||||||
if (encoding === undefined) {
|
if (
|
||||||
if (
|
encoding === undefined &&
|
||||||
module.resourceResolveData &&
|
module.resourceResolveData &&
|
||||||
module.resourceResolveData.encoding !== undefined
|
module.resourceResolveData.encoding !== undefined
|
||||||
) {
|
) {
|
||||||
encoding = module.resourceResolveData.encoding;
|
encoding = module.resourceResolveData.encoding;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (encoding === undefined) {
|
if (encoding === undefined) {
|
||||||
encoding = DEFAULT_ENCODING;
|
encoding = DEFAULT_ENCODING;
|
||||||
|
|
|
@ -34,13 +34,8 @@ class AssetSourceGenerator extends Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = originalSource.source();
|
const content = originalSource.source();
|
||||||
|
const encodedSource =
|
||||||
let encodedSource;
|
typeof content === "string" ? content : content.toString("utf-8");
|
||||||
if (typeof content === "string") {
|
|
||||||
encodedSource = content;
|
|
||||||
} else {
|
|
||||||
encodedSource = content.toString("utf-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
let sourceContent;
|
let sourceContent;
|
||||||
if (concatenationScope) {
|
if (concatenationScope) {
|
||||||
|
|
|
@ -160,7 +160,7 @@ class Pack {
|
||||||
const info = this.itemInfo.get(identifier);
|
const info = this.itemInfo.get(identifier);
|
||||||
this._addRequest(identifier);
|
this._addRequest(identifier);
|
||||||
if (info === undefined) {
|
if (info === undefined) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
if (info.etag !== etag) return null;
|
if (info.etag !== etag) return null;
|
||||||
info.lastAccess = Date.now();
|
info.lastAccess = Date.now();
|
||||||
|
@ -169,7 +169,7 @@ class Pack {
|
||||||
return info.freshValue;
|
return info.freshValue;
|
||||||
}
|
}
|
||||||
if (!this.content[loc]) {
|
if (!this.content[loc]) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
return /** @type {PackContent} */ (this.content[loc]).get(identifier);
|
return /** @type {PackContent} */ (this.content[loc]).get(identifier);
|
||||||
}
|
}
|
||||||
|
@ -1146,19 +1146,19 @@ class PackFileCacheStrategy {
|
||||||
})
|
})
|
||||||
.then(packContainer => {
|
.then(packContainer => {
|
||||||
logger.timeEnd("restore cache container");
|
logger.timeEnd("restore cache container");
|
||||||
if (!packContainer) return undefined;
|
if (!packContainer) return;
|
||||||
if (!(packContainer instanceof PackContainer)) {
|
if (!(packContainer instanceof PackContainer)) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Restored pack from ${cacheLocation}${this._extension}, but contained content is unexpected.`,
|
`Restored pack from ${cacheLocation}${this._extension}, but contained content is unexpected.`,
|
||||||
packContainer
|
packContainer
|
||||||
);
|
);
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
if (packContainer.version !== version) {
|
if (packContainer.version !== version) {
|
||||||
logger.log(
|
logger.log(
|
||||||
`Restored pack from ${cacheLocation}${this._extension}, but version doesn't match.`
|
`Restored pack from ${cacheLocation}${this._extension}, but version doesn't match.`
|
||||||
);
|
);
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
logger.time("check build dependencies");
|
logger.time("check build dependencies");
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
|
|
@ -59,11 +59,10 @@ const objectToString = (object, excludeContext) => {
|
||||||
for (const key in object) {
|
for (const key in object) {
|
||||||
if (excludeContext && key === "context") continue;
|
if (excludeContext && key === "context") continue;
|
||||||
const value = object[key];
|
const value = object[key];
|
||||||
if (typeof value === "object" && value !== null) {
|
str +=
|
||||||
str += `|${key}=[${objectToString(value, false)}|]`;
|
typeof value === "object" && value !== null
|
||||||
} else {
|
? `|${key}=[${objectToString(value, false)}|]`
|
||||||
str += `|${key}=|${value}`;
|
: `|${key}=|${value}`;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
|
@ -565,7 +565,7 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
||||||
if (typeof value === "number") return value;
|
if (typeof value === "number") return value;
|
||||||
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
|
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
|
||||||
const n = Number(value);
|
const n = Number(value);
|
||||||
if (!isNaN(n)) return n;
|
if (!Number.isNaN(n)) return n;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
|
|
|
@ -534,7 +534,7 @@ const getNormalizedEntryStatic = entry => {
|
||||||
* @returns {OptimizationRuntimeChunkNormalized=} normalized runtimeChunk option
|
* @returns {OptimizationRuntimeChunkNormalized=} normalized runtimeChunk option
|
||||||
*/
|
*/
|
||||||
const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
|
const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
|
||||||
if (runtimeChunk === undefined) return undefined;
|
if (runtimeChunk === undefined) return;
|
||||||
if (runtimeChunk === false) return false;
|
if (runtimeChunk === false) return false;
|
||||||
if (runtimeChunk === "single") {
|
if (runtimeChunk === "single") {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -128,7 +128,10 @@ class CssExportsGenerator extends Generator {
|
||||||
|
|
||||||
template.apply(dependency, source, templateContext);
|
template.apply(dependency, source, templateContext);
|
||||||
};
|
};
|
||||||
module.dependencies.forEach(handleDependency);
|
|
||||||
|
for (const dependency of module.dependencies) {
|
||||||
|
handleDependency(dependency);
|
||||||
|
}
|
||||||
|
|
||||||
if (generateContext.concatenationScope) {
|
if (generateContext.concatenationScope) {
|
||||||
const source = new ConcatSource();
|
const source = new ConcatSource();
|
||||||
|
|
|
@ -101,9 +101,14 @@ class CssGenerator extends Generator {
|
||||||
|
|
||||||
template.apply(dependency, source, templateContext);
|
template.apply(dependency, source, templateContext);
|
||||||
};
|
};
|
||||||
module.dependencies.forEach(handleDependency);
|
for (const dependency of module.dependencies) {
|
||||||
if (module.presentationalDependencies !== undefined)
|
handleDependency(dependency);
|
||||||
module.presentationalDependencies.forEach(handleDependency);
|
}
|
||||||
|
if (module.presentationalDependencies !== undefined) {
|
||||||
|
for (const dependency of module.presentationalDependencies) {
|
||||||
|
handleDependency(dependency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const data = generateContext.getData();
|
const data = generateContext.getData();
|
||||||
data.set("css-exports", cssExportsData);
|
data.set("css-exports", cssExportsData);
|
||||||
|
|
|
@ -224,7 +224,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
||||||
withCompression
|
withCompression
|
||||||
? Template.asString([
|
? Template.asString([
|
||||||
// LZW decode
|
// LZW decode
|
||||||
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uffff".charCodeAt(
|
`var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uFFFF".charCodeAt(
|
||||||
0
|
0
|
||||||
)}, phrase;`,
|
)}, phrase;`,
|
||||||
"for (i = 1; i < data.length; i++) {",
|
"for (i = 1; i < data.length; i++) {",
|
||||||
|
|
|
@ -128,7 +128,7 @@ const validateParserOptions = {
|
||||||
const escapeCss = (str, omitOptionalUnderscore) => {
|
const escapeCss = (str, omitOptionalUnderscore) => {
|
||||||
const escaped = `${str}`.replace(
|
const escaped = `${str}`.replace(
|
||||||
// cspell:word uffff
|
// cspell:word uffff
|
||||||
/[^a-zA-Z0-9_\u0081-\uffff-]/g,
|
/[^a-zA-Z0-9_\u0081-\uFFFF-]/g,
|
||||||
s => `\\${s}`
|
s => `\\${s}`
|
||||||
);
|
);
|
||||||
return !omitOptionalUnderscore && /^(?!--)[0-9_-]/.test(escaped)
|
return !omitOptionalUnderscore && /^(?!--)[0-9_-]/.test(escaped)
|
||||||
|
@ -146,7 +146,7 @@ const lzwEncode = str => {
|
||||||
let encoded = "";
|
let encoded = "";
|
||||||
let phrase = str[0];
|
let phrase = str[0];
|
||||||
let code = 256;
|
let code = 256;
|
||||||
const maxCode = "\uffff".charCodeAt(0);
|
const maxCode = "\uFFFF".charCodeAt(0);
|
||||||
for (let i = 1; i < str.length; i++) {
|
for (let i = 1; i < str.length; i++) {
|
||||||
const c = str[i];
|
const c = str[i];
|
||||||
if (map.has(phrase + c)) {
|
if (map.has(phrase + c)) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ const normalizeUrl = (str, isString) => {
|
||||||
// Unescape
|
// Unescape
|
||||||
.replace(UNESCAPE, match => {
|
.replace(UNESCAPE, match => {
|
||||||
if (match.length > 2) {
|
if (match.length > 2) {
|
||||||
return String.fromCharCode(parseInt(match.slice(1).trim(), 16));
|
return String.fromCharCode(Number.parseInt(match.slice(1).trim(), 16));
|
||||||
}
|
}
|
||||||
return match[1];
|
return match[1];
|
||||||
});
|
});
|
||||||
|
@ -171,7 +171,7 @@ class CssParser extends Parser {
|
||||||
} else if (typeof source === "object") {
|
} else if (typeof source === "object") {
|
||||||
throw new Error("webpackAst is unexpected for the CssParser");
|
throw new Error("webpackAst is unexpected for the CssParser");
|
||||||
}
|
}
|
||||||
if (source[0] === "\ufeff") {
|
if (source[0] === "\uFEFF") {
|
||||||
source = source.slice(1);
|
source = source.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,9 @@ class CssParser extends Parser {
|
||||||
{ length: charCodes.reduce((a, b) => Math.max(a, b), 0) + 1 },
|
{ length: charCodes.reduce((a, b) => Math.max(a, b), 0) + 1 },
|
||||||
() => false
|
() => false
|
||||||
);
|
);
|
||||||
charCodes.forEach(cc => (arr[cc] = true));
|
for (const cc of charCodes) {
|
||||||
|
arr[cc] = true;
|
||||||
|
}
|
||||||
return (input, pos) => {
|
return (input, pos) => {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const cc = input.charCodeAt(pos);
|
const cc = input.charCodeAt(pos);
|
||||||
|
|
|
@ -233,19 +233,19 @@ class ProfilingPlugin {
|
||||||
tracer.profiler.startProfiling();
|
tracer.profiler.startProfiling();
|
||||||
|
|
||||||
// Compiler Hooks
|
// Compiler Hooks
|
||||||
Object.keys(compiler.hooks).forEach(hookName => {
|
for (const hookName of Object.keys(compiler.hooks)) {
|
||||||
const hook = compiler.hooks[hookName];
|
const hook = compiler.hooks[hookName];
|
||||||
if (hook) {
|
if (hook) {
|
||||||
hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
|
hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
|
for (const hookName of Object.keys(compiler.resolverFactory.hooks)) {
|
||||||
const hook = compiler.resolverFactory.hooks[hookName];
|
const hook = compiler.resolverFactory.hooks[hookName];
|
||||||
if (hook) {
|
if (hook) {
|
||||||
hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
|
hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
compiler.hooks.compilation.tap(
|
compiler.hooks.compilation.tap(
|
||||||
PLUGIN_NAME,
|
PLUGIN_NAME,
|
||||||
|
@ -340,12 +340,12 @@ class ProfilingPlugin {
|
||||||
*/
|
*/
|
||||||
const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
||||||
if (Reflect.has(instance, "hooks")) {
|
if (Reflect.has(instance, "hooks")) {
|
||||||
Object.keys(instance.hooks).forEach(hookName => {
|
for (const hookName of Object.keys(instance.hooks)) {
|
||||||
const hook = instance.hooks[hookName];
|
const hook = instance.hooks[hookName];
|
||||||
if (hook && !hook._fakeHook) {
|
if (hook && !hook._fakeHook) {
|
||||||
hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
|
hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -363,13 +363,13 @@ const interceptAllParserHooks = (moduleFactory, tracer) => {
|
||||||
WEBASSEMBLY_MODULE_TYPE_SYNC
|
WEBASSEMBLY_MODULE_TYPE_SYNC
|
||||||
];
|
];
|
||||||
|
|
||||||
moduleTypes.forEach(moduleType => {
|
for (const moduleType of moduleTypes) {
|
||||||
moduleFactory.hooks.parser
|
moduleFactory.hooks.parser
|
||||||
.for(moduleType)
|
.for(moduleType)
|
||||||
.tap(PLUGIN_NAME, (parser, parserOpts) => {
|
.tap(PLUGIN_NAME, (parser, parserOpts) => {
|
||||||
interceptAllHooksFor(parser, tracer, "Parser");
|
interceptAllHooksFor(parser, tracer, "Parser");
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -114,7 +114,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
||||||
const deps = [];
|
const deps = [];
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
(param.array).forEach((request, idx) => {
|
for (const [idx, request] of param.array.entries()) {
|
||||||
let dep;
|
let dep;
|
||||||
let localModule;
|
let localModule;
|
||||||
if (request === "require") {
|
if (request === "require") {
|
||||||
|
@ -135,7 +135,7 @@ class AMDDefineDependencyParserPlugin {
|
||||||
parser.state.current.addDependency(dep);
|
parser.state.current.addDependency(dep);
|
||||||
}
|
}
|
||||||
deps.push(dep);
|
deps.push(dep);
|
||||||
});
|
}
|
||||||
const dep = this.newRequireArrayDependency(
|
const dep = this.newRequireArrayDependency(
|
||||||
deps,
|
deps,
|
||||||
/** @type {Range} */ (param.range)
|
/** @type {Range} */ (param.range)
|
||||||
|
@ -156,13 +156,14 @@ class AMDDefineDependencyParserPlugin {
|
||||||
*/
|
*/
|
||||||
processItem(parser, expr, param, namedModule) {
|
processItem(parser, expr, param, namedModule) {
|
||||||
if (param.isConditional()) {
|
if (param.isConditional()) {
|
||||||
/** @type {BasicEvaluatedExpression[]} */
|
const options = /** @type {BasicEvaluatedExpression[]} */ (param.options);
|
||||||
(param.options).forEach(param => {
|
for (const item of options) {
|
||||||
const result = this.processItem(parser, expr, param);
|
const result = this.processItem(parser, expr, item);
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
this.processContext(parser, expr, param);
|
this.processContext(parser, expr, item);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (param.isString()) {
|
} else if (param.isString()) {
|
||||||
let dep;
|
let dep;
|
||||||
|
|
|
@ -302,7 +302,7 @@ class CommonJsExportsParserPlugin {
|
||||||
* @param {CallExpression=} call call expression
|
* @param {CallExpression=} call call expression
|
||||||
* @returns {boolean | void} true, when the expression was handled
|
* @returns {boolean | void} true, when the expression was handled
|
||||||
*/
|
*/
|
||||||
const handleAccessExport = (expr, base, members, call = undefined) => {
|
const handleAccessExport = (expr, base, members, call) => {
|
||||||
if (HarmonyExports.isEnabled(parser.state)) return;
|
if (HarmonyExports.isEnabled(parser.state)) return;
|
||||||
if (members.length === 0) {
|
if (members.length === 0) {
|
||||||
bailout(
|
bailout(
|
||||||
|
|
|
@ -288,19 +288,17 @@ class CommonJsImportsParserPlugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requireOptions) {
|
if (requireOptions && requireOptions.webpackIgnore !== undefined) {
|
||||||
if (requireOptions.webpackIgnore !== undefined) {
|
if (typeof requireOptions.webpackIgnore !== "boolean") {
|
||||||
if (typeof requireOptions.webpackIgnore !== "boolean") {
|
parser.state.module.addWarning(
|
||||||
parser.state.module.addWarning(
|
new UnsupportedFeatureWarning(
|
||||||
new UnsupportedFeatureWarning(
|
`\`webpackIgnore\` expected a boolean, but received: ${requireOptions.webpackIgnore}.`,
|
||||||
`\`webpackIgnore\` expected a boolean, but received: ${requireOptions.webpackIgnore}.`,
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
)
|
||||||
)
|
);
|
||||||
);
|
} else if (requireOptions.webpackIgnore) {
|
||||||
} else if (requireOptions.webpackIgnore) {
|
// Do not instrument `require()` if `webpackIgnore` is `true`
|
||||||
// Do not instrument `require()` if `webpackIgnore` is `true`
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,12 +108,10 @@ CommonJsSelfReferenceDependency.Template = class CommonJsSelfReferenceDependency
|
||||||
{ module, moduleGraph, runtime, runtimeRequirements }
|
{ module, moduleGraph, runtime, runtimeRequirements }
|
||||||
) {
|
) {
|
||||||
const dep = /** @type {CommonJsSelfReferenceDependency} */ (dependency);
|
const dep = /** @type {CommonJsSelfReferenceDependency} */ (dependency);
|
||||||
let used;
|
const used =
|
||||||
if (dep.names.length === 0) {
|
dep.names.length === 0
|
||||||
used = dep.names;
|
? dep.names
|
||||||
} else {
|
: moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime);
|
||||||
used = moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime);
|
|
||||||
}
|
|
||||||
if (!used) {
|
if (!used) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Self-reference dependency has unused export name: This should not happen"
|
"Self-reference dependency has unused export name: This should not happen"
|
||||||
|
|
|
@ -82,7 +82,7 @@ module.exports.create = (
|
||||||
|
|
||||||
// When there are more than two quasis, the generated RegExp can be more precise
|
// When there are more than two quasis, the generated RegExp can be more precise
|
||||||
// We join the quasis with the expression regexp
|
// We join the quasis with the expression regexp
|
||||||
const innerQuasis = quasis.slice(1, quasis.length - 1);
|
const innerQuasis = quasis.slice(1, -1);
|
||||||
const innerRegExp =
|
const innerRegExp =
|
||||||
/** @type {RegExp} */ (options.wrappedContextRegExp).source +
|
/** @type {RegExp} */ (options.wrappedContextRegExp).source +
|
||||||
innerQuasis
|
innerQuasis
|
||||||
|
@ -123,14 +123,14 @@ module.exports.create = (
|
||||||
const replaces = [];
|
const replaces = [];
|
||||||
const parts = /** @type {BasicEvaluatedExpression[]} */ (param.parts);
|
const parts = /** @type {BasicEvaluatedExpression[]} */ (param.parts);
|
||||||
|
|
||||||
parts.forEach((part, i) => {
|
for (const [i, part] of parts.entries()) {
|
||||||
if (i % 2 === 0) {
|
if (i % 2 === 0) {
|
||||||
// Quasis or merged quasi
|
// Quasis or merged quasi
|
||||||
let range = /** @type {Range} */ (part.range);
|
let range = /** @type {Range} */ (part.range);
|
||||||
let value = /** @type {string} */ (part.string);
|
let value = /** @type {string} */ (part.string);
|
||||||
if (param.templateStringKind === "cooked") {
|
if (param.templateStringKind === "cooked") {
|
||||||
value = JSON.stringify(value);
|
value = JSON.stringify(value);
|
||||||
value = value.slice(1, value.length - 1);
|
value = value.slice(1, -1);
|
||||||
}
|
}
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
// prefix
|
// prefix
|
||||||
|
@ -156,7 +156,7 @@ module.exports.create = (
|
||||||
part.expression.value.raw === value
|
part.expression.value.raw === value
|
||||||
) {
|
) {
|
||||||
// Shortcut when it's a single quasi and doesn't need to be replaced
|
// Shortcut when it's a single quasi and doesn't need to be replaced
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
replaces.push({
|
replaces.push({
|
||||||
range,
|
range,
|
||||||
|
@ -166,7 +166,7 @@ module.exports.create = (
|
||||||
// Expression
|
// Expression
|
||||||
parser.walkExpression(part.expression);
|
parser.walkExpression(part.expression);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
dep.replaces = replaces;
|
dep.replaces = replaces;
|
||||||
dep.critical =
|
dep.critical =
|
||||||
|
|
|
@ -178,7 +178,7 @@ class CssLocalIdentifierDependency extends NullDependency {
|
||||||
const escapeCssIdentifier = (str, omitUnderscore) => {
|
const escapeCssIdentifier = (str, omitUnderscore) => {
|
||||||
const escaped = `${str}`.replace(
|
const escaped = `${str}`.replace(
|
||||||
// cspell:word uffff
|
// cspell:word uffff
|
||||||
/[^a-zA-Z0-9_\u0081-\uffff-]/g,
|
/[^a-zA-Z0-9_\u0081-\uFFFF-]/g,
|
||||||
s => `\\${s}`
|
s => `\\${s}`
|
||||||
);
|
);
|
||||||
return !omitUnderscore && /^(?!--)[0-9-]/.test(escaped)
|
return !omitUnderscore && /^(?!--)[0-9-]/.test(escaped)
|
||||||
|
|
|
@ -72,7 +72,7 @@ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
|
||||||
case UsageState.Unused:
|
case UsageState.Unused:
|
||||||
return false;
|
return false;
|
||||||
case UsageState.NoInfo:
|
case UsageState.NoInfo:
|
||||||
return undefined;
|
return;
|
||||||
case UsageState.Unknown:
|
case UsageState.Unknown:
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
|
@ -82,7 +82,6 @@ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
|
||||||
case "provideInfo":
|
case "provideInfo":
|
||||||
return moduleGraph.getExportsInfo(module).isExportProvided(exportName);
|
return moduleGraph.getExportsInfo(module).isExportProvided(exportName);
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExportsInfoDependency extends NullDependency {
|
class ExportsInfoDependency extends NullDependency {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class HarmonyAcceptImportDependency extends HarmonyImportDependency {
|
||||||
* @param {string} request the request string
|
* @param {string} request the request string
|
||||||
*/
|
*/
|
||||||
constructor(request) {
|
constructor(request) {
|
||||||
super(request, NaN);
|
super(request, Number.NaN);
|
||||||
this.weak = true;
|
this.weak = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,11 +112,10 @@ HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImpor
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "namespace": {
|
case "namespace": {
|
||||||
if (ids[0] === "__esModule") {
|
value =
|
||||||
value = ids.length === 1 || undefined;
|
ids[0] === "__esModule"
|
||||||
} else {
|
? ids.length === 1 || undefined
|
||||||
value = exportsInfo.isExportProvided(ids);
|
: exportsInfo.isExportProvided(ids);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "dynamic": {
|
case "dynamic": {
|
||||||
|
|
|
@ -145,26 +145,23 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
||||||
"HarmonyExportDependencyParserPlugin",
|
"HarmonyExportDependencyParserPlugin",
|
||||||
(statement, id, name, idx) => {
|
(statement, id, name, idx) => {
|
||||||
const settings = parser.getTagData(id, harmonySpecifierTag);
|
const settings = parser.getTagData(id, harmonySpecifierTag);
|
||||||
let dep;
|
|
||||||
const harmonyNamedExports = (parser.state.harmonyNamedExports =
|
const harmonyNamedExports = (parser.state.harmonyNamedExports =
|
||||||
parser.state.harmonyNamedExports || new Set());
|
parser.state.harmonyNamedExports || new Set());
|
||||||
harmonyNamedExports.add(name);
|
harmonyNamedExports.add(name);
|
||||||
InnerGraph.addVariableUsage(parser, id, name);
|
InnerGraph.addVariableUsage(parser, id, name);
|
||||||
if (settings) {
|
const dep = settings
|
||||||
dep = new HarmonyExportImportedSpecifierDependency(
|
? new HarmonyExportImportedSpecifierDependency(
|
||||||
settings.source,
|
settings.source,
|
||||||
settings.sourceOrder,
|
settings.sourceOrder,
|
||||||
settings.ids,
|
settings.ids,
|
||||||
name,
|
name,
|
||||||
harmonyNamedExports,
|
harmonyNamedExports,
|
||||||
null,
|
null,
|
||||||
exportPresenceMode,
|
exportPresenceMode,
|
||||||
null,
|
null,
|
||||||
settings.assertions
|
settings.assertions
|
||||||
);
|
)
|
||||||
} else {
|
: new HarmonyExportSpecifierDependency(id, name);
|
||||||
dep = new HarmonyExportSpecifierDependency(id, name);
|
|
||||||
}
|
|
||||||
dep.loc = Object.create(
|
dep.loc = Object.create(
|
||||||
/** @type {DependencyLocation} */ (statement.loc)
|
/** @type {DependencyLocation} */ (statement.loc)
|
||||||
);
|
);
|
||||||
|
|
|
@ -597,13 +597,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
||||||
* @returns {{ names: string[], namesSlice: number, dependencyIndices: number[], dependencyIndex: number } | undefined} exported names and their origin dependency
|
* @returns {{ names: string[], namesSlice: number, dependencyIndices: number[], dependencyIndex: number } | undefined} exported names and their origin dependency
|
||||||
*/
|
*/
|
||||||
_discoverActiveExportsFromOtherStarExports(moduleGraph) {
|
_discoverActiveExportsFromOtherStarExports(moduleGraph) {
|
||||||
if (!this.otherStarExports) return undefined;
|
if (!this.otherStarExports) return;
|
||||||
|
|
||||||
const i =
|
const i =
|
||||||
"length" in this.otherStarExports
|
"length" in this.otherStarExports
|
||||||
? this.otherStarExports.length
|
? this.otherStarExports.length
|
||||||
: countIterable(this.otherStarExports);
|
: countIterable(this.otherStarExports);
|
||||||
if (i === 0) return undefined;
|
if (i === 0) return;
|
||||||
|
|
||||||
if (this.allStarExports) {
|
if (this.allStarExports) {
|
||||||
const { names, dependencyIndices } = moduleGraph.cached(
|
const { names, dependencyIndices } = moduleGraph.cached(
|
||||||
|
@ -643,7 +643,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
||||||
|
|
||||||
switch (mode.type) {
|
switch (mode.type) {
|
||||||
case "missing":
|
case "missing":
|
||||||
return undefined;
|
return;
|
||||||
case "dynamic-reexport": {
|
case "dynamic-reexport": {
|
||||||
const from =
|
const from =
|
||||||
/** @type {ModuleGraphConnection} */
|
/** @type {ModuleGraphConnection} */
|
||||||
|
@ -1153,11 +1153,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
||||||
}
|
}
|
||||||
|
|
||||||
content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = ";
|
content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = ";
|
||||||
if (modern) {
|
content += modern
|
||||||
content += `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`;
|
? `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`
|
||||||
} else {
|
: `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
|
||||||
content += `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
|
|
||||||
}
|
|
||||||
|
|
||||||
runtimeRequirements.add(RuntimeGlobals.exports);
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
||||||
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
||||||
|
|
|
@ -96,7 +96,7 @@ function getAttributes(node) {
|
||||||
? /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions
|
? /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions
|
||||||
: /** @type {{ attributes?: ImportAttributeNode[] }} */ (node).attributes;
|
: /** @type {{ attributes?: ImportAttributeNode[] }} */ (node).attributes;
|
||||||
if (attributes === undefined) {
|
if (attributes === undefined) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
const result = /** @type {ImportAttributes} */ ({});
|
const result = /** @type {ImportAttributes} */ ({});
|
||||||
for (const attribute of attributes) {
|
for (const attribute of attributes) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ class ImportMetaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// import.meta direct
|
// import.meta direct
|
||||||
const webpackVersion = parseInt(
|
const webpackVersion = Number.parseInt(
|
||||||
require("../../package.json").version,
|
require("../../package.json").version,
|
||||||
10
|
10
|
||||||
);
|
);
|
||||||
|
|
|
@ -391,15 +391,13 @@ class WorkerPlugin {
|
||||||
dep2.loc = /** @type {DependencyLocation} */ (expr.loc);
|
dep2.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
parser.state.module.addPresentationalDependency(dep1);
|
parser.state.module.addPresentationalDependency(dep1);
|
||||||
parser.state.module.addPresentationalDependency(dep2);
|
parser.state.module.addPresentationalDependency(dep2);
|
||||||
} else if (insertType === "argument") {
|
} else if (insertType === "argument" && this._module) {
|
||||||
if (this._module) {
|
const dep = new ConstDependency(
|
||||||
const dep = new ConstDependency(
|
', { type: "module" }',
|
||||||
', { type: "module" }',
|
insertLocation
|
||||||
insertLocation
|
);
|
||||||
);
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
parser.state.module.addPresentationalDependency(dep);
|
||||||
parser.state.module.addPresentationalDependency(dep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.walkExpression(expr.callee);
|
parser.walkExpression(expr.callee);
|
||||||
|
@ -479,7 +477,9 @@ class WorkerPlugin {
|
||||||
};
|
};
|
||||||
for (const item of options) {
|
for (const item of options) {
|
||||||
if (item === "...") {
|
if (item === "...") {
|
||||||
DEFAULT_SYNTAX.forEach(processItem);
|
for (const itemFromDefault of DEFAULT_SYNTAX) {
|
||||||
|
processItem(itemFromDefault);
|
||||||
|
}
|
||||||
} else processItem(item);
|
} else processItem(item);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,15 +117,12 @@ module.exports = function () {
|
||||||
if ($hasOwnProperty$(currentUpdate, moduleId)) {
|
if ($hasOwnProperty$(currentUpdate, moduleId)) {
|
||||||
var newModuleFactory = currentUpdate[moduleId];
|
var newModuleFactory = currentUpdate[moduleId];
|
||||||
/** @type {TODO} */
|
/** @type {TODO} */
|
||||||
var result;
|
var result = newModuleFactory
|
||||||
if (newModuleFactory) {
|
? getAffectedModuleEffects(moduleId)
|
||||||
result = getAffectedModuleEffects(moduleId);
|
: {
|
||||||
} else {
|
type: "disposed",
|
||||||
result = {
|
moduleId: moduleId
|
||||||
type: "disposed",
|
};
|
||||||
moduleId: moduleId
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/** @type {Error|false} */
|
/** @type {Error|false} */
|
||||||
var abortError = false;
|
var abortError = false;
|
||||||
var doApply = false;
|
var doApply = false;
|
||||||
|
|
|
@ -184,7 +184,7 @@ class BasicEvaluatedExpression {
|
||||||
asCompileTimeValue() {
|
asCompileTimeValue() {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case TypeUndefined:
|
case TypeUndefined:
|
||||||
return undefined;
|
return;
|
||||||
case TypeNull:
|
case TypeNull:
|
||||||
return null;
|
return null;
|
||||||
case TypeString:
|
case TypeString:
|
||||||
|
@ -252,7 +252,6 @@ class BasicEvaluatedExpression {
|
||||||
const str = this.asString();
|
const str = this.asString();
|
||||||
if (typeof str === "string") return str !== "";
|
if (typeof str === "string") return str !== "";
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,8 +274,6 @@ class BasicEvaluatedExpression {
|
||||||
if (this.isConstArray()) return false;
|
if (this.isConstArray()) return false;
|
||||||
if (this.isTemplateString()) return false;
|
if (this.isTemplateString()) return false;
|
||||||
if (this.isRegExp()) return false;
|
if (this.isRegExp()) return false;
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -297,7 +294,7 @@ class BasicEvaluatedExpression {
|
||||||
this.items
|
this.items
|
||||||
)) {
|
)) {
|
||||||
const itemStr = item.asString();
|
const itemStr = item.asString();
|
||||||
if (itemStr === undefined) return undefined;
|
if (itemStr === undefined) return;
|
||||||
array.push(itemStr);
|
array.push(itemStr);
|
||||||
}
|
}
|
||||||
return `${array}`;
|
return `${array}`;
|
||||||
|
@ -309,12 +306,11 @@ class BasicEvaluatedExpression {
|
||||||
this.parts
|
this.parts
|
||||||
)) {
|
)) {
|
||||||
const partStr = part.asString();
|
const partStr = part.asString();
|
||||||
if (partStr === undefined) return undefined;
|
if (partStr === undefined) return;
|
||||||
str += partStr;
|
str += partStr;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1386,7 +1386,7 @@ class JavascriptParser extends Parser {
|
||||||
.setSideEffects(param.couldHaveSideEffects())
|
.setSideEffects(param.couldHaveSideEffects())
|
||||||
.setRange(/** @type {Range} */ (expr.range));
|
.setRange(/** @type {Range} */ (expr.range));
|
||||||
});
|
});
|
||||||
["substr", "substring", "slice"].forEach(fn => {
|
for (const fn of ["substr", "substring", "slice"]) {
|
||||||
this.hooks.evaluateCallExpressionMember
|
this.hooks.evaluateCallExpressionMember
|
||||||
.for(fn)
|
.for(fn)
|
||||||
.tap("JavascriptParser", (expr, param) => {
|
.tap("JavascriptParser", (expr, param) => {
|
||||||
|
@ -1426,7 +1426,7 @@ class JavascriptParser extends Parser {
|
||||||
.setSideEffects(param.couldHaveSideEffects())
|
.setSideEffects(param.couldHaveSideEffects())
|
||||||
.setRange(/** @type {Range} */ (expr.range));
|
.setRange(/** @type {Range} */ (expr.range));
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {"cooked" | "raw"} kind kind of values to get
|
* @param {"cooked" | "raw"} kind kind of values to get
|
||||||
|
@ -1706,7 +1706,7 @@ class JavascriptParser extends Parser {
|
||||||
* @returns {Set<DestructuringAssignmentProperty> | undefined} destructured identifiers
|
* @returns {Set<DestructuringAssignmentProperty> | undefined} destructured identifiers
|
||||||
*/
|
*/
|
||||||
destructuringAssignmentPropertiesFor(node) {
|
destructuringAssignmentPropertiesFor(node) {
|
||||||
if (!this.destructuringAssignmentProperties) return undefined;
|
if (!this.destructuringAssignmentProperties) return;
|
||||||
return this.destructuringAssignmentProperties.get(node);
|
return this.destructuringAssignmentProperties.get(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1726,10 +1726,11 @@ class JavascriptParser extends Parser {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
walkClass(classy) {
|
walkClass(classy) {
|
||||||
if (classy.superClass) {
|
if (
|
||||||
if (!this.hooks.classExtendsExpression.call(classy.superClass, classy)) {
|
classy.superClass &&
|
||||||
this.walkExpression(classy.superClass);
|
!this.hooks.classExtendsExpression.call(classy.superClass, classy)
|
||||||
}
|
) {
|
||||||
|
this.walkExpression(classy.superClass);
|
||||||
}
|
}
|
||||||
if (classy.body && classy.body.type === "ClassBody") {
|
if (classy.body && classy.body.type === "ClassBody") {
|
||||||
const scopeParams = [];
|
const scopeParams = [];
|
||||||
|
@ -2155,10 +2156,8 @@ class JavascriptParser extends Parser {
|
||||||
* @param {ForStatement} statement for statement
|
* @param {ForStatement} statement for statement
|
||||||
*/
|
*/
|
||||||
preWalkForStatement(statement) {
|
preWalkForStatement(statement) {
|
||||||
if (statement.init) {
|
if (statement.init && statement.init.type === "VariableDeclaration") {
|
||||||
if (statement.init.type === "VariableDeclaration") {
|
this.preWalkStatement(statement.init);
|
||||||
this.preWalkStatement(statement.init);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.preWalkStatement(statement.body);
|
this.preWalkStatement(statement.body);
|
||||||
}
|
}
|
||||||
|
@ -2425,19 +2424,18 @@ class JavascriptParser extends Parser {
|
||||||
} else {
|
} else {
|
||||||
this.hooks.export.call(statement);
|
this.hooks.export.call(statement);
|
||||||
}
|
}
|
||||||
if (statement.declaration) {
|
if (
|
||||||
if (
|
statement.declaration &&
|
||||||
!this.hooks.exportDeclaration.call(statement, statement.declaration)
|
!this.hooks.exportDeclaration.call(statement, statement.declaration)
|
||||||
) {
|
) {
|
||||||
const prev = this.prevStatement;
|
const prev = this.prevStatement;
|
||||||
this.preWalkStatement(statement.declaration);
|
this.preWalkStatement(statement.declaration);
|
||||||
this.prevStatement = prev;
|
this.prevStatement = prev;
|
||||||
this.blockPreWalkStatement(statement.declaration);
|
this.blockPreWalkStatement(statement.declaration);
|
||||||
let index = 0;
|
let index = 0;
|
||||||
this.enterDeclaration(statement.declaration, def => {
|
this.enterDeclaration(statement.declaration, def => {
|
||||||
this.hooks.exportSpecifier.call(statement, def, def, index++);
|
this.hooks.exportSpecifier.call(statement, def, def, index++);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (statement.specifiers) {
|
if (statement.specifiers) {
|
||||||
for (
|
for (
|
||||||
|
@ -3174,31 +3172,30 @@ class JavascriptParser extends Parser {
|
||||||
walkAssignmentExpression(expression) {
|
walkAssignmentExpression(expression) {
|
||||||
if (expression.left.type === "Identifier") {
|
if (expression.left.type === "Identifier") {
|
||||||
const renameIdentifier = this.getRenameIdentifier(expression.right);
|
const renameIdentifier = this.getRenameIdentifier(expression.right);
|
||||||
if (renameIdentifier) {
|
if (
|
||||||
|
renameIdentifier &&
|
||||||
|
this.callHooksForInfo(
|
||||||
|
this.hooks.canRename,
|
||||||
|
renameIdentifier,
|
||||||
|
expression.right
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
// renaming "a = b;"
|
||||||
if (
|
if (
|
||||||
this.callHooksForInfo(
|
!this.callHooksForInfo(
|
||||||
this.hooks.canRename,
|
this.hooks.rename,
|
||||||
renameIdentifier,
|
renameIdentifier,
|
||||||
expression.right
|
expression.right
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// renaming "a = b;"
|
this.setVariable(
|
||||||
if (
|
expression.left.name,
|
||||||
!this.callHooksForInfo(
|
typeof renameIdentifier === "string"
|
||||||
this.hooks.rename,
|
? this.getVariableInfo(renameIdentifier)
|
||||||
renameIdentifier,
|
: renameIdentifier
|
||||||
expression.right
|
);
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.setVariable(
|
|
||||||
expression.left.name,
|
|
||||||
typeof renameIdentifier === "string"
|
|
||||||
? this.getVariableInfo(renameIdentifier)
|
|
||||||
: renameIdentifier
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.walkExpression(expression.right);
|
this.walkExpression(expression.right);
|
||||||
this.enterPattern(expression.left, (name, decl) => {
|
this.enterPattern(expression.left, (name, decl) => {
|
||||||
|
@ -3221,17 +3218,16 @@ class JavascriptParser extends Parser {
|
||||||
expression.left,
|
expression.left,
|
||||||
ALLOWED_MEMBER_TYPES_EXPRESSION
|
ALLOWED_MEMBER_TYPES_EXPRESSION
|
||||||
);
|
);
|
||||||
if (exprName) {
|
if (
|
||||||
if (
|
exprName &&
|
||||||
this.callHooksForInfo(
|
this.callHooksForInfo(
|
||||||
this.hooks.assignMemberChain,
|
this.hooks.assignMemberChain,
|
||||||
exprName.rootInfo,
|
exprName.rootInfo,
|
||||||
expression,
|
expression,
|
||||||
exprName.getMembers()
|
exprName.getMembers()
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.walkExpression(expression.right);
|
this.walkExpression(expression.right);
|
||||||
this.walkExpression(expression.left);
|
this.walkExpression(expression.left);
|
||||||
|
@ -3344,26 +3340,18 @@ class JavascriptParser extends Parser {
|
||||||
const renameIdentifier = this.getRenameIdentifier(
|
const renameIdentifier = this.getRenameIdentifier(
|
||||||
/** @type {Expression} */ (argOrThis)
|
/** @type {Expression} */ (argOrThis)
|
||||||
);
|
);
|
||||||
if (renameIdentifier) {
|
if (
|
||||||
if (
|
renameIdentifier &&
|
||||||
this.callHooksForInfo(
|
this.callHooksForInfo(
|
||||||
this.hooks.canRename,
|
this.hooks.canRename,
|
||||||
renameIdentifier,
|
renameIdentifier,
|
||||||
argOrThis
|
argOrThis
|
||||||
)
|
) &&
|
||||||
) {
|
!this.callHooksForInfo(this.hooks.rename, renameIdentifier, argOrThis)
|
||||||
if (
|
) {
|
||||||
!this.callHooksForInfo(
|
return typeof renameIdentifier === "string"
|
||||||
this.hooks.rename,
|
? /** @type {string} */ (this.getVariableInfo(renameIdentifier))
|
||||||
renameIdentifier,
|
: renameIdentifier;
|
||||||
argOrThis
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return typeof renameIdentifier === "string"
|
|
||||||
? /** @type {string} */ (this.getVariableInfo(renameIdentifier))
|
|
||||||
: renameIdentifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.walkExpression(argOrThis);
|
this.walkExpression(argOrThis);
|
||||||
};
|
};
|
||||||
|
@ -4589,8 +4577,10 @@ class JavascriptParser extends Parser {
|
||||||
)
|
)
|
||||||
)) {
|
)) {
|
||||||
if (typeof val === "object" && val !== null) {
|
if (typeof val === "object" && val !== null) {
|
||||||
if (val.constructor.name === "RegExp") val = new RegExp(val);
|
val =
|
||||||
else val = JSON.parse(JSON.stringify(val));
|
val.constructor.name === "RegExp"
|
||||||
|
? new RegExp(val)
|
||||||
|
: JSON.parse(JSON.stringify(val));
|
||||||
}
|
}
|
||||||
options[key] = val;
|
options[key] = val;
|
||||||
}
|
}
|
||||||
|
@ -4646,9 +4636,9 @@ class JavascriptParser extends Parser {
|
||||||
let name;
|
let name;
|
||||||
if (info instanceof VariableInfo) {
|
if (info instanceof VariableInfo) {
|
||||||
name = info.freeName;
|
name = info.freeName;
|
||||||
if (typeof name !== "string") return undefined;
|
if (typeof name !== "string") return;
|
||||||
} else if (typeof info !== "string") {
|
} else if (typeof info !== "string") {
|
||||||
return undefined;
|
return;
|
||||||
} else {
|
} else {
|
||||||
name = info;
|
name = info;
|
||||||
}
|
}
|
||||||
|
@ -4668,8 +4658,7 @@ class JavascriptParser extends Parser {
|
||||||
this.extractMemberExpressionChain(expression);
|
this.extractMemberExpressionChain(expression);
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case "CallExpression": {
|
case "CallExpression": {
|
||||||
if ((allowedTypes & ALLOWED_MEMBER_TYPES_CALL_EXPRESSION) === 0)
|
if ((allowedTypes & ALLOWED_MEMBER_TYPES_CALL_EXPRESSION) === 0) return;
|
||||||
return undefined;
|
|
||||||
let callee = object.callee;
|
let callee = object.callee;
|
||||||
let rootMembers = EMPTY_ARRAY;
|
let rootMembers = EMPTY_ARRAY;
|
||||||
if (callee.type === "MemberExpression") {
|
if (callee.type === "MemberExpression") {
|
||||||
|
@ -4677,9 +4666,9 @@ class JavascriptParser extends Parser {
|
||||||
this.extractMemberExpressionChain(callee));
|
this.extractMemberExpressionChain(callee));
|
||||||
}
|
}
|
||||||
const rootName = getRootName(callee);
|
const rootName = getRootName(callee);
|
||||||
if (!rootName) return undefined;
|
if (!rootName) return;
|
||||||
const result = this.getFreeInfoFromVariable(rootName);
|
const result = this.getFreeInfoFromVariable(rootName);
|
||||||
if (!result) return undefined;
|
if (!result) return;
|
||||||
const { info: rootInfo, name: resolvedRoot } = result;
|
const { info: rootInfo, name: resolvedRoot } = result;
|
||||||
const calleeName = objectAndMembersToName(resolvedRoot, rootMembers);
|
const calleeName = objectAndMembersToName(resolvedRoot, rootMembers);
|
||||||
return {
|
return {
|
||||||
|
@ -4697,13 +4686,12 @@ class JavascriptParser extends Parser {
|
||||||
case "Identifier":
|
case "Identifier":
|
||||||
case "MetaProperty":
|
case "MetaProperty":
|
||||||
case "ThisExpression": {
|
case "ThisExpression": {
|
||||||
if ((allowedTypes & ALLOWED_MEMBER_TYPES_EXPRESSION) === 0)
|
if ((allowedTypes & ALLOWED_MEMBER_TYPES_EXPRESSION) === 0) return;
|
||||||
return undefined;
|
|
||||||
const rootName = getRootName(object);
|
const rootName = getRootName(object);
|
||||||
if (!rootName) return undefined;
|
if (!rootName) return;
|
||||||
|
|
||||||
const result = this.getFreeInfoFromVariable(rootName);
|
const result = this.getFreeInfoFromVariable(rootName);
|
||||||
if (!result) return undefined;
|
if (!result) return;
|
||||||
const { info: rootInfo, name: resolvedRoot } = result;
|
const { info: rootInfo, name: resolvedRoot } = result;
|
||||||
return {
|
return {
|
||||||
type: "expression",
|
type: "expression",
|
||||||
|
|
|
@ -27,7 +27,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
||||||
const stringifySafe = data => {
|
const stringifySafe = data => {
|
||||||
const stringified = JSON.stringify(data);
|
const stringified = JSON.stringify(data);
|
||||||
if (!stringified) {
|
if (!stringified) {
|
||||||
return undefined; // Invalid JSON
|
return; // Invalid JSON
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringified.replace(/\u2028|\u2029/g, str =>
|
return stringified.replace(/\u2028|\u2029/g, str =>
|
||||||
|
@ -53,16 +53,10 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
|
||||||
if (used === UsageState.Unused) continue;
|
if (used === UsageState.Unused) continue;
|
||||||
|
|
||||||
/** @type {RawJsonData} */
|
/** @type {RawJsonData} */
|
||||||
let value;
|
const value =
|
||||||
if (used === UsageState.OnlyPropertiesUsed && exportInfo.exportsInfo) {
|
used === UsageState.OnlyPropertiesUsed && exportInfo.exportsInfo
|
||||||
value = createObjectForExportsInfo(
|
? createObjectForExportsInfo(data[key], exportInfo.exportsInfo, runtime)
|
||||||
data[key],
|
: data[key];
|
||||||
exportInfo.exportsInfo,
|
|
||||||
runtime
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
value = data[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = /** @type {string} */ (exportInfo.getUsedName(key, runtime));
|
const name = /** @type {string} */ (exportInfo.getUsedName(key, runtime));
|
||||||
/** @type {Record<string, RawJsonData>} */ (reducedData)[name] = value;
|
/** @type {Record<string, RawJsonData>} */ (reducedData)[name] = value;
|
||||||
|
|
|
@ -49,7 +49,7 @@ class JsonParser extends Parser {
|
||||||
data =
|
data =
|
||||||
typeof source === "object"
|
typeof source === "object"
|
||||||
? source
|
? source
|
||||||
: parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
|
: parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Cannot parse JSON: ${/** @type {Error} */ (err).message}`
|
`Cannot parse JSON: ${/** @type {Error} */ (err).message}`
|
||||||
|
|
|
@ -217,13 +217,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
||||||
`Missing external configuration for type:${type}`
|
`Missing external configuration for type:${type}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (Array.isArray(request)) {
|
expr = Array.isArray(request)
|
||||||
expr = `require(${JSON.stringify(
|
? `require(${JSON.stringify(
|
||||||
request[0]
|
request[0]
|
||||||
)})${accessorToObjectAccess(request.slice(1))}`;
|
)})${accessorToObjectAccess(request.slice(1))}`
|
||||||
} else {
|
: `require(${JSON.stringify(request)})`;
|
||||||
expr = `require(${JSON.stringify(request)})`;
|
|
||||||
}
|
|
||||||
if (m.isOptional(moduleGraph)) {
|
if (m.isOptional(moduleGraph)) {
|
||||||
expr = `(function webpackLoadOptionalExternalModule() { try { return ${expr}; } catch(e) {} }())`;
|
expr = `(function webpackLoadOptionalExternalModule() { try { return ${expr}; } catch(e) {} }())`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,7 @@ const truncateArgs = (args, maxLength) => {
|
||||||
// Check if there is space for at least 4 chars per arg
|
// Check if there is space for at least 4 chars per arg
|
||||||
if (availableLength < arraySum(lengths.map(i => Math.min(i, 6)))) {
|
if (availableLength < arraySum(lengths.map(i => Math.min(i, 6)))) {
|
||||||
// remove args
|
// remove args
|
||||||
if (args.length > 1)
|
if (args.length > 1) return truncateArgs(args.slice(0, -1), maxLength);
|
||||||
return truncateArgs(args.slice(0, args.length - 1), maxLength);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||||
|
|
||||||
const clearStatusMessage = () => {
|
const clearStatusMessage = () => {
|
||||||
if (hasStatusMessage) {
|
if (hasStatusMessage) {
|
||||||
stream.write("\x1b[2K\r");
|
stream.write("\u001B[2K\r");
|
||||||
hasStatusMessage = false;
|
hasStatusMessage = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -58,8 +58,8 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||||
const l = /** @type {TODO} */ (stream).columns || 40;
|
const l = /** @type {TODO} */ (stream).columns || 40;
|
||||||
const args = truncateArgs(currentStatusMessage, l - 1);
|
const args = truncateArgs(currentStatusMessage, l - 1);
|
||||||
const str = args.join(" ");
|
const str = args.join(" ");
|
||||||
const coloredStr = `\u001b[1m${str}\u001b[39m\u001b[22m`;
|
const coloredStr = `\u001B[1m${str}\u001B[39m\u001B[22m`;
|
||||||
stream.write(`\x1b[2K\r${coloredStr}`);
|
stream.write(`\u001B[2K\r${coloredStr}`);
|
||||||
hasStatusMessage = true;
|
hasStatusMessage = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,27 +86,27 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||||
|
|
||||||
const writeGroupMessage = writeColored(
|
const writeGroupMessage = writeColored(
|
||||||
"<-> ",
|
"<-> ",
|
||||||
"\u001b[1m\u001b[36m",
|
"\u001B[1m\u001B[36m",
|
||||||
"\u001b[39m\u001b[22m"
|
"\u001B[39m\u001B[22m"
|
||||||
);
|
);
|
||||||
|
|
||||||
const writeGroupCollapsedMessage = writeColored(
|
const writeGroupCollapsedMessage = writeColored(
|
||||||
"<+> ",
|
"<+> ",
|
||||||
"\u001b[1m\u001b[36m",
|
"\u001B[1m\u001B[36m",
|
||||||
"\u001b[39m\u001b[22m"
|
"\u001B[39m\u001B[22m"
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
log: writeColored(" ", "\u001b[1m", "\u001b[22m"),
|
log: writeColored(" ", "\u001B[1m", "\u001B[22m"),
|
||||||
debug: writeColored(" ", "", ""),
|
debug: writeColored(" ", "", ""),
|
||||||
trace: writeColored(" ", "", ""),
|
trace: writeColored(" ", "", ""),
|
||||||
info: writeColored("<i> ", "\u001b[1m\u001b[32m", "\u001b[39m\u001b[22m"),
|
info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"),
|
||||||
warn: writeColored("<w> ", "\u001b[1m\u001b[33m", "\u001b[39m\u001b[22m"),
|
warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"),
|
||||||
error: writeColored("<e> ", "\u001b[1m\u001b[31m", "\u001b[39m\u001b[22m"),
|
error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"),
|
||||||
logTime: writeColored(
|
logTime: writeColored(
|
||||||
"<t> ",
|
"<t> ",
|
||||||
"\u001b[1m\u001b[35m",
|
"\u001B[1m\u001B[35m",
|
||||||
"\u001b[39m\u001b[22m"
|
"\u001B[39m\u001B[22m"
|
||||||
),
|
),
|
||||||
group: (...args) => {
|
group: (...args) => {
|
||||||
writeGroupMessage(...args);
|
writeGroupMessage(...args);
|
||||||
|
@ -123,7 +123,7 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||||
groupEnd: () => {
|
groupEnd: () => {
|
||||||
if (currentCollapsed > 0) currentCollapsed--;
|
if (currentCollapsed > 0) currentCollapsed--;
|
||||||
else if (currentIndent.length >= 2)
|
else if (currentIndent.length >= 2)
|
||||||
currentIndent = currentIndent.slice(0, currentIndent.length - 2);
|
currentIndent = currentIndent.slice(0, -2);
|
||||||
},
|
},
|
||||||
profile: console.profile && (name => console.profile(name)),
|
profile: console.profile && (name => console.profile(name)),
|
||||||
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
|
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
|
||||||
|
|
|
@ -272,12 +272,14 @@ class AggressiveSplittingPlugin {
|
||||||
// We remove invalid splittings and try again
|
// We remove invalid splittings and try again
|
||||||
for (const chunk of compilation.chunks) {
|
for (const chunk of compilation.chunks) {
|
||||||
const splitData = chunkSplitDataMap.get(chunk);
|
const splitData = chunkSplitDataMap.get(chunk);
|
||||||
if (splitData !== undefined) {
|
if (
|
||||||
if (splitData.hash && chunk.hash !== splitData.hash) {
|
splitData !== undefined &&
|
||||||
// Split was successful, but hash doesn't equal
|
splitData.hash &&
|
||||||
// We can throw away the split since it's useless now
|
chunk.hash !== splitData.hash
|
||||||
invalidSplits.add(splitData);
|
) {
|
||||||
}
|
// Split was successful, but hash doesn't equal
|
||||||
|
// We can throw away the split since it's useless now
|
||||||
|
invalidSplits.add(splitData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,12 +218,12 @@ const createComparator = (property, comparator) => (a, b) =>
|
||||||
* @returns {0 | 1 | -1} result
|
* @returns {0 | 1 | -1} result
|
||||||
*/
|
*/
|
||||||
const compareNumbers = (a, b) => {
|
const compareNumbers = (a, b) => {
|
||||||
if (isNaN(a)) {
|
if (Number.isNaN(a)) {
|
||||||
if (!isNaN(b)) {
|
if (!Number.isNaN(b)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isNaN(b)) {
|
if (Number.isNaN(b)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (a !== b) {
|
if (a !== b) {
|
||||||
|
|
|
@ -109,13 +109,14 @@ class InnerGraphPlugin {
|
||||||
parser.hooks.preStatement.tap(PLUGIN_NAME, statement => {
|
parser.hooks.preStatement.tap(PLUGIN_NAME, statement => {
|
||||||
if (!InnerGraph.isEnabled(parser.state)) return;
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
||||||
|
|
||||||
if (parser.scope.topLevelScope === true) {
|
if (
|
||||||
if (statement.type === "FunctionDeclaration") {
|
parser.scope.topLevelScope === true &&
|
||||||
const name = statement.id ? statement.id.name : "*default*";
|
statement.type === "FunctionDeclaration"
|
||||||
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
) {
|
||||||
statementWithTopLevelSymbol.set(statement, fn);
|
const name = statement.id ? statement.id.name : "*default*";
|
||||||
return true;
|
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
||||||
}
|
statementWithTopLevelSymbol.set(statement, fn);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ class LimitChunkCountPlugin {
|
||||||
/** @type {Map<Chunk, Set<ChunkCombination>>} */
|
/** @type {Map<Chunk, Set<ChunkCombination>>} */
|
||||||
const combinationsByChunk = new Map();
|
const combinationsByChunk = new Map();
|
||||||
|
|
||||||
orderedChunks.forEach((b, bIdx) => {
|
for (const [bIdx, b] of orderedChunks.entries()) {
|
||||||
// create combination pairs with size and integrated size
|
// create combination pairs with size and integrated size
|
||||||
for (let aIdx = 0; aIdx < bIdx; aIdx++) {
|
for (let aIdx = 0; aIdx < bIdx; aIdx++) {
|
||||||
const a = orderedChunks[aIdx];
|
const a = orderedChunks[aIdx];
|
||||||
|
@ -149,8 +149,7 @@ class LimitChunkCountPlugin {
|
||||||
addToSetMap(combinationsByChunk, a, c);
|
addToSetMap(combinationsByChunk, a, c);
|
||||||
addToSetMap(combinationsByChunk, b, c);
|
addToSetMap(combinationsByChunk, b, c);
|
||||||
}
|
}
|
||||||
return combinations;
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// list of modified chunks during this run
|
// list of modified chunks during this run
|
||||||
// combinations affected by this change are skipped to allow
|
// combinations affected by this change are skipped to allow
|
||||||
|
|
|
@ -773,14 +773,10 @@ class ModuleConcatenationPlugin {
|
||||||
);
|
);
|
||||||
if (runtimeCondition === false) continue;
|
if (runtimeCondition === false) continue;
|
||||||
if (runtimeCondition === true) continue outer;
|
if (runtimeCondition === true) continue outer;
|
||||||
if (currentRuntimeCondition !== false) {
|
currentRuntimeCondition =
|
||||||
currentRuntimeCondition = mergeRuntime(
|
currentRuntimeCondition !== false
|
||||||
currentRuntimeCondition,
|
? mergeRuntime(currentRuntimeCondition, runtimeCondition)
|
||||||
runtimeCondition
|
: runtimeCondition;
|
||||||
);
|
|
||||||
} else {
|
|
||||||
currentRuntimeCondition = runtimeCondition;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (currentRuntimeCondition !== false) {
|
if (currentRuntimeCondition !== false) {
|
||||||
otherRuntimeConnections.push({
|
otherRuntimeConnections.push({
|
||||||
|
|
|
@ -254,7 +254,7 @@ ${referencingAssets
|
||||||
})
|
})
|
||||||
.join("\n")}`);
|
.join("\n")}`);
|
||||||
compilation.errors.push(err);
|
compilation.errors.push(err);
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
const hashes = new Set();
|
const hashes = new Set();
|
||||||
for (const { referencedHashes, ownHashes } of assets) {
|
for (const { referencedHashes, ownHashes } of assets) {
|
||||||
|
|
|
@ -323,11 +323,7 @@ const combineSizes = (a, b, combine) => {
|
||||||
/** @type {SplitChunksSizes} */
|
/** @type {SplitChunksSizes} */
|
||||||
const result = {};
|
const result = {};
|
||||||
for (const key of aKeys) {
|
for (const key of aKeys) {
|
||||||
if (bKeys.has(key)) {
|
result[key] = bKeys.has(key) ? combine(a[key], b[key]) : a[key];
|
||||||
result[key] = combine(a[key], b[key]);
|
|
||||||
} else {
|
|
||||||
result[key] = a[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (const key of bKeys) {
|
for (const key of bKeys) {
|
||||||
if (!aKeys.has(key)) {
|
if (!aKeys.has(key)) {
|
||||||
|
@ -1434,7 +1430,7 @@ module.exports = class SplitChunksPlugin {
|
||||||
: item.cacheGroup.maxAsyncRequests
|
: item.cacheGroup.maxAsyncRequests
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
isFinite(maxRequests) &&
|
Number.isFinite(maxRequests) &&
|
||||||
getRequests(chunk) >= maxRequests
|
getRequests(chunk) >= maxRequests
|
||||||
) {
|
) {
|
||||||
usedChunks.delete(chunk);
|
usedChunks.delete(chunk);
|
||||||
|
|
|
@ -74,11 +74,10 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
chunkFilename.length ===
|
chunkFilename.length ===
|
||||||
/** @type {string} */ (dynamicFilename).length
|
/** @type {string} */ (dynamicFilename).length &&
|
||||||
|
chunkFilename < /** @type {string} */ (dynamicFilename)
|
||||||
) {
|
) {
|
||||||
if (chunkFilename < /** @type {string} */ (dynamicFilename)) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maxChunks = set.size;
|
maxChunks = set.size;
|
||||||
|
@ -137,7 +136,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
||||||
return '" + chunkId + "';
|
return '" + chunkId + "';
|
||||||
}
|
}
|
||||||
const s = JSON.stringify(str);
|
const s = JSON.stringify(str);
|
||||||
return s.slice(1, s.length - 1);
|
return s.slice(1, -1);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @param {string} value string
|
* @param {string} value string
|
||||||
|
|
|
@ -138,7 +138,7 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
||||||
if (cacheControl) {
|
if (cacheControl) {
|
||||||
const parsed = parseKeyValuePairs(cacheControl);
|
const parsed = parseKeyValuePairs(cacheControl);
|
||||||
if (parsed["no-cache"]) storeCache = storeLock = false;
|
if (parsed["no-cache"]) storeCache = storeLock = false;
|
||||||
if (parsed["max-age"] && !isNaN(Number(parsed["max-age"]))) {
|
if (parsed["max-age"] && !Number.isNaN(Number(parsed["max-age"]))) {
|
||||||
validUntil = requestTime + Number(parsed["max-age"]) * 1000;
|
validUntil = requestTime + Number(parsed["max-age"]) * 1000;
|
||||||
}
|
}
|
||||||
if (parsed["must-revalidate"]) validUntil = 0;
|
if (parsed["must-revalidate"]) validUntil = 0;
|
||||||
|
|
|
@ -635,7 +635,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
||||||
if (nextItem === ESCAPE_ESCAPE_VALUE) {
|
if (nextItem === ESCAPE_ESCAPE_VALUE) {
|
||||||
return ESCAPE;
|
return ESCAPE;
|
||||||
} else if (nextItem === ESCAPE_UNDEFINED) {
|
} else if (nextItem === ESCAPE_UNDEFINED) {
|
||||||
return undefined;
|
// Nothing
|
||||||
} else if (nextItem === ESCAPE_END_OBJECT) {
|
} else if (nextItem === ESCAPE_END_OBJECT) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unexpected end of object at position ${currentDataPos - 1}`
|
`Unexpected end of object at position ${currentDataPos - 1}`
|
||||||
|
@ -668,11 +668,9 @@ class ObjectMiddleware extends SerializerMiddleware {
|
||||||
if (request && !loadedRequests.has(request)) {
|
if (request && !loadedRequests.has(request)) {
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
for (const [regExp, loader] of loaders) {
|
for (const [regExp, loader] of loaders) {
|
||||||
if (regExp.test(request)) {
|
if (regExp.test(request) && loader(request)) {
|
||||||
if (loader(request)) {
|
loaded = true;
|
||||||
loaded = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
|
|
|
@ -52,11 +52,10 @@ class Serializer {
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
let current = value;
|
let current = value;
|
||||||
for (const middleware of this.deserializeMiddlewares) {
|
for (const middleware of this.deserializeMiddlewares) {
|
||||||
if (current && typeof current.then === "function") {
|
current =
|
||||||
current = current.then(data => middleware.deserialize(data, ctx));
|
current && typeof current.then === "function"
|
||||||
} else {
|
? current.then(data => middleware.deserialize(data, ctx))
|
||||||
current = middleware.deserialize(current, ctx);
|
: middleware.deserialize(current, ctx);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ class SerializerMiddleware {
|
||||||
* @returns {object} options
|
* @returns {object} options
|
||||||
*/
|
*/
|
||||||
static getLazyOptions(fn) {
|
static getLazyOptions(fn) {
|
||||||
if (typeof fn !== "function") return undefined;
|
if (typeof fn !== "function") return;
|
||||||
return /** @type {any} */ (fn).options;
|
return /** @type {any} */ (fn).options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class SerializerMiddleware {
|
||||||
* @returns {any} serialized value
|
* @returns {any} serialized value
|
||||||
*/
|
*/
|
||||||
static getLazySerializedValue(fn) {
|
static getLazySerializedValue(fn) {
|
||||||
if (typeof fn !== "function") return undefined;
|
if (typeof fn !== "function") return;
|
||||||
return fn[LAZY_SERIALIZED_VALUE];
|
return fn[LAZY_SERIALIZED_VALUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,7 @@ const extractCommithashByDomain = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!type) {
|
commithash = !type ? hash : `#${commithash}`;
|
||||||
commithash = hash;
|
|
||||||
} else {
|
|
||||||
commithash = `#${commithash}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project && project.endsWith(".git")) {
|
if (project && project.endsWith(".git")) {
|
||||||
project = project.slice(0, -4);
|
project = project.slice(0, -4);
|
||||||
|
@ -252,11 +248,9 @@ function canBeDecoded(str) {
|
||||||
function getGitUrlVersion(gitUrl) {
|
function getGitUrlVersion(gitUrl) {
|
||||||
const oriGitUrl = gitUrl;
|
const oriGitUrl = gitUrl;
|
||||||
// github extreme shorthand
|
// github extreme shorthand
|
||||||
if (RE_URL_GITHUB_EXTREME_SHORT.test(gitUrl)) {
|
gitUrl = RE_URL_GITHUB_EXTREME_SHORT.test(gitUrl)
|
||||||
gitUrl = `github:${gitUrl}`;
|
? `github:${gitUrl}`
|
||||||
} else {
|
: correctProtocol(gitUrl);
|
||||||
gitUrl = correctProtocol(gitUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
gitUrl = correctUrl(gitUrl);
|
gitUrl = correctUrl(gitUrl);
|
||||||
|
|
||||||
|
|
|
@ -576,11 +576,10 @@ const SIMPLE_EXTRACTORS = {
|
||||||
|
|
||||||
if (type === LogType.groupEnd) {
|
if (type === LogType.groupEnd) {
|
||||||
groupStack.pop();
|
groupStack.pop();
|
||||||
if (groupStack.length > 0) {
|
currentList =
|
||||||
currentList = groupStack[groupStack.length - 1].children;
|
groupStack.length > 0
|
||||||
} else {
|
? groupStack[groupStack.length - 1].children
|
||||||
currentList = rootList;
|
: rootList;
|
||||||
}
|
|
||||||
if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
|
if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,7 +625,7 @@ const SIMPLE_PRINTERS = {
|
||||||
: `${bold(moduleName)}`,
|
: `${bold(moduleName)}`,
|
||||||
"error.loc": (loc, { green }) => green(loc),
|
"error.loc": (loc, { green }) => green(loc),
|
||||||
"error.message": (message, { bold, formatError }) =>
|
"error.message": (message, { bold, formatError }) =>
|
||||||
message.includes("\u001b[") ? message : bold(formatError(message)),
|
message.includes("\u001B[") ? message : bold(formatError(message)),
|
||||||
"error.details": (details, { formatError }) => formatError(details),
|
"error.details": (details, { formatError }) => formatError(details),
|
||||||
"error.filteredDetails": filteredDetails =>
|
"error.filteredDetails": filteredDetails =>
|
||||||
filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
|
filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
|
||||||
|
@ -1198,12 +1198,12 @@ const SIMPLE_ELEMENT_JOINERS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const AVAILABLE_COLORS = {
|
const AVAILABLE_COLORS = {
|
||||||
bold: "\u001b[1m",
|
bold: "\u001B[1m",
|
||||||
yellow: "\u001b[1m\u001b[33m",
|
yellow: "\u001B[1m\u001B[33m",
|
||||||
red: "\u001b[1m\u001b[31m",
|
red: "\u001B[1m\u001B[31m",
|
||||||
green: "\u001b[1m\u001b[32m",
|
green: "\u001B[1m\u001B[32m",
|
||||||
cyan: "\u001b[1m\u001b[36m",
|
cyan: "\u001B[1m\u001B[36m",
|
||||||
magenta: "\u001b[1m\u001b[35m"
|
magenta: "\u001B[1m\u001B[35m"
|
||||||
};
|
};
|
||||||
|
|
||||||
const AVAILABLE_FORMATS = {
|
const AVAILABLE_FORMATS = {
|
||||||
|
@ -1254,7 +1254,7 @@ const AVAILABLE_FORMATS = {
|
||||||
return `${boldQuantity ? bold(time) : time}${unit}`;
|
return `${boldQuantity ? bold(time) : time}${unit}`;
|
||||||
},
|
},
|
||||||
formatError: (message, { green, yellow, red }) => {
|
formatError: (message, { green, yellow, red }) => {
|
||||||
if (message.includes("\u001b[")) return message;
|
if (message.includes("\u001B[")) return message;
|
||||||
const highlights = [
|
const highlights = [
|
||||||
{ regExp: /(Did you mean .+)/g, format: green },
|
{ regExp: /(Did you mean .+)/g, format: green },
|
||||||
{
|
{
|
||||||
|
@ -1345,11 +1345,11 @@ class DefaultStatsPrinterPlugin {
|
||||||
`${start}${
|
`${start}${
|
||||||
typeof str === "string"
|
typeof str === "string"
|
||||||
? str.replace(
|
? str.replace(
|
||||||
/((\u001b\[39m|\u001b\[22m|\u001b\[0m)+)/g,
|
/((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
|
||||||
`$1${start}`
|
`$1${start}`
|
||||||
)
|
)
|
||||||
: str
|
: str
|
||||||
}\u001b[39m\u001b[22m`;
|
}\u001B[39m\u001B[22m`;
|
||||||
} else {
|
} else {
|
||||||
context[color] = str => str;
|
context[color] = str => str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ArrayQueue {
|
||||||
*/
|
*/
|
||||||
dequeue() {
|
dequeue() {
|
||||||
if (this._listReversed.length === 0) {
|
if (this._listReversed.length === 0) {
|
||||||
if (this._list.length === 0) return undefined;
|
if (this._list.length === 0) return;
|
||||||
if (this._list.length === 1) return this._list.pop();
|
if (this._list.length === 1) return this._list.pop();
|
||||||
if (this._list.length < 16) return this._list.shift();
|
if (this._list.length < 16) return this._list.shift();
|
||||||
const temp = this._listReversed;
|
const temp = this._listReversed;
|
||||||
|
|
|
@ -94,7 +94,7 @@ class LazyBucketSortedSet {
|
||||||
* @returns {T | undefined} an item
|
* @returns {T | undefined} an item
|
||||||
*/
|
*/
|
||||||
popFirst() {
|
popFirst() {
|
||||||
if (this.size === 0) return undefined;
|
if (this.size === 0) return;
|
||||||
this.size--;
|
this.size--;
|
||||||
if (this._unsortedItems.size > 0) {
|
if (this._unsortedItems.size > 0) {
|
||||||
for (const item of this._unsortedItems) {
|
for (const item of this._unsortedItems) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Queue {
|
||||||
*/
|
*/
|
||||||
dequeue() {
|
dequeue() {
|
||||||
const result = this._iterator.next();
|
const result = this._iterator.next();
|
||||||
if (result.done) return undefined;
|
if (result.done) return;
|
||||||
this._set.delete(result.value);
|
this._set.delete(result.value);
|
||||||
return result.value;
|
return result.value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,10 @@ class Semaphore {
|
||||||
}
|
}
|
||||||
|
|
||||||
_continue() {
|
_continue() {
|
||||||
if (this.available > 0) {
|
if (this.available > 0 && this.waiters.length > 0) {
|
||||||
if (this.waiters.length > 0) {
|
this.available--;
|
||||||
this.available--;
|
const callback = /** @type {(function(): void)} */ (this.waiters.pop());
|
||||||
const callback = /** @type {(function(): void)} */ (this.waiters.pop());
|
callback();
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,6 @@ class StackedMap {
|
||||||
}
|
}
|
||||||
this.map.set(item, TOMBSTONE);
|
this.map.set(item, TOMBSTONE);
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_compress() {
|
_compress() {
|
||||||
|
|
|
@ -57,7 +57,7 @@ class TupleQueue {
|
||||||
this._set.delete(...value);
|
this._set.delete(...value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
this._set.delete(...result.value);
|
this._set.delete(...result.value);
|
||||||
return result.value;
|
return result.value;
|
||||||
|
|
|
@ -36,7 +36,7 @@ function getScheme(specifier) {
|
||||||
(start < aLowerCaseCharCode || start > zLowerCaseCharCode) &&
|
(start < aLowerCaseCharCode || start > zLowerCaseCharCode) &&
|
||||||
(start < aUpperCaseCharCode || start > zUpperCaseCharCode)
|
(start < aUpperCaseCharCode || start > zUpperCaseCharCode)
|
||||||
) {
|
) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
|
@ -49,12 +49,12 @@ function getScheme(specifier) {
|
||||||
ch === plusCharCode ||
|
ch === plusCharCode ||
|
||||||
ch === hyphenCharCode
|
ch === hyphenCharCode
|
||||||
) {
|
) {
|
||||||
if (++i === specifier.length) return undefined;
|
if (++i === specifier.length) return;
|
||||||
ch = specifier.charCodeAt(i);
|
ch = specifier.charCodeAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scheme must end with colon
|
// Scheme must end with colon
|
||||||
if (ch !== colonCharCode) return undefined;
|
if (ch !== colonCharCode) return;
|
||||||
|
|
||||||
// Check for Windows absolute path
|
// Check for Windows absolute path
|
||||||
// https://url.spec.whatwg.org/#url-miscellaneous
|
// https://url.spec.whatwg.org/#url-miscellaneous
|
||||||
|
@ -67,7 +67,7 @@ function getScheme(specifier) {
|
||||||
nextChar === hashCharCode ||
|
nextChar === hashCharCode ||
|
||||||
nextChar === queryCharCode
|
nextChar === queryCharCode
|
||||||
) {
|
) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class WeakTupleMap {
|
||||||
let node = this;
|
let node = this;
|
||||||
for (let i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
node = node._peek(args[i]);
|
node = node._peek(args[i]);
|
||||||
if (node === undefined) return undefined;
|
if (node === undefined) return;
|
||||||
}
|
}
|
||||||
return node._getValue();
|
return node._getValue();
|
||||||
}
|
}
|
||||||
|
@ -158,10 +158,10 @@ class WeakTupleMap {
|
||||||
*/
|
*/
|
||||||
_peek(thing) {
|
_peek(thing) {
|
||||||
if (isWeakKey(thing)) {
|
if (isWeakKey(thing)) {
|
||||||
if ((this.f & 4) !== 4) return undefined;
|
if ((this.f & 4) !== 4) return;
|
||||||
return /** @type {W<T, V>} */ (this.w).get(thing);
|
return /** @type {W<T, V>} */ (this.w).get(thing);
|
||||||
}
|
}
|
||||||
if ((this.f & 2) !== 2) return undefined;
|
if ((this.f & 2) !== 2) return;
|
||||||
return /** @type {M<T, V>} */ (this.m).get(thing);
|
return /** @type {M<T, V>} */ (this.m).get(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ class TwoKeyWeakMap {
|
||||||
get(key1, key2) {
|
get(key1, key2) {
|
||||||
const childMap = this._map.get(key1);
|
const childMap = this._map.get(key1);
|
||||||
if (childMap === undefined) {
|
if (childMap === undefined) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
return childMap.get(key2);
|
return childMap.get(key2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,6 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
||||||
for (const item of this) {
|
for (const item of this) {
|
||||||
if (i++ === index) return item;
|
if (i++ === index) return item;
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
};
|
};
|
||||||
return fn;
|
return fn;
|
||||||
};
|
};
|
||||||
|
|
|
@ -115,9 +115,7 @@ const isTooBig = (size, maxSize) => {
|
||||||
const s = size[key];
|
const s = size[key];
|
||||||
if (s === 0) continue;
|
if (s === 0) continue;
|
||||||
const maxSizeValue = maxSize[key];
|
const maxSizeValue = maxSize[key];
|
||||||
if (typeof maxSizeValue === "number") {
|
if (typeof maxSizeValue === "number" && s > maxSizeValue) return true;
|
||||||
if (s > maxSizeValue) return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -132,9 +130,7 @@ const isTooSmall = (size, minSize) => {
|
||||||
const s = size[key];
|
const s = size[key];
|
||||||
if (s === 0) continue;
|
if (s === 0) continue;
|
||||||
const minSizeValue = minSize[key];
|
const minSizeValue = minSize[key];
|
||||||
if (typeof minSizeValue === "number") {
|
if (typeof minSizeValue === "number" && s < minSizeValue) return true;
|
||||||
if (s < minSizeValue) return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -150,9 +146,7 @@ const getTooSmallTypes = (size, minSize) => {
|
||||||
const s = size[key];
|
const s = size[key];
|
||||||
if (s === 0) continue;
|
if (s === 0) continue;
|
||||||
const minSizeValue = minSize[key];
|
const minSizeValue = minSize[key];
|
||||||
if (typeof minSizeValue === "number") {
|
if (typeof minSizeValue === "number" && s < minSizeValue) types.add(key);
|
||||||
if (s < minSizeValue) types.add(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return types;
|
return types;
|
||||||
};
|
};
|
||||||
|
@ -242,7 +236,7 @@ class Group {
|
||||||
lastNode = node;
|
lastNode = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resultNodes.length === this.nodes.length) return undefined;
|
if (resultNodes.length === this.nodes.length) return;
|
||||||
this.nodes = newNodes;
|
this.nodes = newNodes;
|
||||||
this.similarities = newSimilarities;
|
this.similarities = newSimilarities;
|
||||||
this.size = sumSize(newNodes);
|
this.size = sumSize(newNodes);
|
||||||
|
|
|
@ -42,18 +42,15 @@ const getPathInAst = (ast, node) => {
|
||||||
const nr = node.range;
|
const nr = node.range;
|
||||||
|
|
||||||
const enterNode = n => {
|
const enterNode = n => {
|
||||||
if (!n) return undefined;
|
if (!n) return;
|
||||||
const r = n.range;
|
const r = n.range;
|
||||||
if (r) {
|
if (r && r[0] <= nr[0] && r[1] >= nr[1]) {
|
||||||
if (r[0] <= nr[0] && r[1] >= nr[1]) {
|
const path = getPathInAst(n, node);
|
||||||
const path = getPathInAst(n, node);
|
if (path) {
|
||||||
if (path) {
|
path.push(n);
|
||||||
path.push(n);
|
return path;
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Array.isArray(ast)) {
|
if (Array.isArray(ast)) {
|
||||||
|
|
|
@ -15,8 +15,8 @@ const A_CODE = "a".charCodeAt(0);
|
||||||
module.exports = (hash, hashLength) => {
|
module.exports = (hash, hashLength) => {
|
||||||
if (hashLength < 1) return "";
|
if (hashLength < 1) return "";
|
||||||
const slice = hash.slice(0, hashLength);
|
const slice = hash.slice(0, hashLength);
|
||||||
if (slice.match(/[^\d]/)) return slice;
|
if (/[^\d]/.test(slice)) return slice;
|
||||||
return `${String.fromCharCode(
|
return `${String.fromCharCode(
|
||||||
A_CODE + (parseInt(hash[0], 10) % 6)
|
A_CODE + (Number.parseInt(hash[0], 10) % 6)
|
||||||
)}${slice.slice(1)}`;
|
)}${slice.slice(1)}`;
|
||||||
};
|
};
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue