mirror of https://github.com/webpack/webpack.git
refactor(types): more
This commit is contained in:
parent
1ab7cad9a3
commit
4809421990
|
@ -13,8 +13,11 @@ const {
|
|||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
/** @typedef {import("estree").CallExpression} CallExpression */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const nestedWebpackIdentifierTag = Symbol("nested webpack identifier");
|
||||
const PLUGIN_NAME = "CompatibilityPlugin";
|
||||
|
@ -43,31 +46,41 @@ class CompatibilityPlugin {
|
|||
)
|
||||
return;
|
||||
|
||||
parser.hooks.call.for("require").tap(PLUGIN_NAME, expr => {
|
||||
// support for browserify style require delegator: "require(o, !0)"
|
||||
if (expr.arguments.length !== 2) return;
|
||||
const second = parser.evaluateExpression(expr.arguments[1]);
|
||||
if (!second.isBoolean()) return;
|
||||
if (second.asBool() !== true) return;
|
||||
const dep = new ConstDependency("require", expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
if (parser.state.current.dependencies.length > 0) {
|
||||
const last =
|
||||
parser.state.current.dependencies[
|
||||
parser.state.current.dependencies.length - 1
|
||||
];
|
||||
if (
|
||||
last.critical &&
|
||||
last.options &&
|
||||
last.options.request === "." &&
|
||||
last.userRequest === "." &&
|
||||
last.options.recursive
|
||||
)
|
||||
parser.state.current.dependencies.pop();
|
||||
parser.hooks.call.for("require").tap(
|
||||
PLUGIN_NAME,
|
||||
/**
|
||||
* @param {CallExpression} expr call expression
|
||||
* @returns {boolean | void} true when need to handle
|
||||
*/
|
||||
expr => {
|
||||
// support for browserify style require delegator: "require(o, !0)"
|
||||
if (expr.arguments.length !== 2) return;
|
||||
const second = parser.evaluateExpression(expr.arguments[1]);
|
||||
if (!second.isBoolean()) return;
|
||||
if (second.asBool() !== true) return;
|
||||
const dep = new ConstDependency(
|
||||
"require",
|
||||
/** @type {Range} */ (expr.callee.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
if (parser.state.current.dependencies.length > 0) {
|
||||
const last =
|
||||
parser.state.current.dependencies[
|
||||
parser.state.current.dependencies.length - 1
|
||||
];
|
||||
if (
|
||||
last.critical &&
|
||||
last.options &&
|
||||
last.options.request === "." &&
|
||||
last.userRequest === "." &&
|
||||
last.options.recursive
|
||||
)
|
||||
parser.state.current.dependencies.pop();
|
||||
}
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
}
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -82,7 +95,9 @@ class CompatibilityPlugin {
|
|||
statement.id &&
|
||||
statement.id.name === RuntimeGlobals.require
|
||||
) {
|
||||
const newName = `__nested_webpack_require_${statement.range[0]}__`;
|
||||
const newName = `__nested_webpack_require_${
|
||||
/** @type {Range} */ (statement.range)[0]
|
||||
}__`;
|
||||
parser.tagVariable(
|
||||
statement.id.name,
|
||||
nestedWebpackIdentifierTag,
|
||||
|
@ -101,7 +116,9 @@ class CompatibilityPlugin {
|
|||
parser.hooks.pattern
|
||||
.for(RuntimeGlobals.require)
|
||||
.tap(PLUGIN_NAME, pattern => {
|
||||
const newName = `__nested_webpack_require_${pattern.range[0]}__`;
|
||||
const newName = `__nested_webpack_require_${
|
||||
/** @type {Range} */ (pattern.range)[0]
|
||||
}__`;
|
||||
parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
|
||||
name: newName,
|
||||
declaration: {
|
||||
|
@ -135,8 +152,11 @@ class CompatibilityPlugin {
|
|||
parser.state.module.addPresentationalDependency(dep);
|
||||
declaration.updated = true;
|
||||
}
|
||||
const dep = new ConstDependency(name, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
const dep = new ConstDependency(
|
||||
name,
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
@ -145,11 +165,11 @@ class CompatibilityPlugin {
|
|||
parser.hooks.program.tap(PLUGIN_NAME, (program, comments) => {
|
||||
if (comments.length === 0) return;
|
||||
const c = comments[0];
|
||||
if (c.type === "Line" && c.range[0] === 0) {
|
||||
if (c.type === "Line" && /** @type {Range} */ (c.range)[0] === 0) {
|
||||
if (parser.state.source.slice(0, 2).toString() !== "#!") return;
|
||||
// this is a hashbang comment
|
||||
const dep = new ConstDependency("//", 0);
|
||||
dep.loc = c.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (c.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3208,6 +3208,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|||
const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
|
||||
this;
|
||||
const results = this.codeGenerationResults;
|
||||
/** @type {WebpackError[]} */
|
||||
const errors = [];
|
||||
/** @type {Set<Module> | undefined} */
|
||||
let notCodeGeneratedModules = undefined;
|
||||
|
@ -3303,7 +3304,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|||
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
||||
* @param {WebpackError[]} errors errors
|
||||
* @param {CodeGenerationResults} results results
|
||||
* @param {function(WebpackError=, boolean=): void} callback callback
|
||||
* @param {function((WebpackError | null)=, boolean=): void} callback callback
|
||||
*/
|
||||
_codeGenerationModule(
|
||||
module,
|
||||
|
|
|
@ -42,6 +42,13 @@ const RUNTIME_REQUIREMENTS = new Set([
|
|||
]);
|
||||
|
||||
class DelegatedModule extends Module {
|
||||
/**
|
||||
* @param {string} sourceRequest source request
|
||||
* @param {TODO} data data
|
||||
* @param {"require" | "object"} type type
|
||||
* @param {string} userRequest user request
|
||||
* @param {string | Module} originalRequest original request
|
||||
*/
|
||||
constructor(sourceRequest, data, type, userRequest, originalRequest) {
|
||||
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
||||
|
||||
|
@ -51,7 +58,7 @@ class DelegatedModule extends Module {
|
|||
this.delegationType = type;
|
||||
this.userRequest = userRequest;
|
||||
this.originalRequest = originalRequest;
|
||||
/** @type {ManifestModuleData} */
|
||||
/** @type {ManifestModuleData | undefined} */
|
||||
this.delegateData = data;
|
||||
|
||||
// Build info
|
||||
|
@ -110,7 +117,8 @@ class DelegatedModule extends Module {
|
|||
* @returns {void}
|
||||
*/
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.buildMeta = { ...this.delegateData.buildMeta };
|
||||
const delegateData = /** @type {ManifestModuleData} */ (this.delegateData);
|
||||
this.buildMeta = { ...delegateData.buildMeta };
|
||||
this.buildInfo = {};
|
||||
this.dependencies.length = 0;
|
||||
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
||||
|
@ -118,7 +126,7 @@ class DelegatedModule extends Module {
|
|||
);
|
||||
this.addDependency(this.delegatedSourceDependency);
|
||||
this.addDependency(
|
||||
new StaticExportsDependency(this.delegateData.exports || true, false)
|
||||
new StaticExportsDependency(delegateData.exports || true, false)
|
||||
);
|
||||
callback();
|
||||
}
|
||||
|
@ -202,6 +210,10 @@ class DelegatedModule extends Module {
|
|||
super.serialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context\
|
||||
* @returns {DelegatedModule} DelegatedModule
|
||||
*/
|
||||
static deserialize(context) {
|
||||
const { read } = context;
|
||||
const obj = new DelegatedModule(
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
const DelegatedModule = require("./DelegatedModule");
|
||||
|
||||
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
||||
|
||||
// options.source
|
||||
// options.type
|
||||
// options.context
|
||||
|
@ -20,6 +22,10 @@ class DelegatedModuleFactoryPlugin {
|
|||
options.extensions = options.extensions || ["", ".js", ".json", ".wasm"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NormalModuleFactory} normalModuleFactory the normal module factory
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(normalModuleFactory) {
|
||||
const scope = this.options.scope;
|
||||
if (scope) {
|
||||
|
|
|
@ -82,6 +82,10 @@ class EvalSourceMapDevToolPlugin {
|
|||
return cachedSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Source} r result
|
||||
* @returns {Source} result
|
||||
*/
|
||||
const result = r => {
|
||||
cache.set(source, r);
|
||||
return r;
|
||||
|
|
|
@ -14,6 +14,8 @@ const { forEachRuntime } = require("./util/runtime");
|
|||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
|
||||
/** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
|
||||
|
@ -44,6 +46,9 @@ class RestoreProvidedData {
|
|||
this.otherTerminalBinding = otherTerminalBinding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize({ write }) {
|
||||
write(this.exports);
|
||||
write(this.otherProvided);
|
||||
|
@ -51,6 +56,10 @@ class RestoreProvidedData {
|
|||
write(this.otherTerminalBinding);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
* @returns {RestoreProvidedData} RestoreProvidedData
|
||||
*/
|
||||
static deserialize({ read }) {
|
||||
return new RestoreProvidedData(read(), read(), read(), read());
|
||||
}
|
||||
|
@ -301,7 +310,12 @@ class ExportsInfo {
|
|||
changed = true;
|
||||
}
|
||||
if (targetKey) {
|
||||
exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
|
||||
exportInfo.setTarget(
|
||||
targetKey,
|
||||
/** @type {ModuleGraphConnection} */ (targetModule),
|
||||
[exportInfo.name],
|
||||
-1
|
||||
);
|
||||
}
|
||||
}
|
||||
if (this._redirectTo !== undefined) {
|
||||
|
@ -331,7 +345,7 @@ class ExportsInfo {
|
|||
if (targetKey) {
|
||||
this._otherExportsInfo.setTarget(
|
||||
targetKey,
|
||||
targetModule,
|
||||
/** @type {ModuleGraphConnection} */ (targetModule),
|
||||
undefined,
|
||||
priority
|
||||
);
|
||||
|
@ -1226,7 +1240,7 @@ class ExportInfo {
|
|||
/**
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
||||
* @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
|
||||
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
||||
* @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) {
|
||||
|
|
|
@ -14,7 +14,9 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|||
const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const PLUGIN_NAME = "ExportsInfoApiPlugin";
|
||||
|
||||
|
@ -43,20 +45,27 @@ class ExportsInfoApiPlugin {
|
|||
const dep =
|
||||
members.length >= 2
|
||||
? new ExportsInfoDependency(
|
||||
expr.range,
|
||||
/** @type {Range} */ (expr.range),
|
||||
members.slice(0, -1),
|
||||
members[members.length - 1]
|
||||
)
|
||||
: new ExportsInfoDependency(expr.range, null, members[0]);
|
||||
dep.loc = expr.loc;
|
||||
: new ExportsInfoDependency(
|
||||
/** @type {Range} */ (expr.range),
|
||||
null,
|
||||
members[0]
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("__webpack_exports_info__")
|
||||
.tap(PLUGIN_NAME, expr => {
|
||||
const dep = new ConstDependency("true", expr.range);
|
||||
dep.loc = expr.loc;
|
||||
const dep = new ConstDependency(
|
||||
"true",
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -384,6 +384,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|||
};
|
||||
|
||||
class ExternalModule extends Module {
|
||||
/**
|
||||
* @param {string | string[] | Record<string, string | string[]>} request request
|
||||
* @param {TODO} type type
|
||||
* @param {string} userRequest user request
|
||||
*/
|
||||
constructor(request, type, userRequest) {
|
||||
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
||||
|
||||
|
|
|
@ -8,10 +8,14 @@
|
|||
const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Module").FactoryMeta} FactoryMeta */
|
||||
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
|
||||
class FlagAllModulesAsUsedPlugin {
|
||||
/**
|
||||
* @param {string} explanation explanation
|
||||
*/
|
||||
constructor(explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
|
@ -40,7 +44,8 @@ class FlagAllModulesAsUsedPlugin {
|
|||
if (module.factoryMeta === undefined) {
|
||||
module.factoryMeta = {};
|
||||
}
|
||||
module.factoryMeta.sideEffectFree = false;
|
||||
/** @type {FactoryMeta} */
|
||||
(module.factoryMeta).sideEffectFree = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -189,6 +189,10 @@ class HotModuleReplacementPlugin {
|
|||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyModuleHot = parser => {
|
||||
parser.hooks.evaluateIdentifier.for("module.hot").tap(
|
||||
{
|
||||
|
@ -221,6 +225,10 @@ class HotModuleReplacementPlugin {
|
|||
.tap(PLUGIN_NAME, createHMRExpressionHandler(parser));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyImportMetaHot = parser => {
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("import.meta.webpackHot")
|
||||
|
|
|
@ -10,17 +10,21 @@ const makeSerializable = require("./util/makeSerializable");
|
|||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
|
||||
/**
|
||||
* @param {InitFragment} fragment the init fragment
|
||||
* @template T
|
||||
* @param {InitFragment<T>} fragment the init fragment
|
||||
* @param {number} index index
|
||||
* @returns {[InitFragment, number]} tuple with both
|
||||
* @returns {[InitFragment<T>, number]} tuple with both
|
||||
*/
|
||||
const extractFragmentIndex = (fragment, index) => [fragment, index];
|
||||
|
||||
/**
|
||||
* @param {[InitFragment, number]} a first pair
|
||||
* @param {[InitFragment, number]} b second pair
|
||||
* @template T
|
||||
* @param {[InitFragment<T>, number]} a first pair
|
||||
* @param {[InitFragment<T>, number]} b second pair
|
||||
* @returns {number} sort value
|
||||
*/
|
||||
const sortFragmentWithIndex = ([a, i], [b, j]) => {
|
||||
|
@ -66,6 +70,14 @@ class InitFragment {
|
|||
return this.endContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template Context
|
||||
* @template T
|
||||
* @param {Source} source sources
|
||||
* @param {InitFragment<T>[]} initFragments init fragments
|
||||
* @param {Context} context context
|
||||
* @returns {Source} source
|
||||
*/
|
||||
static addToSource(source, initFragments, context) {
|
||||
if (initFragments.length > 0) {
|
||||
// Sort fragments by position. If 2 fragments have the same position,
|
||||
|
@ -77,7 +89,12 @@ class InitFragment {
|
|||
// Deduplicate fragments. If a fragment has no key, it is always included.
|
||||
const keyedFragments = new Map();
|
||||
for (const [fragment] of sortedFragments) {
|
||||
if (typeof fragment.mergeAll === "function") {
|
||||
if (
|
||||
typeof (
|
||||
/** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment[]) => InitFragment[] }} */
|
||||
(fragment).mergeAll
|
||||
) === "function"
|
||||
) {
|
||||
if (!fragment.key) {
|
||||
throw new Error(
|
||||
`InitFragment with mergeAll function must have a valid key: ${fragment.constructor.name}`
|
||||
|
@ -125,6 +142,9 @@ class InitFragment {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
|
||||
|
@ -135,6 +155,9 @@ class InitFragment {
|
|||
write(this.endContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ const {
|
|||
const InnerGraph = require("./optimize/InnerGraph");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
|
||||
const PLUGIN_NAME = "JavascriptMetaInfoPlugin";
|
||||
|
@ -33,8 +34,11 @@ class JavascriptMetaInfoPlugin {
|
|||
*/
|
||||
const handler = parser => {
|
||||
parser.hooks.call.for("eval").tap(PLUGIN_NAME, () => {
|
||||
parser.state.module.buildInfo.moduleConcatenationBailout = "eval()";
|
||||
parser.state.module.buildInfo.usingEval = true;
|
||||
const buildInfo =
|
||||
/** @type {BuildInfo} */
|
||||
(parser.state.module.buildInfo);
|
||||
buildInfo.moduleConcatenationBailout = "eval()";
|
||||
buildInfo.usingEval = true;
|
||||
const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
|
||||
if (currentSymbol) {
|
||||
InnerGraph.addUsage(parser.state, null, currentSymbol);
|
||||
|
@ -43,11 +47,12 @@ class JavascriptMetaInfoPlugin {
|
|||
}
|
||||
});
|
||||
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
||||
let topLevelDeclarations =
|
||||
parser.state.module.buildInfo.topLevelDeclarations;
|
||||
const buildInfo =
|
||||
/** @type {BuildInfo} */
|
||||
(parser.state.module.buildInfo);
|
||||
let topLevelDeclarations = buildInfo.topLevelDeclarations;
|
||||
if (topLevelDeclarations === undefined) {
|
||||
topLevelDeclarations =
|
||||
parser.state.module.buildInfo.topLevelDeclarations = new Set();
|
||||
topLevelDeclarations = buildInfo.topLevelDeclarations = new Set();
|
||||
}
|
||||
for (const name of parser.scope.definitions.asSet()) {
|
||||
const freeInfo = parser.getFreeInfoFromVariable(name);
|
||||
|
|
|
@ -12,15 +12,29 @@ const { compareModulesById } = require("./util/comparators");
|
|||
const { dirname, mkdirp } = require("./util/fs");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
||||
|
||||
/**
|
||||
* @typedef {Object} ManifestModuleData
|
||||
* @property {string | number} id
|
||||
* @property {Object} buildMeta
|
||||
* @property {boolean | string[]} exports
|
||||
* @property {BuildMeta} buildMeta
|
||||
* @property {boolean | string[] | undefined} exports
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} LibManifestPluginOptions
|
||||
* @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
|
||||
* @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
|
||||
* @property {boolean=} format If true, manifest json file (output) will be formatted.
|
||||
* @property {string=} name Name of the exposed dll function (external name, use value of 'output.library').
|
||||
* @property {string} path Absolute path to the manifest json file (output).
|
||||
* @property {string=} type Type of the dll bundle (external type, use value of 'output.libraryTarget').
|
||||
*/
|
||||
|
||||
class LibManifestPlugin {
|
||||
/**
|
||||
* @param {LibManifestPluginOptions} options the options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
@ -67,7 +81,9 @@ class LibManifestPlugin {
|
|||
continue;
|
||||
}
|
||||
const ident = module.libIdent({
|
||||
context: this.options.context || compiler.options.context,
|
||||
context:
|
||||
this.options.context ||
|
||||
/** @type {string} */ (compiler.options.context),
|
||||
associatedObjectForCache: compiler.root
|
||||
});
|
||||
if (ident) {
|
||||
|
@ -76,7 +92,7 @@ class LibManifestPlugin {
|
|||
/** @type {ManifestModuleData} */
|
||||
const data = {
|
||||
id: chunkGraph.getModuleId(module),
|
||||
buildMeta: module.buildMeta,
|
||||
buildMeta: /** @type {BuildMeta} */ (module.buildMeta),
|
||||
exports: Array.isArray(providedExports)
|
||||
? providedExports
|
||||
: undefined
|
||||
|
|
|
@ -109,6 +109,11 @@ const makeSerializable = require("./util/makeSerializable");
|
|||
/** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
|
||||
/** @typedef {Record<string, any>} BuildInfo */
|
||||
|
||||
/**
|
||||
* @typedef {Object} FactoryMeta
|
||||
* @property {boolean=} sideEffectFree
|
||||
*/
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
||||
let debugId = 1000;
|
||||
|
@ -159,7 +164,7 @@ class Module extends DependenciesBlock {
|
|||
// Info from Factory
|
||||
/** @type {ResolveOptions | undefined} */
|
||||
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
||||
/** @type {object | undefined} */
|
||||
/** @type {FactoryMeta | undefined} */
|
||||
this.factoryMeta = undefined;
|
||||
// TODO refactor this -> options object filled from Factory
|
||||
// TODO webpack 6: use an enum
|
||||
|
|
|
@ -34,6 +34,7 @@ class ModuleProfile {
|
|||
this.storing = 0;
|
||||
this.storingParallelismFactor = 0;
|
||||
|
||||
/** @type {{ start: number, end: number }[] | undefined } */
|
||||
this.additionalFactoryTimes = undefined;
|
||||
this.additionalFactories = 0;
|
||||
this.additionalFactoriesParallelismFactor = 0;
|
||||
|
|
|
@ -16,6 +16,7 @@ class ModuleRestoreError extends WebpackError {
|
|||
*/
|
||||
constructor(module, err) {
|
||||
let message = "Module restore failed: ";
|
||||
/** @type {string | undefined} */
|
||||
let details = undefined;
|
||||
if (err !== null && typeof err === "object") {
|
||||
if (typeof err.stack === "string" && err.stack) {
|
||||
|
@ -33,6 +34,7 @@ class ModuleRestoreError extends WebpackError {
|
|||
super(message);
|
||||
|
||||
this.name = "ModuleRestoreError";
|
||||
/** @type {string | undefined} */
|
||||
this.details = details;
|
||||
this.module = module;
|
||||
this.error = err;
|
||||
|
|
|
@ -21,14 +21,23 @@ const { relative } = require("./util/fs");
|
|||
const { parseResource } = require("./util/identifier");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("../declarations/WebpackOptions").NodeOptions} NodeOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./NormalModule")} NormalModule */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const PLUGIN_NAME = "NodeStuffPlugin";
|
||||
|
||||
class NodeStuffPlugin {
|
||||
/**
|
||||
* @param {NodeOptions} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
@ -43,6 +52,11 @@ class NodeStuffPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
PLUGIN_NAME,
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @param {JavascriptParserOptions} parserOptions options
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = (parser, parserOptions) => {
|
||||
if (parserOptions.node === false) return;
|
||||
|
||||
|
@ -56,10 +70,10 @@ class NodeStuffPlugin {
|
|||
parser.hooks.expression.for("global").tap(PLUGIN_NAME, expr => {
|
||||
const dep = new ConstDependency(
|
||||
RuntimeGlobals.global,
|
||||
expr.range,
|
||||
/** @type {Range} */ (expr.range),
|
||||
[RuntimeGlobals.global]
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
|
||||
// TODO webpack 6 remove
|
||||
|
@ -76,25 +90,31 @@ class NodeStuffPlugin {
|
|||
parser.hooks.rename.for("global").tap(PLUGIN_NAME, expr => {
|
||||
const dep = new ConstDependency(
|
||||
RuntimeGlobals.global,
|
||||
expr.range,
|
||||
/** @type {Range} */ (expr.range),
|
||||
[RuntimeGlobals.global]
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} expressionName expression name
|
||||
* @param {(module: NormalModule) => string} fn function
|
||||
* @param {string=} warning warning
|
||||
* @returns {void}
|
||||
*/
|
||||
const setModuleConstant = (expressionName, fn, warning) => {
|
||||
parser.hooks.expression
|
||||
.for(expressionName)
|
||||
.tap(PLUGIN_NAME, expr => {
|
||||
const dep = new CachedConstDependency(
|
||||
JSON.stringify(fn(parser.state.module)),
|
||||
expr.range,
|
||||
/** @type {Range} */ (expr.range),
|
||||
expressionName
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
|
||||
// TODO webpack 6 remove
|
||||
|
@ -108,6 +128,12 @@ class NodeStuffPlugin {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} expressionName expression name
|
||||
* @param {string} value value
|
||||
* @param {string=} warning warning
|
||||
* @returns {void}
|
||||
*/
|
||||
const setConstant = (expressionName, value, warning) =>
|
||||
setModuleConstant(expressionName, () => value, warning);
|
||||
|
||||
|
|
|
@ -14,7 +14,11 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|||
const ProvidedDependency = require("./dependencies/ProvidedDependency");
|
||||
const { approve } = require("./javascript/JavascriptParserHelpers");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const PLUGIN_NAME = "ProvidePlugin";
|
||||
|
||||
|
@ -48,6 +52,11 @@ class ProvidePlugin {
|
|||
ProvidedDependency,
|
||||
new ProvidedDependency.Template()
|
||||
);
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @param {JavascriptParserOptions} parserOptions options
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = (parser, parserOptions) => {
|
||||
Object.keys(definitions).forEach(name => {
|
||||
const request = [].concat(definitions[name]);
|
||||
|
@ -67,9 +76,9 @@ class ProvidePlugin {
|
|||
request[0],
|
||||
nameIdentifier,
|
||||
request.slice(1),
|
||||
expr.range
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
@ -82,9 +91,9 @@ class ProvidePlugin {
|
|||
request[0],
|
||||
nameIdentifier,
|
||||
request.slice(1),
|
||||
expr.callee.range
|
||||
/** @type {Range} */ (expr.callee.range)
|
||||
);
|
||||
dep.loc = expr.callee.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
|
||||
parser.state.module.addDependency(dep);
|
||||
parser.walkExpressions(expr.arguments);
|
||||
return true;
|
||||
|
|
|
@ -72,7 +72,9 @@ class RawModule extends Module {
|
|||
* @returns {string} a user readable identifier of the module
|
||||
*/
|
||||
readableIdentifier(requestShortener) {
|
||||
return requestShortener.shorten(this.readableIdentifierStr);
|
||||
return /** @type {string} */ (
|
||||
requestShortener.shorten(this.readableIdentifierStr)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,9 @@ const {
|
|||
toConstantDependency
|
||||
} = require("./javascript/JavascriptParserHelpers");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
|
||||
const PLUGIN_NAME = "RequireJsStuffPlugin";
|
||||
|
||||
|
@ -33,6 +35,11 @@ module.exports = class RequireJsStuffPlugin {
|
|||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @param {JavascriptParserOptions} parserOptions options
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = (parser, parserOptions) => {
|
||||
if (
|
||||
parserOptions.requireJs === undefined ||
|
||||
|
|
|
@ -166,7 +166,7 @@ class RuntimeModule extends Module {
|
|||
/* istanbul ignore next */
|
||||
/**
|
||||
* @abstract
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const AbstractMethodError = require("./AbstractMethodError");
|
||||
|
@ -174,11 +174,11 @@ class RuntimeModule extends Module {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
getGeneratedCode() {
|
||||
if (this._cachedGeneratedCode) {
|
||||
return this._cachedGeneratedCode;
|
||||
return /** @type {string | null} */ (this._cachedGeneratedCode);
|
||||
}
|
||||
return (this._cachedGeneratedCode = this.generate());
|
||||
}
|
||||
|
|
|
@ -128,7 +128,8 @@ class RuntimePlugin {
|
|||
});
|
||||
}
|
||||
for (const req of Object.keys(TREE_DEPENDENCIES)) {
|
||||
const deps = TREE_DEPENDENCIES[req];
|
||||
const deps =
|
||||
TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(req)
|
||||
.tap("RuntimePlugin", (chunk, set) => {
|
||||
|
@ -136,7 +137,8 @@ class RuntimePlugin {
|
|||
});
|
||||
}
|
||||
for (const req of Object.keys(MODULE_DEPENDENCIES)) {
|
||||
const deps = MODULE_DEPENDENCIES[req];
|
||||
const deps =
|
||||
MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
|
||||
compilation.hooks.runtimeRequirementInModule
|
||||
.for(req)
|
||||
.tap("RuntimePlugin", (chunk, set) => {
|
||||
|
|
|
@ -7,9 +7,13 @@
|
|||
|
||||
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
|
||||
class SourceMapDevToolModuleOptionsPlugin {
|
||||
/**
|
||||
* @param {SourceMapDevToolPluginOptions} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|||
/** @typedef {import("./Cache").Etag} Etag */
|
||||
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Compilation").Asset} Asset */
|
||||
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
||||
/** @typedef {import("./Compilation").PathData} PathData */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
@ -227,7 +228,9 @@ class SourceMapDevToolPlugin {
|
|||
asyncLib.each(
|
||||
files,
|
||||
(file, callback) => {
|
||||
const asset = compilation.getAsset(file);
|
||||
const asset =
|
||||
/** @type {Readonly<Asset>} */
|
||||
(compilation.getAsset(file));
|
||||
if (asset.info.related && asset.info.related.sourceMap) {
|
||||
fileIndex++;
|
||||
return callback();
|
||||
|
@ -363,7 +366,9 @@ class SourceMapDevToolPlugin {
|
|||
// find modules with conflicting source names
|
||||
for (let idx = 0; idx < allModules.length; idx++) {
|
||||
const module = allModules[idx];
|
||||
let sourceName = moduleToSourceNameMapping.get(module);
|
||||
let sourceName =
|
||||
/** @type {string} */
|
||||
(moduleToSourceNameMapping.get(module));
|
||||
let hasName = conflictDetectionSet.has(sourceName);
|
||||
if (!hasName) {
|
||||
conflictDetectionSet.add(sourceName);
|
||||
|
|
|
@ -13,7 +13,10 @@ const {
|
|||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const PLUGIN_NAME = "UseStrictPlugin";
|
||||
|
||||
|
@ -42,10 +45,14 @@ class UseStrictPlugin {
|
|||
// Remove "use strict" expression. It will be added later by the renderer again.
|
||||
// This is necessary in order to not break the strict mode when webpack prepends code.
|
||||
// @see https://github.com/webpack/webpack/issues/1970
|
||||
const dep = new ConstDependency("", firstNode.range);
|
||||
dep.loc = firstNode.loc;
|
||||
const dep = new ConstDependency(
|
||||
"",
|
||||
/** @type {Range} */ (firstNode.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (firstNode.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
parser.state.module.buildInfo.strict = true;
|
||||
/** @type {BuildInfo} */
|
||||
(parser.state.module.buildInfo).strict = true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -16,10 +16,12 @@ const {
|
|||
toConstantDependency
|
||||
} = require("./javascript/JavascriptParserHelpers");
|
||||
|
||||
/** @typedef {import("enhanced-resolve/lib/Resolver")} Resolver */
|
||||
/** @typedef {import("enhanced-resolve").Resolver} Resolver */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
||||
|
||||
const PLUGIN_NAME = "WebpackIsIncludedPlugin";
|
||||
|
||||
|
@ -61,10 +63,10 @@ class WebpackIsIncludedPlugin {
|
|||
if (!request.isString()) return;
|
||||
|
||||
const dep = new WebpackIsIncludedDependency(
|
||||
request.string,
|
||||
expr.range
|
||||
/** @type {string} */ (request.string),
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -181,6 +181,7 @@ class AssetGenerator extends Generator {
|
|||
);
|
||||
}
|
||||
|
||||
/** @type {string | boolean | undefined} */
|
||||
let mimeType = this.dataUrlOptions.mimetype;
|
||||
if (mimeType === undefined) {
|
||||
const ext = path.extname(module.nameForCondition());
|
||||
|
@ -213,7 +214,7 @@ class AssetGenerator extends Generator {
|
|||
);
|
||||
}
|
||||
|
||||
return mimeType;
|
||||
return /** @type {string} */ (mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,8 @@ const Parser = require("../Parser");
|
|||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
|
||||
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
||||
/** @typedef {import("../Parser").ParserState} ParserState */
|
||||
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
||||
|
||||
|
@ -30,22 +32,25 @@ class AssetParser extends Parser {
|
|||
if (typeof source === "object" && !Buffer.isBuffer(source)) {
|
||||
throw new Error("AssetParser doesn't accept preparsed AST");
|
||||
}
|
||||
state.module.buildInfo.strict = true;
|
||||
state.module.buildMeta.exportsType = "default";
|
||||
state.module.buildMeta.defaultObject = false;
|
||||
|
||||
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
||||
buildInfo.strict = true;
|
||||
const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
||||
buildMeta.exportsType = "default";
|
||||
buildMeta.defaultObject = false;
|
||||
|
||||
if (typeof this.dataUrlCondition === "function") {
|
||||
state.module.buildInfo.dataUrl = this.dataUrlCondition(source, {
|
||||
buildInfo.dataUrl = this.dataUrlCondition(source, {
|
||||
filename: state.module.matchResource || state.module.resource,
|
||||
module: state.module
|
||||
});
|
||||
} else if (typeof this.dataUrlCondition === "boolean") {
|
||||
state.module.buildInfo.dataUrl = this.dataUrlCondition;
|
||||
buildInfo.dataUrl = this.dataUrlCondition;
|
||||
} else if (
|
||||
this.dataUrlCondition &&
|
||||
typeof this.dataUrlCondition === "object"
|
||||
) {
|
||||
state.module.buildInfo.dataUrl =
|
||||
buildInfo.dataUrl =
|
||||
Buffer.byteLength(source) <=
|
||||
/** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
|
||||
(this.dataUrlCondition.maxSize);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
const Parser = require("../Parser");
|
||||
|
||||
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
||||
/** @typedef {import("../Parser").ParserState} ParserState */
|
||||
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
||||
|
||||
|
@ -21,9 +23,12 @@ class AssetSourceParser extends Parser {
|
|||
throw new Error("AssetSourceParser doesn't accept preparsed AST");
|
||||
}
|
||||
const { module } = state;
|
||||
module.buildInfo.strict = true;
|
||||
module.buildMeta.exportsType = "default";
|
||||
state.module.buildMeta.defaultObject = false;
|
||||
/** @type {BuildInfo} */
|
||||
(module.buildInfo).strict = true;
|
||||
/** @type {BuildMeta} */
|
||||
(module.buildMeta).exportsType = "default";
|
||||
/** @type {BuildMeta} */
|
||||
(state.module.buildMeta).defaultObject = false;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|||
this.promises = promises;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
|
||||
* @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
|
||||
*/
|
||||
merge(other) {
|
||||
const promises = new Set(other.promises);
|
||||
for (const p of this.promises) {
|
||||
|
|
|
@ -50,7 +50,7 @@ class IdleFileCachePlugin {
|
|||
let timeSpendInStore = 0;
|
||||
let avgTimeSpendInStore = 0;
|
||||
|
||||
/** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise>} */
|
||||
/** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void>>} */
|
||||
const pendingIdleTasks = new Map();
|
||||
|
||||
compiler.cache.hooks.store.tap(
|
||||
|
@ -171,6 +171,7 @@ class IdleFileCachePlugin {
|
|||
isInitialStore = false;
|
||||
}
|
||||
};
|
||||
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
||||
let idleTimer = undefined;
|
||||
compiler.cache.hooks.beginIdle.tap(
|
||||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
|
||||
|
|
|
@ -22,6 +22,8 @@ const {
|
|||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
|
||||
/** @typedef {import("../logging/Logger").Logger} Logger */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||
|
||||
class PackContainer {
|
||||
|
@ -58,6 +60,9 @@ class PackContainer {
|
|||
writeLazy(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize({ read }) {
|
||||
this.version = read();
|
||||
this.buildSnapshot = read();
|
||||
|
@ -99,7 +104,7 @@ class Pack {
|
|||
constructor(logger, maxAge) {
|
||||
/** @type {Map<string, PackItemInfo>} */
|
||||
this.itemInfo = new Map();
|
||||
/** @type {string[]} */
|
||||
/** @type {(string | undefined)[]} */
|
||||
this.requests = [];
|
||||
this.requestsTimeout = undefined;
|
||||
/** @type {Map<string, PackItemInfo>} */
|
||||
|
@ -111,6 +116,9 @@ class Pack {
|
|||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} identifier identifier
|
||||
*/
|
||||
_addRequest(identifier) {
|
||||
this.requests.push(identifier);
|
||||
if (this.requestsTimeout === undefined) {
|
||||
|
@ -149,7 +157,7 @@ class Pack {
|
|||
if (!this.content[loc]) {
|
||||
return undefined;
|
||||
}
|
||||
return this.content[loc].get(identifier);
|
||||
return /** @type {PackContent} */ (this.content[loc]).get(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +183,7 @@ class Pack {
|
|||
if (loc >= 0) {
|
||||
this._addRequest(identifier);
|
||||
this.freshContent.set(identifier, info);
|
||||
const content = this.content[loc];
|
||||
const content = /** @type {PackContent} */ (this.content[loc]);
|
||||
content.delete(identifier);
|
||||
if (content.items.size === 0) {
|
||||
this.content[loc] = undefined;
|
||||
|
@ -351,11 +359,12 @@ class Pack {
|
|||
mergedIndices = smallUnusedContents;
|
||||
} else return;
|
||||
|
||||
/** @type {PackContent[] } */
|
||||
const mergedContent = [];
|
||||
|
||||
// 3. Remove old content entries
|
||||
for (const i of mergedIndices) {
|
||||
mergedContent.push(this.content[i]);
|
||||
mergedContent.push(/** @type {PackContent} */ (this.content[i]));
|
||||
this.content[i] = undefined;
|
||||
}
|
||||
|
||||
|
@ -364,7 +373,7 @@ class Pack {
|
|||
const mergedItems = new Set();
|
||||
/** @type {Set<string>} */
|
||||
const mergedUsedItems = new Set();
|
||||
/** @type {(function(Map<string, any>): Promise)[]} */
|
||||
/** @type {(function(Map<string, any>): Promise<void>)[]} */
|
||||
const addToMergedMap = [];
|
||||
for (const content of mergedContent) {
|
||||
for (const identifier of content.items) {
|
||||
|
@ -498,17 +507,20 @@ class Pack {
|
|||
* Only runs for one content to avoid large invalidation.
|
||||
*/
|
||||
_gcOldestContent() {
|
||||
/** @type {PackItemInfo} */
|
||||
/** @type {PackItemInfo | undefined} */
|
||||
let oldest = undefined;
|
||||
for (const info of this.itemInfo.values()) {
|
||||
if (oldest === undefined || info.lastAccess < oldest.lastAccess) {
|
||||
oldest = info;
|
||||
}
|
||||
}
|
||||
if (Date.now() - oldest.lastAccess > this.maxAge) {
|
||||
const loc = oldest.location;
|
||||
if (
|
||||
Date.now() - /** @type {PackItemInfo} */ (oldest).lastAccess >
|
||||
this.maxAge
|
||||
) {
|
||||
const loc = /** @type {PackItemInfo} */ (oldest).location;
|
||||
if (loc < 0) return;
|
||||
const content = this.content[loc];
|
||||
const content = /** @type {PackContent} */ (this.content[loc]);
|
||||
const items = new Set(content.items);
|
||||
const usedItems = new Set(content.used);
|
||||
this._gcAndUpdateLocation(items, usedItems, loc);
|
||||
|
@ -771,6 +783,7 @@ class PackContent {
|
|||
|
||||
// We are in state B
|
||||
const { lazyName } = this;
|
||||
/** @type {string | undefined} */
|
||||
let timeMessage;
|
||||
if (lazyName) {
|
||||
// only log once
|
||||
|
@ -811,7 +824,7 @@ class PackContent {
|
|||
|
||||
/**
|
||||
* @param {string} reason explanation why unpack is necessary
|
||||
* @returns {void | Promise} maybe a promise if lazy
|
||||
* @returns {void | Promise<void>} maybe a promise if lazy
|
||||
*/
|
||||
unpack(reason) {
|
||||
if (this.content) return;
|
||||
|
@ -819,6 +832,7 @@ class PackContent {
|
|||
// Move from state B to C
|
||||
if (this.lazy) {
|
||||
const { lazyName } = this;
|
||||
/** @type {string | undefined} */
|
||||
let timeMessage;
|
||||
if (lazyName) {
|
||||
// only log once
|
||||
|
@ -862,6 +876,9 @@ class PackContent {
|
|||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} identifier identifier
|
||||
*/
|
||||
delete(identifier) {
|
||||
this.items.delete(identifier);
|
||||
this.used.delete(identifier);
|
||||
|
@ -906,6 +923,7 @@ class PackContent {
|
|||
}
|
||||
// State B2
|
||||
const { lazyName } = this;
|
||||
/** @type {string | undefined} */
|
||||
let timeMessage;
|
||||
if (lazyName) {
|
||||
// only log once
|
||||
|
@ -1028,17 +1046,20 @@ class PackFileCacheStrategy {
|
|||
this.buildDependencies = new Set();
|
||||
/** @type {LazySet<string>} */
|
||||
this.newBuildDependencies = new LazySet();
|
||||
/** @type {Snapshot} */
|
||||
/** @type {Snapshot | undefined} */
|
||||
this.resolveBuildDependenciesSnapshot = undefined;
|
||||
/** @type {Map<string, string | false>} */
|
||||
/** @type {Map<string, string | false> | undefined} */
|
||||
this.resolveResults = undefined;
|
||||
/** @type {Snapshot} */
|
||||
/** @type {Snapshot | undefined} */
|
||||
this.buildSnapshot = undefined;
|
||||
/** @type {Promise<Pack>} */
|
||||
/** @type {Promise<Pack> | undefined} */
|
||||
this.packPromise = this._openPack();
|
||||
this.storePromise = Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Pack>} pack
|
||||
*/
|
||||
_getPack() {
|
||||
if (this.packPromise === undefined) {
|
||||
this.packPromise = this.storePromise.then(() => this._openPack());
|
||||
|
|
|
@ -18,7 +18,7 @@ class RemoteRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { compilation, chunkGraph } = this;
|
||||
|
|
|
@ -56,7 +56,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { compilation, chunk, _runtimeRequirements } = this;
|
||||
|
|
|
@ -14,7 +14,7 @@ class AMDDefineRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return Template.asString([
|
||||
|
@ -35,7 +35,7 @@ class AMDOptionsRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return Template.asString([
|
||||
|
|
|
@ -21,6 +21,7 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
|
|||
/** @typedef {import("estree").Expression} Expression */
|
||||
/** @typedef {import("estree").Super} Super */
|
||||
|
||||
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("../NormalModule")} NormalModule */
|
||||
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
||||
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
||||
|
@ -43,7 +44,7 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
|
|||
* ```
|
||||
*
|
||||
* @param {TODO} expr expression
|
||||
* @returns {Expression} returns the value of property descriptor
|
||||
* @returns {Expression | undefined} returns the value of property descriptor
|
||||
*/
|
||||
const getValueOfPropertyDescription = expr => {
|
||||
if (expr.type !== "ObjectExpression") return;
|
||||
|
@ -127,6 +128,9 @@ const parseRequireCall = (parser, expr) => {
|
|||
};
|
||||
|
||||
class CommonJsExportsParserPlugin {
|
||||
/**
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
*/
|
||||
constructor(moduleGraph) {
|
||||
this.moduleGraph = moduleGraph;
|
||||
}
|
||||
|
@ -143,7 +147,7 @@ class CommonJsExportsParserPlugin {
|
|||
/**
|
||||
* @param {boolean} topLevel true, when the export is on top level
|
||||
* @param {string[]} members members of the export
|
||||
* @param {Expression} valueExpr expression for the value
|
||||
* @param {Expression | undefined} valueExpr expression for the value
|
||||
* @returns {void}
|
||||
*/
|
||||
const checkNamespace = (topLevel, members, valueExpr) => {
|
||||
|
@ -156,10 +160,16 @@ class CommonJsExportsParserPlugin {
|
|||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @param {string=} reason reason
|
||||
*/
|
||||
const bailout = reason => {
|
||||
DynamicExports.bailout(parser.state);
|
||||
if (reason) bailoutHint(reason);
|
||||
};
|
||||
/**
|
||||
* @param {string} reason reason
|
||||
*/
|
||||
const bailoutHint = reason => {
|
||||
this.moduleGraph
|
||||
.getOptimizationBailout(parser.state.module)
|
||||
|
@ -292,8 +302,8 @@ class CommonJsExportsParserPlugin {
|
|||
* @param {Expression | Super} expr expression
|
||||
* @param {CommonJSDependencyBaseKeywords} base commonjs base keywords
|
||||
* @param {string[]} members members of the export
|
||||
* @param {CallExpression} call call expression
|
||||
* @returns {boolean} true, when the expression was handled
|
||||
* @param {CallExpression=} call call expression
|
||||
* @returns {boolean | void} true, when the expression was handled
|
||||
*/
|
||||
const handleAccessExport = (expr, base, members, call = undefined) => {
|
||||
if (HarmonyExports.isEnabled(parser.state)) return;
|
||||
|
|
|
@ -29,8 +29,11 @@ const RequireResolveContextDependency = require("./RequireResolveContextDependen
|
|||
const RequireResolveDependency = require("./RequireResolveDependency");
|
||||
const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency");
|
||||
|
||||
/** @typedef {import("estree").CallExpression} CallExpressionNode */
|
||||
/** @typedef {import("estree").CallExpression} CallExpression */
|
||||
/** @typedef {import("estree").Expression} Expression */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
||||
/** @typedef {import("../javascript/JavascriptParser").ImportSource} ImportSource */
|
||||
|
||||
const createRequireSpecifierTag = Symbol("createRequire");
|
||||
const createdRequireIdentifierTag = Symbol("createRequire()");
|
||||
|
@ -43,6 +46,10 @@ class CommonJsImportsParserPlugin {
|
|||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(parser) {
|
||||
const options = this.options;
|
||||
|
||||
|
@ -138,6 +145,10 @@ class CommonJsImportsParserPlugin {
|
|||
//#endregion
|
||||
|
||||
//#region Renaming
|
||||
/**
|
||||
* @param {Expression} expr expression
|
||||
* @returns {boolean} true when set undefined
|
||||
*/
|
||||
const defineUndefined = expr => {
|
||||
// To avoid "not defined" error, replace the value with undefined
|
||||
const dep = new ConstDependency("undefined", expr.range);
|
||||
|
@ -319,12 +330,22 @@ class CommonJsImportsParserPlugin {
|
|||
//#endregion
|
||||
|
||||
//#region Require with property access
|
||||
/**
|
||||
* @param {Expression} expr expression
|
||||
* @param {string[]} calleeMembers callee members
|
||||
* @param {CallExpression} callExpr call expression
|
||||
* @param {string[]} members members
|
||||
* @returns {boolean | void} true when handled
|
||||
*/
|
||||
const chainHandler = (expr, calleeMembers, callExpr, members) => {
|
||||
if (callExpr.arguments.length !== 1) return;
|
||||
const param = parser.evaluateExpression(callExpr.arguments[0]);
|
||||
if (param.isString() && !getLocalModule(parser.state, param.string)) {
|
||||
if (
|
||||
param.isString() &&
|
||||
!getLocalModule(parser.state, /** @type {string} */ (param.string))
|
||||
) {
|
||||
const dep = new CommonJsFullRequireDependency(
|
||||
param.string,
|
||||
/** @type {string} */ (param.string),
|
||||
expr.range,
|
||||
members
|
||||
);
|
||||
|
@ -335,12 +356,22 @@ class CommonJsImportsParserPlugin {
|
|||
return true;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @param {CallExpression} expr expression
|
||||
* @param {string[]} calleeMembers callee members
|
||||
* @param {CallExpression} callExpr call expression
|
||||
* @param {string[]} members members
|
||||
* @returns {boolean | void} true when handled
|
||||
*/
|
||||
const callChainHandler = (expr, calleeMembers, callExpr, members) => {
|
||||
if (callExpr.arguments.length !== 1) return;
|
||||
const param = parser.evaluateExpression(callExpr.arguments[0]);
|
||||
if (param.isString() && !getLocalModule(parser.state, param.string)) {
|
||||
if (
|
||||
param.isString() &&
|
||||
!getLocalModule(parser.state, /** @type {string} */ (param.string))
|
||||
) {
|
||||
const dep = new CommonJsFullRequireDependency(
|
||||
param.string,
|
||||
/** @type {string} */ (param.string),
|
||||
expr.callee.range,
|
||||
members
|
||||
);
|
||||
|
@ -444,7 +475,9 @@ class CommonJsImportsParserPlugin {
|
|||
|
||||
if (!options.createRequire) return;
|
||||
|
||||
/** @type {ImportSource[]} */
|
||||
let moduleName = [];
|
||||
/** @type {string | undefined} */
|
||||
let specifierName;
|
||||
|
||||
if (options.createRequire === true) {
|
||||
|
@ -509,8 +542,8 @@ class CommonJsImportsParserPlugin {
|
|||
.for(createdRequireIdentifierTag)
|
||||
.tap("CommonJsImportsParserPlugin", createRequireHandler(false));
|
||||
/**
|
||||
* @param {CallExpressionNode} expr call expression
|
||||
* @returns {string} context
|
||||
* @param {CallExpression} expr call expression
|
||||
* @returns {string | void} context
|
||||
*/
|
||||
const parseCreateRequireArguments = expr => {
|
||||
const args = expr.arguments;
|
||||
|
@ -532,9 +565,9 @@ class CommonJsImportsParserPlugin {
|
|||
parser.state.module.addWarning(err);
|
||||
return;
|
||||
}
|
||||
const ctx = evaluated.string.startsWith("file://")
|
||||
? fileURLToPath(evaluated.string)
|
||||
: evaluated.string;
|
||||
const ctx = /** @type {string} */ (evaluated.string).startsWith("file://")
|
||||
? fileURLToPath(/** @type {string} */ (evaluated.string))
|
||||
: /** @type {string} */ (evaluated.string);
|
||||
// argument always should be a filename
|
||||
return ctx.slice(0, ctx.lastIndexOf(ctx.startsWith("/") ? "/" : "\\"));
|
||||
};
|
||||
|
@ -586,9 +619,9 @@ class CommonJsImportsParserPlugin {
|
|||
declarator.init.callee.type !== "Identifier"
|
||||
)
|
||||
return;
|
||||
const variableInfo = parser.getVariableInfo(
|
||||
declarator.init.callee.name
|
||||
);
|
||||
const variableInfo =
|
||||
/** @type {TODO} */
|
||||
(parser.getVariableInfo(declarator.init.callee.name));
|
||||
if (
|
||||
variableInfo &&
|
||||
variableInfo.tagInfo &&
|
||||
|
|
|
@ -35,6 +35,7 @@ const {
|
|||
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
||||
|
||||
|
@ -250,10 +251,10 @@ class HarmonyModuleDecoratorRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { runtimeTemplate } = this.compilation;
|
||||
const { runtimeTemplate } = /** @type {Compilation} */ (this.compilation);
|
||||
return Template.asString([
|
||||
`${
|
||||
RuntimeGlobals.harmonyModuleDecorator
|
||||
|
@ -280,10 +281,10 @@ class NodeModuleDecoratorRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { runtimeTemplate } = this.compilation;
|
||||
const { runtimeTemplate } = /** @type {Compilation} */ (this.compilation);
|
||||
return Template.asString([
|
||||
`${RuntimeGlobals.nodeModuleDecorator} = ${runtimeTemplate.basicFunction(
|
||||
"module",
|
||||
|
|
|
@ -18,7 +18,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
|
|||
* @param {TODO} options options for the context module
|
||||
* @param {Range} range location in source code
|
||||
* @param {Range} valueRange location of the require call
|
||||
* @param {boolean} inShorthand true, if the require call is in shorthand notation
|
||||
* @param {boolean | string } inShorthand true or name
|
||||
* @param {string} context context
|
||||
*/
|
||||
constructor(options, range, valueRange, inShorthand, context) {
|
||||
|
|
|
@ -15,7 +15,7 @@ class SystemRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return Template.asString([
|
||||
|
|
|
@ -20,7 +20,7 @@ class ExportWebpackRequireRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return `export default ${RuntimeGlobals.require};`;
|
||||
|
|
|
@ -80,7 +80,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -14,7 +14,7 @@ class HotModuleReplacementRuntimeModule extends RuntimeModule {
|
|||
super("hot module replacement", RuntimeModule.STAGE_BASIC);
|
||||
}
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return Template.getFunctionContent(
|
||||
|
|
|
@ -36,7 +36,7 @@ class HashedModuleIdsPlugin {
|
|||
|
||||
/** @type {HashedModuleIdsPluginOptions} */
|
||||
this.options = {
|
||||
context: null,
|
||||
context: undefined,
|
||||
hashFunction: "md4",
|
||||
hashDigest: "base64",
|
||||
hashDigestLength: 4,
|
||||
|
|
|
@ -349,7 +349,7 @@ class JavascriptParser extends Parser {
|
|||
importCall: new SyncBailHook(["expression"]),
|
||||
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
||||
topLevelAwait: new SyncBailHook(["expression"]),
|
||||
/** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
|
||||
/** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
|
||||
call: new HookMap(() => new SyncBailHook(["expression"])),
|
||||
/** Something like "a.b()" */
|
||||
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
|
||||
|
@ -374,7 +374,7 @@ class JavascriptParser extends Parser {
|
|||
])
|
||||
),
|
||||
/** Something like "a.b().c.d()"" */
|
||||
/** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
|
||||
/** @type {HookMap<SyncBailHook<[CallExpression, string[], CallExpression, string[]], boolean | void>>} */
|
||||
callMemberChainOfCallMemberChain: new HookMap(
|
||||
() =>
|
||||
new SyncBailHook([
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const SyncBailHook = require("tapable/lib/SyncBailHook");
|
||||
const { SyncBailHook } = require("tapable");
|
||||
const { Logger } = require("./Logger");
|
||||
const createConsoleLogger = require("./createConsoleLogger");
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { chunkGraph, chunk } = this;
|
||||
|
|
|
@ -46,7 +46,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { chunkGraph, chunk } = this;
|
||||
|
|
|
@ -16,6 +16,7 @@ const InnerGraph = require("./InnerGraph");
|
|||
/** @typedef {import("estree").ClassExpression} ClassExpressionNode */
|
||||
/** @typedef {import("estree").Node} Node */
|
||||
/** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
|
||||
|
@ -46,7 +47,7 @@ class InnerGraphPlugin {
|
|||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @param {Object} parserOptions options
|
||||
* @param {JavascriptParserOptions} parserOptions options
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = (parser, parserOptions) => {
|
||||
|
|
|
@ -24,7 +24,7 @@ class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { runtimeFunction, runtimeHandlers } = this;
|
||||
|
|
|
@ -22,7 +22,7 @@ class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { startupChunks } = this;
|
||||
|
|
|
@ -21,7 +21,7 @@ class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { chunkMap } = this;
|
||||
|
|
|
@ -21,7 +21,7 @@ class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { chunkMap } = this;
|
||||
|
|
|
@ -16,7 +16,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -18,7 +18,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -17,7 +17,7 @@ class BaseUriRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const chunk = /** @type {Chunk} */ (this.chunk);
|
||||
|
|
|
@ -17,7 +17,7 @@ class ChunkNameRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return `${RuntimeGlobals.chunkName} = ${JSON.stringify(this.chunkName)};`;
|
||||
|
|
|
@ -16,7 +16,7 @@ class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -19,7 +19,7 @@ class CompatRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class CreateScriptRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -20,7 +20,7 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -35,7 +35,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { global, contentType, getFilenameForChunk, allChunks } = this;
|
||||
|
|
|
@ -16,7 +16,7 @@ class GetFullHashRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -24,7 +24,7 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { global, filename } = this;
|
||||
|
|
|
@ -20,7 +20,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -14,7 +14,7 @@ class GlobalRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return Template.asString([
|
||||
|
|
|
@ -17,7 +17,7 @@ class HasOwnPropertyRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -53,7 +53,7 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -14,7 +14,7 @@ class NonceRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return `${RuntimeGlobals.scriptNonce} = undefined;`;
|
||||
|
|
|
@ -16,7 +16,7 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -20,7 +20,7 @@ class PublicPathRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const { publicPath } = this;
|
||||
|
|
|
@ -16,7 +16,7 @@ class RelativeUrlRuntimeModule extends HelperRuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -16,7 +16,7 @@ class RuntimeIdRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
||||
|
|
|
@ -23,7 +23,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
||||
|
|
|
@ -20,7 +20,7 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -15,7 +15,7 @@ class SystemContextRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
return `${RuntimeGlobals.systemContext} = __system_context__;`;
|
||||
|
|
|
@ -32,7 +32,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -23,7 +23,7 @@ class ShareRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -29,7 +29,7 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -226,7 +226,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const fn = RuntimeGlobals.ensureChunkHandlers;
|
||||
|
|
|
@ -70,7 +70,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -59,7 +59,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {string} runtime code
|
||||
* @returns {string | null} runtime code
|
||||
*/
|
||||
generate() {
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
"@babel/core": "^7.21.4",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/mime-types": "^2.1.1",
|
||||
"@types/node": "^20.1.7",
|
||||
"assemblyscript": "^0.27.2",
|
||||
"babel-loader": "^8.1.0",
|
||||
|
|
|
@ -13,7 +13,6 @@ import {
|
|||
AssignmentPattern,
|
||||
AssignmentProperty,
|
||||
AwaitExpression,
|
||||
BaseCallExpression,
|
||||
BigIntLiteral,
|
||||
BinaryExpression,
|
||||
BlockStatement,
|
||||
|
@ -4232,7 +4231,11 @@ declare interface ExternalItemObjectUnknown {
|
|||
}
|
||||
type ExternalItemValue = string | boolean | string[] | { [index: string]: any };
|
||||
declare class ExternalModule extends Module {
|
||||
constructor(request?: any, type?: any, userRequest?: any);
|
||||
constructor(
|
||||
request: string | string[] | Record<string, string | string[]>,
|
||||
type: any,
|
||||
userRequest: string
|
||||
);
|
||||
request: string | string[] | Record<string, string | string[]>;
|
||||
externalType: string;
|
||||
userRequest: string;
|
||||
|
@ -4348,6 +4351,9 @@ declare interface FactorizeModuleOptions {
|
|||
contextInfo?: Partial<ModuleFactoryCreateDataContextInfo>;
|
||||
context?: string;
|
||||
}
|
||||
declare interface FactoryMeta {
|
||||
sideEffectFree?: boolean;
|
||||
}
|
||||
type FakeHook<T> = T & FakeHookMarker;
|
||||
declare interface FakeHookMarker {}
|
||||
declare interface FallbackCacheGroup {
|
||||
|
@ -5119,8 +5125,8 @@ declare abstract class InitFragment<Context> {
|
|||
endContent?: string | Source;
|
||||
getContent(context: Context): string | Source;
|
||||
getEndContent(context: Context): undefined | string | Source;
|
||||
serialize(context?: any): void;
|
||||
deserialize(context?: any): void;
|
||||
serialize(context: ObjectSerializerContext): void;
|
||||
deserialize(context: ObjectDeserializerContext): void;
|
||||
merge: any;
|
||||
}
|
||||
declare interface InputFileSystem {
|
||||
|
@ -5502,7 +5508,7 @@ declare class JavascriptParser extends Parser {
|
|||
typeof: HookMap<SyncBailHook<[Expression], boolean | void>>;
|
||||
importCall: SyncBailHook<[ImportExpression], boolean | void>;
|
||||
topLevelAwait: SyncBailHook<[Expression], boolean | void>;
|
||||
call: HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>;
|
||||
call: HookMap<SyncBailHook<[CallExpression], boolean | void>>;
|
||||
callMemberChain: HookMap<
|
||||
SyncBailHook<
|
||||
[CallExpression, string[], boolean[], [number, number][]],
|
||||
|
@ -5517,7 +5523,7 @@ declare class JavascriptParser extends Parser {
|
|||
>;
|
||||
callMemberChainOfCallMemberChain: HookMap<
|
||||
SyncBailHook<
|
||||
[Expression, string[], CallExpression, string[]],
|
||||
[CallExpression, string[], CallExpression, string[]],
|
||||
boolean | void
|
||||
>
|
||||
>;
|
||||
|
@ -6884,14 +6890,45 @@ declare interface LibIdentOptions {
|
|||
associatedObjectForCache?: Object;
|
||||
}
|
||||
declare class LibManifestPlugin {
|
||||
constructor(options?: any);
|
||||
options: any;
|
||||
constructor(options: LibManifestPluginOptions);
|
||||
options: LibManifestPluginOptions;
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
*/
|
||||
apply(compiler: Compiler): void;
|
||||
}
|
||||
declare interface LibManifestPluginOptions {
|
||||
/**
|
||||
* Context of requests in the manifest file (defaults to the webpack context).
|
||||
*/
|
||||
context?: string;
|
||||
|
||||
/**
|
||||
* If true, only entry points will be exposed (default: true).
|
||||
*/
|
||||
entryOnly?: boolean;
|
||||
|
||||
/**
|
||||
* If true, manifest json file (output) will be formatted.
|
||||
*/
|
||||
format?: boolean;
|
||||
|
||||
/**
|
||||
* Name of the exposed dll function (external name, use value of 'output.library').
|
||||
*/
|
||||
name?: string;
|
||||
|
||||
/**
|
||||
* Absolute path to the manifest json file (output).
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* Type of the dll bundle (external type, use value of 'output.libraryTarget').
|
||||
*/
|
||||
type?: string;
|
||||
}
|
||||
declare interface LibraryContext<T> {
|
||||
compilation: Compilation;
|
||||
chunkGraph: ChunkGraph;
|
||||
|
@ -7470,7 +7507,7 @@ declare class Module extends DependenciesBlock {
|
|||
needId: boolean;
|
||||
debugId: number;
|
||||
resolveOptions?: ResolveOptionsWebpackOptions;
|
||||
factoryMeta?: object;
|
||||
factoryMeta?: FactoryMeta;
|
||||
useSourceMap: boolean;
|
||||
useSimpleSourceMap: boolean;
|
||||
buildMeta?: BuildMeta;
|
||||
|
@ -8042,7 +8079,7 @@ declare abstract class ModuleProfile {
|
|||
storingEndTime: number;
|
||||
storing: number;
|
||||
storingParallelismFactor: number;
|
||||
additionalFactoryTimes: any;
|
||||
additionalFactoryTimes?: { start: number; end: number }[];
|
||||
additionalFactories: number;
|
||||
additionalFactoriesParallelismFactor: number;
|
||||
additionalIntegration: number;
|
||||
|
@ -11151,8 +11188,8 @@ declare class RuntimeModule extends Module {
|
|||
fullHash: boolean;
|
||||
dependentHash: boolean;
|
||||
attach(compilation: Compilation, chunk: Chunk, chunkGraph?: ChunkGraph): void;
|
||||
generate(): string;
|
||||
getGeneratedCode(): string;
|
||||
generate(): null | string;
|
||||
getGeneratedCode(): null | string;
|
||||
shouldIsolate(): boolean;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1150,6 +1150,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
|
||||
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
|
||||
|
||||
"@types/mime-types@^2.1.1":
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/mime-types/-/mime-types-2.1.1.tgz#d9ba43490fa3a3df958759adf69396c3532cf2c1"
|
||||
integrity sha512-vXOTGVSLR2jMw440moWTC7H19iUyLtP3Z1YTj7cSsubOICinjMxFeb/V57v9QdyyPGbbWolUFSSmSiRSn94tFw==
|
||||
|
||||
"@types/minimist@^1.2.2":
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
|
||||
|
|
Loading…
Reference in New Issue