diff --git a/declarations.d.ts b/declarations.d.ts index 9aa29ae97..ea8453ea7 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -1,4 +1,3 @@ -type TODO = any; type EXPECTED_ANY = any; type EXPECTED_FUNCTION = Function; type EXPECTED_OBJECT = object; diff --git a/declarations/LoaderContext.d.ts b/declarations/LoaderContext.d.ts index f1baa7e8d..34f859514 100644 --- a/declarations/LoaderContext.d.ts +++ b/declarations/LoaderContext.d.ts @@ -10,8 +10,9 @@ import type Hash from "../lib/util/Hash"; import type { InputFileSystem } from "../lib/util/fs"; import type { Logger } from "../lib/logging/Logger"; import type { + ImportModuleOptions, ImportModuleCallback, - ImportModuleOptions + ExecuteModuleExports } from "../lib/dependencies/LoaderPlugin"; import type { Resolver } from "enhanced-resolve"; import type { @@ -92,7 +93,10 @@ export interface LoaderPluginLoaderContext { options: ImportModuleOptions | undefined, callback: ImportModuleCallback ): void; - importModule(request: string, options?: ImportModuleOptions): Promise; + importModule( + request: string, + options?: ImportModuleOptions + ): Promise; } /** The properties are added by https://github.com/webpack/loader-runner */ diff --git a/lib/CompatibilityPlugin.js b/lib/CompatibilityPlugin.js index ef3e78c34..3a8145834 100644 --- a/lib/CompatibilityPlugin.js +++ b/lib/CompatibilityPlugin.js @@ -19,7 +19,19 @@ const ConstDependency = require("./dependencies/ConstDependency"); /** @typedef {import("./dependencies/ContextDependency")} ContextDependency */ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */ /** @typedef {import("./javascript/JavascriptParser").Range} Range */ -/** @typedef {import("./javascript/JavascriptParser").TagData} TagData */ + +/** + * @typedef {object} CompatibilitySettingsDeclaration + * @property {boolean} updated + * @property {DependencyLocation} loc + * @property {Range} range + */ + +/** + * @typedef {object} CompatibilitySettings + * @property {string} name + * @property {CompatibilitySettingsDeclaration} declaration + */ const nestedWebpackIdentifierTag = Symbol("nested webpack identifier"); const PLUGIN_NAME = "CompatibilityPlugin"; @@ -103,7 +115,8 @@ class CompatibilityPlugin { statement.id.name === RuntimeGlobals.require ) { const newName = `__nested_webpack_require_${ - /** @type {Range} */ (statement.range)[0] + /** @type {Range} */ + (statement.range)[0] }__`; parser.tagVariable( statement.id.name, @@ -112,8 +125,8 @@ class CompatibilityPlugin { name: newName, declaration: { updated: false, - loc: statement.id.loc, - range: statement.id.range + loc: /** @type {DependencyLocation} */ (statement.id.loc), + range: /** @type {Range} */ (statement.id.range) } } ); @@ -130,8 +143,8 @@ class CompatibilityPlugin { name: newName, declaration: { updated: false, - loc: pattern.loc, - range: pattern.range + loc: /** @type {DependencyLocation} */ (pattern.loc), + range: /** @type {Range} */ (pattern.range) } }); return true; @@ -143,8 +156,8 @@ class CompatibilityPlugin { name: "__nested_webpack_exports__", declaration: { updated: false, - loc: pattern.loc, - range: pattern.range + loc: /** @type {DependencyLocation} */ (pattern.loc), + range: /** @type {Range} */ (pattern.range) } }); return true; @@ -153,7 +166,7 @@ class CompatibilityPlugin { .for(nestedWebpackIdentifierTag) .tap(PLUGIN_NAME, (expr) => { const { name, declaration } = - /** @type {TagData} */ + /** @type {CompatibilitySettings} */ (parser.currentTagData); if (!declaration.updated) { const dep = new ConstDependency(name, declaration.range); diff --git a/lib/Compilation.js b/lib/Compilation.js index def82b382..3efa18994 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -721,7 +721,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si processAssetsHook.tapAsync( getOptions(options), (assets, callback) => - /** @type {TODO} */ (fn)(...getArgs(), callback) + /** @type {EXPECTED_ANY} */ (fn)(...getArgs(), callback) ); }, /** @type {AsyncSeriesHook["tapPromise"]} */ @@ -1087,9 +1087,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.moduleMemCaches = undefined; /** @type {ModuleMemCaches | undefined} */ this.moduleMemCaches2 = undefined; + /** @type {ModuleGraph} */ this.moduleGraph = new ModuleGraph(); /** @type {ChunkGraph} */ - this.chunkGraph = /** @type {TODO} */ (undefined); + this.chunkGraph = new ChunkGraph( + this.moduleGraph, + this.outputOptions.hashFunction + ); /** @type {CodeGenerationResults | undefined} */ this.codeGenerationResults = undefined; @@ -3128,15 +3132,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.addModuleQueue.clear(); return callback(err); }; - const chunkGraph = new ChunkGraph( - this.moduleGraph, - this.outputOptions.hashFunction - ); - this.chunkGraph = chunkGraph; if (this._backCompat) { for (const module of this.modules) { - ChunkGraph.setChunkGraphForModule(module, chunkGraph); + ChunkGraph.setChunkGraphForModule(module, this.chunkGraph); } } @@ -3181,7 +3180,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si const module = this.moduleGraph.getModule(dep); if (module) { - chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint); + this.chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint); entryModules.add(module); const modulesList = chunkGraphInit.get(entrypoint); if (modulesList === undefined) { diff --git a/lib/Compiler.js b/lib/Compiler.js index c0e8f994d..46156d927 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -82,6 +82,7 @@ const webpack = require("."); * @param {Error | null} err * @param {Chunk[]=} entries * @param {Compilation=} compilation + * @returns {void} */ /** diff --git a/lib/ContextModule.js b/lib/ContextModule.js index 3ef3c844b..42df380a6 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -97,6 +97,7 @@ const makeSerializable = require("./util/makeSerializable"); * @callback ResolveDependenciesCallback * @param {Error | null} err * @param {ContextElementDependency[]=} dependencies + * @returns {void} */ /** diff --git a/lib/ContextModuleFactory.js b/lib/ContextModuleFactory.js index 062e12d8d..7f7aac350 100644 --- a/lib/ContextModuleFactory.js +++ b/lib/ContextModuleFactory.js @@ -45,7 +45,7 @@ const { join } = require("./util/fs"); */ /** @typedef {ContextResolveData & ContextOptions} BeforeContextResolveData */ -/** @typedef {BeforeContextResolveData & { resource: TODO, resourceQuery: string | undefined, resourceFragment: string | undefined, resolveDependencies: ContextModuleFactory["resolveDependencies"] }} AfterContextResolveData */ +/** @typedef {BeforeContextResolveData & { resource: string | string[], resourceQuery: string | undefined, resourceFragment: string | undefined, resolveDependencies: ContextModuleFactory["resolveDependencies"] }} AfterContextResolveData */ const EMPTY_RESOLVE_OPTIONS = {}; @@ -228,7 +228,7 @@ class ContextModuleFactory extends ModuleFactory { }, (err, result) => { if (err) return callback(err); - callback(null, /** @type {string} */ (result)); + callback(null, result); } ); }, @@ -355,6 +355,7 @@ class ContextModuleFactory extends ModuleFactory { * @param {string} directory directory * @param {(context: string, subResource: string, callback: () => void) => void} addSubDirectory addSubDirectoryFn * @param {ResolveDependenciesCallback} callback callback + * @returns {void} */ const addDirectory = (ctx, directory, addSubDirectory, callback) => { fs.readdir(directory, (err, files) => { diff --git a/lib/ContextReplacementPlugin.js b/lib/ContextReplacementPlugin.js index d0b481de5..b66fbcadb 100644 --- a/lib/ContextReplacementPlugin.js +++ b/lib/ContextReplacementPlugin.js @@ -124,7 +124,14 @@ class ContextReplacementPlugin { }); cmf.hooks.afterResolve.tap(PLUGIN_NAME, (result) => { if (!result) return; - if (resourceRegExp.test(result.resource)) { + const isMatchResourceRegExp = () => { + if (Array.isArray(result.resource)) { + return result.resource.some((item) => resourceRegExp.test(item)); + } + + return resourceRegExp.test(result.resource); + }; + if (isMatchResourceRegExp()) { if (newContentResource !== undefined) { if ( newContentResource.startsWith("/") || @@ -132,10 +139,15 @@ class ContextReplacementPlugin { ) { result.resource = newContentResource; } else { + const rootPath = + typeof result.resource === "string" + ? result.resource + : /** @type {string} */ + (result.resource.find((item) => resourceRegExp.test(item))); result.resource = join( /** @type {InputFileSystem} */ (compiler.inputFileSystem), - result.resource, + rootPath, newContentResource ); } @@ -155,18 +167,27 @@ class ContextReplacementPlugin { if (typeof newContentCallback === "function") { const origResource = result.resource; newContentCallback(result); - if ( - result.resource !== origResource && - !result.resource.startsWith("/") && - (result.resource.length <= 1 || result.resource[1] !== ":") - ) { - // When the function changed it to an relative path - result.resource = join( - /** @type {InputFileSystem} */ - (compiler.inputFileSystem), - origResource, - result.resource - ); + if (result.resource !== origResource) { + const newResource = Array.isArray(result.resource) + ? result.resource + : [result.resource]; + + for (let i = 0; i < newResource.length; i++) { + if ( + !newResource[i].startsWith("/") && + (newResource[i].length <= 1 || newResource[i][1] !== ":") + ) { + // When the function changed it to an relative path + newResource[i] = join( + /** @type {InputFileSystem} */ + (compiler.inputFileSystem), + origResource[i], + newResource[i] + ); + } + } + + result.resource = newResource; } } else { for (const d of result.dependencies) { diff --git a/lib/ExportsInfo.js b/lib/ExportsInfo.js index ade80eee7..c3b0df908 100644 --- a/lib/ExportsInfo.js +++ b/lib/ExportsInfo.js @@ -108,7 +108,7 @@ class ExportsInfo { constructor() { /** @type {Exports} */ this._exports = new Map(); - this._otherExportsInfo = new ExportInfo(/** @type {TODO} */ (null)); + this._otherExportsInfo = new ExportInfo(null); this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*"); this._exportsAreOrdered = false; /** @type {ExportsInfo=} */ @@ -847,12 +847,12 @@ class ExportsInfo { class ExportInfo { /** - * @param {ExportInfoName} name the original name of the export + * @param {ExportInfoName | null} name the original name of the export * @param {ExportInfo=} initFrom init values from this ExportInfo */ constructor(name, initFrom) { /** @type {ExportInfoName} */ - this.name = name; + this.name = /** @type {ExportInfoName} */ (name); /** * @private * @type {ExportInfoUsedName} diff --git a/lib/Module.js b/lib/Module.js index 3c247a4be..4ddd01d8e 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -98,7 +98,7 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {Set} RuntimeRequirements */ /** @typedef {ReadonlySet} ReadOnlyRuntimeRequirements */ -/** @typedef {Map<"topLevelDeclarations", Set> & Map<"chunkInitFragments", InitFragment[]>} KnownCodeGenerationResultDataForJavascriptModules */ +/** @typedef {Map<"topLevelDeclarations", Set> & Map<"chunkInitFragments", InitFragment[]>} KnownCodeGenerationResultDataForJavascriptModules */ /** @typedef {Map<"url", { ["css-url"]: string }>} KnownCodeGenerationResultDataForCssModules */ /** @typedef {Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"fullContentHash", string>} KnownCodeGenerationResultDataForAssetModules */ /** @typedef {Map<"share-init", [{ shareScope: string, initStage: number, init: string }]>} KnownCodeGenerationResultForSharing */ diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index ff29bb00e..a646d083c 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -44,6 +44,7 @@ const ArrayQueue = require("./util/ArrayQueue"); * @callback RunWithDependenciesHandler * @param {Compiler} compiler * @param {Callback} callback + * @returns {void} */ /** diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 6f8c5986c..4cb24cfbb 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -308,13 +308,13 @@ class NormalModuleFactory extends ModuleFactory { module: new SyncWaterfallHook(["module", "createData", "resolveData"]), /** @type {HookMap>} */ createParser: new HookMap(() => new SyncBailHook(["parserOptions"])), - /** @type {HookMap>} */ + /** @type {HookMap>} */ parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])), /** @type {HookMap>} */ createGenerator: new HookMap( () => new SyncBailHook(["generatorOptions"]) ), - /** @type {HookMap>} */ + /** @type {HookMap>} */ generator: new HookMap( () => new SyncHook(["generator", "generatorOptions"]) ), diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index dd0818b34..3c2803618 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -144,6 +144,9 @@ class Profiler { return Promise.resolve(); } + /** + * @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result + */ stopProfiling() { return this.sendCommand("Profiler.stop").then(({ profile }) => { const hrtime = process.hrtime(); @@ -280,7 +283,10 @@ class ProfilingPlugin { (hookName) ]; if (hook) { - hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName)); + hook.intercept( + /** @type {EXPECTED_ANY} */ + (makeInterceptorFor("Resolver", tracer)(hookName)) + ); } } @@ -467,9 +473,10 @@ const interceptAllCssModulesPluginHooks = (compilation, tracer) => { /** @typedef {(...args: EXPECTED_ANY[]) => EXPECTED_ANY | Promise<(...args: EXPECTED_ANY[]) => EXPECTED_ANY>} PluginFunction */ /** + * @template T * @param {string} instance instance * @param {Trace} tracer tracer - * @returns {(hookName: string) => TODO} interceptor + * @returns {(hookName: string) => HookInterceptor} interceptor */ const makeInterceptorFor = (instance, tracer) => (hookName) => ({ /** diff --git a/lib/dependencies/CommonJsImportsParserPlugin.js b/lib/dependencies/CommonJsImportsParserPlugin.js index 9bb81115c..25cea6a33 100644 --- a/lib/dependencies/CommonJsImportsParserPlugin.js +++ b/lib/dependencies/CommonJsImportsParserPlugin.js @@ -39,6 +39,12 @@ const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency /** @typedef {import("../javascript/JavascriptParser").ImportSource} ImportSource */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ +/** + * @typedef {object} CommonJsImportSettings + * @property {string=} name + * @property {string} context + */ + const createRequireSpecifierTag = Symbol("createRequire"); const createdRequireIdentifierTag = Symbol("createRequire()"); @@ -58,10 +64,11 @@ class CommonJsImportsParserPlugin { */ apply(parser) { const options = this.options; - const getContext = () => { if (parser.currentTagData) { - const { context } = parser.currentTagData; + const { context } = + /** @type {CommonJsImportSettings} */ + (parser.currentTagData); return context; } }; diff --git a/lib/dependencies/CommonJsRequireContextDependency.js b/lib/dependencies/CommonJsRequireContextDependency.js index 68f9e6640..181330234 100644 --- a/lib/dependencies/CommonJsRequireContextDependency.js +++ b/lib/dependencies/CommonJsRequireContextDependency.js @@ -20,7 +20,7 @@ class CommonJsRequireContextDependency extends ContextDependency { * @param {Range} range location in source code * @param {Range | undefined} valueRange location of the require call * @param {boolean | string } inShorthand true or name - * @param {string} context context + * @param {string=} context context */ constructor(options, range, valueRange, inShorthand, context) { super(options, context); diff --git a/lib/dependencies/ContextDependency.js b/lib/dependencies/ContextDependency.js index d72c4faed..742ba32cf 100644 --- a/lib/dependencies/ContextDependency.js +++ b/lib/dependencies/ContextDependency.js @@ -10,6 +10,7 @@ const DependencyTemplate = require("../DependencyTemplate"); const makeSerializable = require("../util/makeSerializable"); const memoize = require("../util/memoize"); +/** @typedef {import("../javascript/JavascriptParser").Range} Range */ /** @typedef {import("../ContextModule").ContextOptions} ContextOptions */ /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */ /** @typedef {import("../ModuleGraph")} ModuleGraph */ @@ -23,6 +24,8 @@ const getCriticalDependencyWarning = memoize(() => /** @typedef {ContextOptions & { request: string }} ContextDependencyOptions */ +/** @typedef {{ value: string, range: Range }[]} Replaces */ + /** * @param {RegExp | false | null | undefined} r regexp * @returns {string} stringified regexp @@ -52,12 +55,15 @@ class ContextDependency extends Dependency { this.hadGlobalOrStickyRegExp = true; } + /** @type {string | undefined} */ this.request = undefined; + /** @type {Range | undefined} */ this.range = undefined; + /** @type {Range | undefined} */ this.valueRange = undefined; /** @type {boolean | string | undefined} */ this.inShorthand = undefined; - // TODO refactor this + /** @type {Replaces | undefined} */ this.replaces = undefined; this._requestContext = context; } @@ -142,7 +148,6 @@ class ContextDependency extends Dependency { write(this._requestContext); write(this.range); write(this.valueRange); - write(this.prepend); write(this.replaces); super.serialize(context); @@ -162,7 +167,6 @@ class ContextDependency extends Dependency { this._requestContext = read(); this.range = read(); this.valueRange = read(); - this.prepend = read(); this.replaces = read(); super.deserialize(context); diff --git a/lib/dependencies/ContextDependencyHelpers.js b/lib/dependencies/ContextDependencyHelpers.js index 08a0adaa2..f68296511 100644 --- a/lib/dependencies/ContextDependencyHelpers.js +++ b/lib/dependencies/ContextDependencyHelpers.js @@ -15,6 +15,7 @@ const { parseResource } = require("../util/identifier"); /** @typedef {import("../javascript/JavascriptParser").Range} Range */ /** @typedef {import("./ContextDependency")} ContextDependency */ /** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */ +/** @typedef {import("./ContextDependency").Replaces} Replaces */ /** * Escapes regular expression metacharacters @@ -118,7 +119,7 @@ module.exports.create = ( ); dep.loc = /** @type {DependencyLocation} */ (expr.loc); - /** @type {{ value: string, range: Range }[]} */ + /** @type {Replaces} */ const replaces = []; const parts = /** @type {BasicEvaluatedExpression[]} */ (param.parts); diff --git a/lib/dependencies/ContextDependencyTemplateAsId.js b/lib/dependencies/ContextDependencyTemplateAsId.js index da119adb0..ec7257806 100644 --- a/lib/dependencies/ContextDependencyTemplateAsId.js +++ b/lib/dependencies/ContextDependencyTemplateAsId.js @@ -8,6 +8,7 @@ const ContextDependency = require("./ContextDependency"); /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ +/** @typedef {import("../javascript/JavascriptParser").Range} Range */ /** @typedef {import("../Dependency")} Dependency */ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ @@ -28,11 +29,13 @@ class ContextDependencyTemplateAsId extends ContextDependency.Template { const moduleExports = runtimeTemplate.moduleExports({ module, chunkGraph, - request: dep.request, + request: /** @type {string} */ (dep.request), weak: dep.weak, runtimeRequirements }); + const range = /** @type {Range} */ (dep.range); + if (module) { if (dep.valueRange) { if (Array.isArray(dep.replaces)) { @@ -41,21 +44,18 @@ class ContextDependencyTemplateAsId extends ContextDependency.Template { source.replace(rep.range[0], rep.range[1] - 1, rep.value); } } - source.replace(dep.valueRange[1], dep.range[1] - 1, ")"); + + source.replace(dep.valueRange[1], range[1] - 1, ")"); source.replace( - dep.range[0], + range[0], dep.valueRange[0] - 1, `${moduleExports}.resolve(` ); } else { - source.replace( - dep.range[0], - dep.range[1] - 1, - `${moduleExports}.resolve` - ); + source.replace(range[0], range[1] - 1, `${moduleExports}.resolve`); } } else { - source.replace(dep.range[0], dep.range[1] - 1, moduleExports); + source.replace(range[0], range[1] - 1, moduleExports); } } } diff --git a/lib/dependencies/ContextDependencyTemplateAsRequireCall.js b/lib/dependencies/ContextDependencyTemplateAsRequireCall.js index ef02cce67..503b18d0d 100644 --- a/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +++ b/lib/dependencies/ContextDependencyTemplateAsRequireCall.js @@ -8,6 +8,7 @@ const ContextDependency = require("./ContextDependency"); /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ +/** @typedef {import("../javascript/JavascriptParser").Range} Range */ /** @typedef {import("../Dependency")} Dependency */ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ @@ -27,13 +28,16 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template let moduleExports = runtimeTemplate.moduleExports({ module: moduleGraph.getModule(dep), chunkGraph, - request: dep.request, + request: /** @type {string} */ (dep.request), runtimeRequirements }); if (dep.inShorthand) { moduleExports = `${dep.inShorthand}: ${moduleExports}`; } + + const range = /** @type {Range} */ (dep.range); + if (moduleGraph.getModule(dep)) { if (dep.valueRange) { if (Array.isArray(dep.replaces)) { @@ -42,17 +46,13 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template source.replace(rep.range[0], rep.range[1] - 1, rep.value); } } - source.replace(dep.valueRange[1], dep.range[1] - 1, ")"); - source.replace( - dep.range[0], - dep.valueRange[0] - 1, - `${moduleExports}(` - ); + source.replace(dep.valueRange[1], range[1] - 1, ")"); + source.replace(range[0], dep.valueRange[0] - 1, `${moduleExports}(`); } else { - source.replace(dep.range[0], dep.range[1] - 1, moduleExports); + source.replace(range[0], range[1] - 1, moduleExports); } } else { - source.replace(dep.range[0], dep.range[1] - 1, moduleExports); + source.replace(range[0], range[1] - 1, moduleExports); } } } diff --git a/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js b/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js index 58c1bef53..b8594a3fa 100644 --- a/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +++ b/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js @@ -33,7 +33,7 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe * @param {string[]} ids ids * @param {string} name name * @param {Range} range location in source code - * @param {ImportAttributes} attributes import assertions + * @param {ImportAttributes | undefined} attributes import assertions * @param {string} operator operator */ constructor(request, sourceOrder, ids, name, range, attributes, operator) { diff --git a/lib/dependencies/HarmonyExportDependencyParserPlugin.js b/lib/dependencies/HarmonyExportDependencyParserPlugin.js index be2056fee..7aa5836d3 100644 --- a/lib/dependencies/HarmonyExportDependencyParserPlugin.js +++ b/lib/dependencies/HarmonyExportDependencyParserPlugin.js @@ -25,6 +25,7 @@ const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDepe /** @typedef {import("../javascript/JavascriptParser").ClassDeclaration} ClassDeclaration */ /** @typedef {import("../javascript/JavascriptParser").FunctionDeclaration} FunctionDeclaration */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ +/** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */ const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency; @@ -156,7 +157,9 @@ module.exports = class HarmonyExportDependencyParserPlugin { parser.hooks.exportSpecifier.tap( PLUGIN_NAME, (statement, id, name, idx) => { - const settings = parser.getTagData(id, harmonySpecifierTag); + const settings = + /** @type {HarmonySettings} */ + (parser.getTagData(id, harmonySpecifierTag)); const harmonyNamedExports = (parser.state.harmonyNamedExports = parser.state.harmonyNamedExports || new Set()); harmonyNamedExports.add(name); diff --git a/lib/dependencies/HarmonyImportDependencyParserPlugin.js b/lib/dependencies/HarmonyImportDependencyParserPlugin.js index 7eaba5ed7..2427ec6cd 100644 --- a/lib/dependencies/HarmonyImportDependencyParserPlugin.js +++ b/lib/dependencies/HarmonyImportDependencyParserPlugin.js @@ -24,25 +24,15 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend /** @typedef {import("estree").Expression} Expression */ /** @typedef {import("estree").Identifier} Identifier */ -/** @typedef {import("estree").Literal} Literal */ /** @typedef {import("estree").MemberExpression} MemberExpression */ -/** @typedef {import("estree").ObjectExpression} ObjectExpression */ -/** @typedef {import("estree").Property} Property */ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ -/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ -/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */ /** @typedef {import("../javascript/JavascriptParser").ExportAllDeclaration} ExportAllDeclaration */ /** @typedef {import("../javascript/JavascriptParser").ExportNamedDeclaration} ExportNamedDeclaration */ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */ /** @typedef {import("../javascript/JavascriptParser").ImportDeclaration} ImportDeclaration */ -/** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ -/** @typedef {import("../javascript/JavascriptParser").TagData} TagData */ -/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */ -/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */ -/** @typedef {import("./HarmonyImportDependency")} HarmonyImportDependency */ const harmonySpecifierTag = Symbol("harmony import"); @@ -158,14 +148,18 @@ module.exports = class HarmonyImportDependencyParserPlugin { const defer = this.deferImport ? getImportMode(parser, statement).defer : false; - parser.tagVariable(name, harmonySpecifierTag, { + parser.tagVariable( name, - source, - ids, - sourceOrder: parser.state.lastHarmonyImportOrder, - attributes: getImportAttributes(statement), - defer - }); + harmonySpecifierTag, + /** @type {HarmonySettings} */ ({ + name, + source, + ids, + sourceOrder: parser.state.lastHarmonyImportOrder, + attributes: getImportAttributes(statement), + defer + }) + ); return true; } ); @@ -191,7 +185,7 @@ module.exports = class HarmonyImportDependencyParserPlugin { return; } const settings = - /** @type {TagData} */ + /** @type {HarmonySettings} */ (rootInfo.tagInfo.data); const members = /** @type {(() => string[])} */ diff --git a/lib/dependencies/LoaderPlugin.js b/lib/dependencies/LoaderPlugin.js index fe9c8707e..58ee8dcd5 100644 --- a/lib/dependencies/LoaderPlugin.js +++ b/lib/dependencies/LoaderPlugin.js @@ -23,6 +23,7 @@ const LoaderImportDependency = require("./LoaderImportDependency"); * @callback ImportModuleCallback * @param {(Error | null)=} err error object * @param {ExecuteModuleExports=} exports exports of the evaluated module + * @returns {void} */ /** diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 933052c3d..40749dd50 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -36,6 +36,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); /** @typedef {import("estree").PrivateIdentifier} PrivateIdentifier */ /** @typedef {import("estree").PropertyDefinition} PropertyDefinition */ /** @typedef {import("estree").Expression} Expression */ +/** @typedef {import("estree").ImportAttribute} ImportAttribute */ +/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */ /** @typedef {import("estree").Identifier} Identifier */ /** @typedef {import("estree").VariableDeclaration} VariableDeclaration */ /** @typedef {import("estree").IfStatement} IfStatement */ @@ -74,6 +76,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); /** @typedef {import("estree").WhileStatement} WhileStatement */ /** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */ /** @typedef {import("estree").ExpressionStatement} ExpressionStatement */ +/** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */ +/** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */ /** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */ /** @typedef {import("estree").DoWhileStatement} DoWhileStatement */ /** @typedef {import("estree").TryStatement} TryStatement */ @@ -87,6 +91,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */ /** @typedef {import("estree").TemplateLiteral} TemplateLiteral */ /** @typedef {import("estree").AssignmentProperty} AssignmentProperty */ +/** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */ /** @typedef {import("estree").MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration */ /** @typedef {import("estree").MaybeNamedClassDeclaration} MaybeNamedClassDeclaration */ /** @@ -105,12 +110,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); /** @typedef {Set} DestructuringAssignmentProperties */ // TODO remove cast when @types/estree has been updated to import assertions -/** @typedef {import("estree").BaseNode & { type: "ImportAttribute", key: Identifier | Literal, value: Literal }} ImportAttribute */ -/** @typedef {import("estree").ImportDeclaration & { attributes?: ImportAttribute[], phase?: "defer" }} ImportDeclaration */ -/** @typedef {import("estree").ExportNamedDeclaration & { attributes?: ImportAttribute[] }} ExportNamedDeclaration */ -/** @typedef {import("estree").ExportAllDeclaration & { attributes?: ImportAttribute[] }} ExportAllDeclaration */ /** @typedef {import("estree").ImportExpression & { options?: Expression | null, phase?: "defer" }} ImportExpression */ -/** @typedef {ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration} ModuleDeclaration */ /** @type {string[]} */ const EMPTY_ARRAY = []; @@ -304,7 +304,15 @@ class VariableInfo { /** @typedef {Omit & { sourceType: "module" | "script" | "auto", ecmaVersion?: AcornOptions["ecmaVersion"] }} ParseOptions */ /** @typedef {symbol} Tag */ -/** @typedef {Record} TagData */ + +/** @typedef {import("../dependencies/HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */ +/** @typedef {import("../dependencies/ImportParserPlugin").ImportSettings} ImportSettings */ +/** @typedef {import("../dependencies/CommonJsImportsParserPlugin").CommonJsImportSettings} CommonJsImportSettings */ +/** @typedef {import("../CompatibilityPlugin").CompatibilitySettings} CompatibilitySettings */ +/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */ + +/** @typedef {HarmonySettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings} KnownTagData */ +/** @typedef {KnownTagData & Record} TagData */ /** * @typedef {object} TagInfo @@ -619,9 +627,9 @@ class JavascriptParser extends Parser { }); this.sourceType = sourceType; /** @type {ScopeInfo} */ - this.scope = /** @type {TODO} */ (undefined); + this.scope = /** @type {EXPECTED_ANY} */ (undefined); /** @type {ParserState} */ - this.state = /** @type {TODO} */ (undefined); + this.state = /** @type {EXPECTED_ANY} */ (undefined); /** @type {Comment[] | undefined} */ this.comments = undefined; /** @type {Set | undefined} */ @@ -4098,7 +4106,7 @@ class JavascriptParser extends Parser { * @param {HookMap>} hookMap hooks the should be called * @param {ExportedVariableInfo} info variable info * @param {((name: string) => R | undefined) | undefined} fallback callback when variable in not handled by hooks - * @param {((result?: string) => TODO) | undefined} defined callback when variable is defined + * @param {((result?: string) => R | undefined) | undefined} defined callback when variable is defined * @param {AsArray} args args for the hook * @returns {R | undefined} result of hook */ diff --git a/lib/optimize/InnerGraph.js b/lib/optimize/InnerGraph.js index a8c57de1f..f27abc5fd 100644 --- a/lib/optimize/InnerGraph.js +++ b/lib/optimize/InnerGraph.js @@ -31,7 +31,7 @@ const JavascriptParser = require("../javascript/JavascriptParser"); * @property {Map>} usageCallbackMap */ -/** @typedef {false|StateObject} State */ +/** @typedef {false | StateObject} State */ class TopLevelSymbol { /** diff --git a/lib/rules/RuleSetCompiler.js b/lib/rules/RuleSetCompiler.js index cf61b76d1..46555caf5 100644 --- a/lib/rules/RuleSetCompiler.js +++ b/lib/rules/RuleSetCompiler.js @@ -7,6 +7,7 @@ const { SyncHook } = require("tapable"); +/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */ /** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */ /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */ /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */ @@ -40,7 +41,7 @@ const { SyncHook } = require("tapable"); * @property {ImportAttributes=} assertions * @property {string=} mimetype * @property {string} dependency - * @property {Record=} descriptionData + * @property {ResolveRequest["descriptionFileData"]=} descriptionData * @property {string=} compiler * @property {string} issuer * @property {string} issuerLayer @@ -128,7 +129,7 @@ class RuleSetCompiler { for (const condition of rule.conditions) { const p = condition.property; if (Array.isArray(p)) { - /** @type {EffectData | EffectData[keyof EffectData] | undefined} */ + /** @type {EXPECTED_ANY} */ let current = data; for (const subProperty of p) { if ( diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 296159e36..ad6b3b904 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -112,9 +112,6 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); */ /** @typedef {KnownStatsAsset & Record} StatsAsset */ -/** @typedef {ChunkId} KnownStatsAssetChunk */ -/** @typedef {ChunkName} KnownStatsAssetChunkName */ -/** @typedef {string} KnownStatsAssetChunkIdHint */ /** * @typedef {object} KnownStatsAsset * @property {string} type @@ -125,12 +122,12 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {boolean} comparedForEmit * @property {boolean} cached * @property {StatsAsset[]=} related - * @property {KnownStatsAssetChunk[]=} chunks - * @property {KnownStatsAssetChunkName[]=} chunkNames - * @property {KnownStatsAssetChunkIdHint[]=} chunkIdHints - * @property {KnownStatsAssetChunk[]=} auxiliaryChunks - * @property {KnownStatsAssetChunkName[]=} auxiliaryChunkNames - * @property {KnownStatsAssetChunkIdHint[]=} auxiliaryChunkIdHints + * @property {ChunkId[]=} chunks + * @property {ChunkName[]=} chunkNames + * @property {string[]=} chunkIdHints + * @property {ChunkId[]=} auxiliaryChunks + * @property {ChunkName[]=} auxiliaryChunkNames + * @property {string[]=} auxiliaryChunkIdHints * @property {number=} filteredRelated * @property {boolean=} isOverSizeLimit */ @@ -138,7 +135,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); /** @typedef {KnownStatsChunkGroup & Record} StatsChunkGroup */ /** * @typedef {object} KnownStatsChunkGroup - * @property {(string | null)=} name + * @property {ChunkName=} name * @property {(string | number)[]=} chunks * @property {({ name: string, size?: number })[]=} assets * @property {number=} filteredAssets @@ -146,8 +143,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {({ name: string, size?: number })[]=} auxiliaryAssets * @property {number=} filteredAuxiliaryAssets * @property {number=} auxiliaryAssetsSize - * @property {{ [x: string]: StatsChunkGroup[] }=} children - * @property {{ [x: string]: string[] }=} childAssets + * @property {Record=} children + * @property {Record=} childAssets * @property {boolean=} isOverSizeLimit */ @@ -166,7 +163,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {number=} index2 * @property {number=} postOrderIndex * @property {number=} size - * @property {{ [x: string]: number }=} sizes + * @property {Record=} sizes * @property {boolean=} cacheable * @property {boolean=} built * @property {boolean=} codeGenerated @@ -216,7 +213,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @typedef {object} KnownStatsModuleIssuer * @property {string} identifier * @property {string} name - * @property {(string|number)=} id + * @property {ModuleId=} id * @property {StatsProfile} profile */ @@ -233,8 +230,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {string | null} explanation * @property {string | null} userRequest * @property {(string | null)=} loc - * @property {(string | number | null)=} moduleId - * @property {(string | number | null)=} resolvedModuleId + * @property {ModuleId | null=} moduleId + * @property {ModuleId | null=} resolvedModuleId */ /** @typedef {KnownStatsChunk & Record} StatsChunk */ @@ -254,10 +251,10 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {string[]} auxiliaryFiles * @property {string} hash * @property {Record} childrenByOrder - * @property {(string|number)=} id - * @property {(string|number)[]=} siblings - * @property {(string|number)[]=} parents - * @property {(string|number)[]=} children + * @property {ChunkId=} id + * @property {ChunkId[]=} siblings + * @property {ChunkId[]=} parents + * @property {ChunkId[]=} children * @property {StatsModule[]=} modules * @property {number=} filteredModules * @property {StatsChunkOrigin[]=} origins @@ -282,8 +279,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {string=} moduleIdentifier * @property {string=} moduleName * @property {StatsModuleTraceDependency[]=} dependencies - * @property {(string|number)=} originId - * @property {(string|number)=} moduleId + * @property {ModuleId=} originId + * @property {ModuleId=} moduleId */ /** @typedef {KnownStatsModuleTraceDependency & Record} StatsModuleTraceDependency */ @@ -304,7 +301,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @property {string=} moduleName * @property {string=} loc * @property {ChunkId=} chunkId - * @property {string|number=} moduleId + * @property {ModuleId=} moduleId * @property {StatsModuleTraceItem[]=} moduleTrace * @property {string=} details * @property {string=} stack diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index 149ae375c..8beab5eb6 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -10,9 +10,6 @@ /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkId} ChunkId */ /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkName} ChunkName */ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAsset} KnownStatsAsset */ -/** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunk} KnownStatsAssetChunk */ -/** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkIdHint} KnownStatsAssetChunkIdHint */ -/** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkName} KnownStatsAssetChunkName */ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunk} KnownStatsChunk */ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkGroup} KnownStatsChunkGroup */ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkOrigin} KnownStatsChunkOrigin */ @@ -412,9 +409,9 @@ const COMPILATION_SIMPLE_PRINTERS = { * Printers & * Exclamation & * { ["asset.filteredChildren"]?: SimplePrinter } & - * { assetChunk?: SimplePrinter } & - * { assetChunkName?: SimplePrinter } & - * { assetChunkIdHint?: SimplePrinter }} AssetSimplePrinters + * { assetChunk?: SimplePrinter } & + * { assetChunkName?: SimplePrinter } & + * { assetChunkIdHint?: SimplePrinter }} AssetSimplePrinters */ /** @type {AssetSimplePrinters} */ @@ -464,7 +461,6 @@ const ASSET_SIMPLE_PRINTERS = { : undefined, assetChunk: (id, { formatChunkId }) => formatChunkId(id), - assetChunkName: (name) => name || undefined, assetChunkIdHint: (name) => name || undefined }; @@ -1454,7 +1450,12 @@ const AVAILABLE_COLORS = { * @typedef {T extends [infer Head, ...infer Tail] ? Tail : undefined} Tail */ -/** @typedef {{ [Key in keyof KnownStatsPrinterFormatters]: (value: Parameters>[0], options: Required & StatsPrinterContextWithExtra, ...args: Tail>>) => string }} AvailableFormats */ +/** + * @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T + * @typedef {T extends (firstArg: EXPECTED_ANY, ...rest: infer R) => EXPECTED_ANY ? R : never} TailParameters + */ + +/** @typedef {{ [Key in keyof KnownStatsPrinterFormatters]: (value: Parameters>[0], options: Required & StatsPrinterContextWithExtra, ...args: TailParameters>) => string }} AvailableFormats */ /** @type {AvailableFormats} */ const AVAILABLE_FORMATS = { @@ -1630,16 +1631,14 @@ class DefaultStatsPrinterPlugin { context[color] = (str) => str; } } - for (const _format of Object.keys(AVAILABLE_FORMATS)) { - const format = - /** @type {keyof KnownStatsPrinterFormatters} */ - (_format); - + for (const format of /** @type {(keyof KnownStatsPrinterFormatters)[]} */ ( + Object.keys(AVAILABLE_FORMATS) + )) { context[format] = /** @type {(content: Parameters>[0], ...args: Tail>>) => string} */ (content, ...args) => - /** @type {TODO} */ - (AVAILABLE_FORMATS)[format]( + /** @type {EXPECTED_ANY} */ + (AVAILABLE_FORMATS[format])( content, /** @type {StatsPrinterContext & Required} */ (context), @@ -1649,15 +1648,12 @@ class DefaultStatsPrinterPlugin { context.timeReference = compilation.time; }); - for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) { + for (const key of /** @type {(keyof CompilationSimplePrinters)[]} */ ( + Object.keys(COMPILATION_SIMPLE_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - ( - COMPILATION_SIMPLE_PRINTERS[ - /** @type {keyof CompilationSimplePrinters} */ - (key) - ] - )( + /** @type {EXPECTED_ANY} */ + (COMPILATION_SIMPLE_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"compilation">} */ (ctx), @@ -1666,15 +1662,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) { + for (const key of /** @type {(keyof AssetSimplePrinters)[]} */ ( + Object.keys(ASSET_SIMPLE_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => /** @type {NonNullable} */ - ( - ASSET_SIMPLE_PRINTERS[ - /** @type {keyof AssetSimplePrinters} */ - (key) - ] - )( + (ASSET_SIMPLE_PRINTERS[key])( obj, /** @type {DefineStatsPrinterContext<"asset" | "asset.info">} */ (ctx), @@ -1683,15 +1676,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) { + for (const key of /** @type {(keyof ModuleSimplePrinters)[]} */ ( + Object.keys(MODULE_SIMPLE_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - ( - MODULE_SIMPLE_PRINTERS[ - /** @type {keyof ModuleSimplePrinters} */ - (key) - ] - )( + /** @type {EXPECTED_ANY} */ + (MODULE_SIMPLE_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"module">} */ (ctx), @@ -1700,15 +1690,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) { + for (const key of /** @type {(keyof ModuleIssuerPrinters)[]} */ ( + Object.keys(MODULE_ISSUER_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => /** @type {NonNullable} */ - ( - MODULE_ISSUER_PRINTERS[ - /** @type {keyof ModuleIssuerPrinters} */ - (key) - ] - )( + (MODULE_ISSUER_PRINTERS[key])( obj, /** @type {DefineStatsPrinterContext<"moduleIssuer">} */ (ctx), @@ -1717,15 +1704,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_REASON_PRINTERS)) { + for (const key of /** @type {(keyof ModuleReasonsPrinters)[]} */ ( + Object.keys(MODULE_REASON_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - ( - MODULE_REASON_PRINTERS[ - /** @type {keyof ModuleReasonsPrinters} */ - (key) - ] - )( + /** @type {EXPECTED_ANY} */ + (MODULE_REASON_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"moduleReason">} */ (ctx), @@ -1734,15 +1718,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) { + for (const key of /** @type {(keyof ModuleProfilePrinters)[]} */ ( + Object.keys(MODULE_PROFILE_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => /** @type {NonNullable} */ - ( - MODULE_PROFILE_PRINTERS[ - /** @type {keyof ModuleProfilePrinters} */ - (key) - ] - )( + (MODULE_PROFILE_PRINTERS[key])( obj, /** @type {DefineStatsPrinterContext<"profile">} */ (ctx), @@ -1751,15 +1732,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) { + for (const key of /** @type {(keyof ChunkGroupPrinters)[]} */ ( + Object.keys(CHUNK_GROUP_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - ( - CHUNK_GROUP_PRINTERS[ - /** @type {keyof ChunkGroupPrinters} */ - (key) - ] - )( + /** @type {EXPECTED_ANY} */ + (CHUNK_GROUP_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */ (ctx), @@ -1768,10 +1746,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(CHUNK_PRINTERS)) { + for (const key of /** @type {(keyof ChunkPrinters)[]} */ ( + Object.keys(CHUNK_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - (CHUNK_PRINTERS[/** @type {keyof ChunkPrinters} */ (key)])( + /** @type {EXPECTED_ANY} */ + (CHUNK_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"chunk">} */ (ctx), @@ -1780,10 +1760,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(ERROR_PRINTERS)) { + for (const key of /** @type {(keyof ErrorPrinters)[]} */ ( + Object.keys(ERROR_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - (ERROR_PRINTERS[/** @type {keyof ErrorPrinters} */ (key)])( + /** @type {EXPECTED_ANY} */ + (ERROR_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"error">} */ (ctx), @@ -1792,15 +1774,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(LOG_ENTRY_PRINTERS)) { + for (const key of /** @type {(keyof LogEntryPrinters)[]} */ ( + Object.keys(LOG_ENTRY_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => - /** @type {TODO} */ - ( - LOG_ENTRY_PRINTERS[ - /** @type {keyof LogEntryPrinters} */ - (key) - ] - )( + /** @type {EXPECTED_ANY} */ + (LOG_ENTRY_PRINTERS)[key]( obj, /** @type {DefineStatsPrinterContext<"logging">} */ (ctx), @@ -1809,15 +1788,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) { + for (const key of /** @type {(keyof ModuleTraceDependencyPrinters)[]} */ ( + Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => /** @type {NonNullable} */ - ( - MODULE_TRACE_DEPENDENCY_PRINTERS[ - /** @type {keyof ModuleTraceDependencyPrinters} */ - (key) - ] - )( + (MODULE_TRACE_DEPENDENCY_PRINTERS[key])( obj, /** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */ (ctx), @@ -1826,15 +1802,12 @@ class DefaultStatsPrinterPlugin { ); } - for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) { + for (const key of /** @type {(keyof ModuleTraceItemPrinters)[]} */ ( + Object.keys(MODULE_TRACE_ITEM_PRINTERS) + )) { stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => /** @type {NonNullable} */ - ( - MODULE_TRACE_ITEM_PRINTERS[ - /** @type {keyof ModuleTraceItemPrinters} */ - (key) - ] - )( + (MODULE_TRACE_ITEM_PRINTERS[key])( obj, /** @type {DefineStatsPrinterContext<"moduleTraceItem">} */ (ctx), diff --git a/lib/stats/StatsFactory.js b/lib/stats/StatsFactory.js index ae09f4ff0..be26c6a11 100644 --- a/lib/stats/StatsFactory.js +++ b/lib/stats/StatsFactory.js @@ -70,10 +70,10 @@ const smartGrouping = require("../util/smartGrouping"); * @typedef {T extends ChunkGroupInfoWithName[] ? Record> : T extends (infer V)[] ? StatsObject[] : StatsObject} CreatedObject */ -/** @typedef {TODO} ObjectForExtract */ -/** @typedef {TODO} FactoryData */ -/** @typedef {TODO} FactoryDataItem */ -/** @typedef {TODO} Result */ +/** @typedef {EXPECTED_ANY} ObjectForExtract */ +/** @typedef {EXPECTED_ANY} FactoryData */ +/** @typedef {EXPECTED_ANY} FactoryDataItem */ +/** @typedef {EXPECTED_ANY} Result */ /** * @typedef {object} StatsFactoryHooks diff --git a/lib/url/URLParserPlugin.js b/lib/url/URLParserPlugin.js index 7a864134e..2ae2d2a40 100644 --- a/lib/url/URLParserPlugin.js +++ b/lib/url/URLParserPlugin.js @@ -24,7 +24,6 @@ const InnerGraph = require("../optimize/InnerGraph"); /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ /** @typedef {import("../NormalModule")} NormalModule */ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ -/** @typedef {import("../javascript/JavascriptParser")} Parser */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ const PLUGIN_NAME = "URLParserPlugin"; @@ -36,7 +35,7 @@ const PLUGIN_NAME = "URLParserPlugin"; const getUrl = (module) => pathToFileURL(module.resource); /** - * @param {Parser} parser parser parser + * @param {JavascriptParser} parser parser parser * @param {MemberExpression} arg arg * @returns {boolean} true when it is `meta.url`, otherwise false */ @@ -63,7 +62,7 @@ const getEvaluatedExprCache = new WeakMap(); /** * @param {NewExpressionNode} expr expression - * @param {Parser} parser parser parser + * @param {JavascriptParser} parser parser parser * @returns {BasicEvaluatedExpression | undefined} basic evaluated expression */ const getEvaluatedExpr = (expr, parser) => { diff --git a/lib/util/cleverMerge.js b/lib/util/cleverMerge.js index 7e3fbbb71..7de8c7c07 100644 --- a/lib/util/cleverMerge.js +++ b/lib/util/cleverMerge.js @@ -92,7 +92,7 @@ const cachedSetProperty = (obj, property, value) => { * @template T * @typedef {object} ObjectParsedPropertyEntry * @property {T[keyof T] | undefined} base base value - * @property {string | undefined} byProperty the name of the selector property + * @property {`by${string}` | undefined} byProperty the name of the selector property * @property {ByValues | undefined} byValues value depending on selector property, merged with base */ @@ -105,7 +105,7 @@ const cachedSetProperty = (obj, property, value) => { /** * @template {object} T - * @typedef {{ byProperty: string, fn: DynamicFunction }} ParsedObjectDynamic + * @typedef {{ byProperty: `by${string}`, fn: DynamicFunction }} ParsedObjectDynamic */ /** @@ -169,7 +169,7 @@ const parseObject = (obj) => { for (const key of Object.keys(obj)) { const entry = getInfo(/** @type {keyof T} */ (key)); if (entry.byProperty === undefined) { - entry.byProperty = byProperty; + entry.byProperty = /** @type {`by${string}`} */ (byProperty); entry.byValues = new Map(); } else if (entry.byProperty !== byProperty) { throw new Error( @@ -196,7 +196,7 @@ const parseObject = (obj) => { } else if (typeof byObj === "function") { if (dynamicInfo === undefined) { dynamicInfo = { - byProperty: key, + byProperty: /** @type {`by${string}`} */ (key), fn: byObj }; } else { @@ -222,17 +222,16 @@ const parseObject = (obj) => { /** * @template {object} T * @param {ParsedObjectStatic} info static properties (key is property name) - * @param {{ byProperty: string, fn: DynamicFunction } | undefined} dynamicInfo dynamic part + * @param {{ byProperty: `by${string}`, fn: DynamicFunction } | undefined} dynamicInfo dynamic part * @returns {T} the object */ const serializeObject = (info, dynamicInfo) => { - const obj = /** @type {T} */ ({}); + const obj = /** @type {EXPECTED_ANY} */ ({}); // Setup byProperty structure for (const entry of info.values()) { if (entry.byProperty !== undefined) { - const byProperty = /** @type {keyof T} */ (entry.byProperty); - const byObj = (obj[byProperty] = - obj[byProperty] || /** @type {TODO} */ ({})); + const byProperty = entry.byProperty; + const byObj = (obj[byProperty] = obj[byProperty] || {}); for (const byValue of /** @type {ByValues} */ (entry.byValues).keys()) { byObj[byValue] = byObj[byValue] || {}; } @@ -240,13 +239,12 @@ const serializeObject = (info, dynamicInfo) => { } for (const [key, entry] of info) { if (entry.base !== undefined) { - obj[/** @type {keyof T} */ (key)] = entry.base; + obj[key] = entry.base; } // Fill byProperty structure if (entry.byProperty !== undefined) { - const byProperty = /** @type {keyof T} */ (entry.byProperty); - const byObj = (obj[byProperty] = - obj[byProperty] || /** @type {TODO} */ ({})); + const byProperty = entry.byProperty; + const byObj = (obj[byProperty] = obj[byProperty] || {}); for (const byValue of Object.keys(byObj)) { const value = getFromByValues( /** @type {ByValues} */ @@ -258,8 +256,7 @@ const serializeObject = (info, dynamicInfo) => { } } if (dynamicInfo !== undefined) { - /** @type {TODO} */ - (obj)[dynamicInfo.byProperty] = dynamicInfo.fn; + obj[dynamicInfo.byProperty] = dynamicInfo.fn; } return obj; }; @@ -384,7 +381,7 @@ const _cleverMerge = (first, second, internalCaching = false) => { * @param {ObjectParsedPropertyEntry} firstEntry a * @param {ObjectParsedPropertyEntry} secondEntry b * @param {boolean} internalCaching should parsing of objects and nested merges be cached - * @returns {ObjectParsedPropertyEntry} new entry + * @returns {ObjectParsedPropertyEntry | ObjectParsedPropertyEntry | ObjectParsedPropertyEntry} new entry */ const mergeEntries = (firstEntry, secondEntry, internalCaching) => { switch (getValueType(secondEntry.base)) { @@ -479,7 +476,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => { if (!secondEntry.byProperty) { // = first.base + (first.byProperty + second.base) return { - base: newBase, + base: /** @type {T[keyof T] & O[keyof O]} */ (newBase), byProperty: firstEntry.byProperty, byValues: intermediateByValues }; @@ -499,7 +496,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => { ); } return { - base: newBase, + base: /** @type {T[keyof T] & O[keyof O]} */ (newBase), byProperty: firstEntry.byProperty, byValues: newByValues }; diff --git a/lib/util/deprecation.js b/lib/util/deprecation.js index 5d3b61b31..648f54eae 100644 --- a/lib/util/deprecation.js +++ b/lib/util/deprecation.js @@ -75,38 +75,37 @@ const DISABLED_METHODS = [ /** * @template T - * @typedef {Set & {[Symbol.isConcatSpreadable]?: boolean} & { push?: (...items: T[]) => void } & { [P in DISABLED_METHODS_NAMES]?: () => void } & { [P in COPY_METHODS_NAMES]?: () => TODO }} SetWithDeprecatedArrayMethods + * @typedef {Set & { [Symbol.isConcatSpreadable]: boolean } & { push: (...items: T[]) => void, length?: number } & { [P in DISABLED_METHODS_NAMES]: () => void } & { [P in COPY_METHODS_NAMES]: P extends keyof Array ? () => Pick, P> : never }} SetWithDeprecatedArrayMethods */ /** * @template T - * @param {SetWithDeprecatedArrayMethods} set new set + * @param {Set} set new set * @param {string} name property name * @returns {void} */ module.exports.arrayToSetDeprecation = (set, name) => { for (const method of COPY_METHODS) { - if (set[method]) continue; + if (/** @type {SetWithDeprecatedArrayMethods} */ (set)[method]) continue; const d = createDeprecation( `${name} was changed from Array to Set (using Array method '${method}' is deprecated)`, "ARRAY_TO_SET" ); - /** - * @deprecated - * @this {Set} - * @returns {number} count - */ - // eslint-disable-next-line func-names - set[method] = function () { - d(); - // eslint-disable-next-line unicorn/prefer-spread - const array = Array.from(this); - return Array.prototype[/** @type {keyof COPY_METHODS} */ (method)].apply( - array, - // eslint-disable-next-line prefer-rest-params - arguments - ); - }; + /** @type {EXPECTED_ANY} */ + (set)[method] = + // eslint-disable-next-line func-names + function () { + d(); + // eslint-disable-next-line unicorn/prefer-spread + const array = Array.from(this); + return Array.prototype[ + /** @type {keyof COPY_METHODS} */ (method) + ].apply( + array, + // eslint-disable-next-line prefer-rest-params + arguments + ); + }; } const dPush = createDeprecation( `${name} was changed from Array to Set (using Array method 'push' is deprecated)`, @@ -120,12 +119,8 @@ module.exports.arrayToSetDeprecation = (set, name) => { `${name} was changed from Array to Set (indexing Array is deprecated)`, "ARRAY_TO_SET_INDEXER" ); - /** - * @deprecated - * @this {Set} - * @returns {number} count - */ - set.push = function push() { + /** @type {SetWithDeprecatedArrayMethods} */ + (set).push = function push() { dPush(); // eslint-disable-next-line prefer-rest-params, unicorn/prefer-spread for (const item of Array.from(arguments)) { @@ -134,9 +129,10 @@ module.exports.arrayToSetDeprecation = (set, name) => { return this.size; }; for (const method of DISABLED_METHODS) { - if (set[method]) continue; + if (/** @type {SetWithDeprecatedArrayMethods} */ (set)[method]) continue; - set[method] = () => { + /** @type {SetWithDeprecatedArrayMethods} */ + (set)[method] = () => { throw new Error( `${name} was changed from Array to Set (using Array method '${method}' is not possible)` ); @@ -191,7 +187,8 @@ module.exports.arrayToSetDeprecation = (set, name) => { ); } }); - set[Symbol.isConcatSpreadable] = true; + /** @type {SetWithDeprecatedArrayMethods} */ + (set)[Symbol.isConcatSpreadable] = true; }; /** @@ -214,7 +211,8 @@ module.exports.createArrayToSetDeprecationSet = (name) => { if (!initialized) { initialized = true; module.exports.arrayToSetDeprecation( - SetDeprecatedArray.prototype, + /** @type {SetWithDeprecatedArrayMethods} */ + (SetDeprecatedArray.prototype), name ); } diff --git a/test/cases/parsing/precreated-ast/ast-loader.js b/test/cases/parsing/precreated-ast/ast-loader.js index add7af8cc..b6181cb47 100644 --- a/test/cases/parsing/precreated-ast/ast-loader.js +++ b/test/cases/parsing/precreated-ast/ast-loader.js @@ -5,10 +5,11 @@ const acornParser = acorn.Parser; /** @type {import("../../../../").LoaderDefinition} */ module.exports = function (source) { - /** @type {TODO} */ + /** @type {acorn.Comment[]} */ const comments = []; const semicolons = new Set(); + //@ts-ignore const ast = acornParser.parse(source, { ranges: true, locations: true, diff --git a/test/configCases/context-modules/multiple-alias-2/index.js b/test/configCases/context-modules/multiple-alias-2/index.js new file mode 100644 index 000000000..dd75643df --- /dev/null +++ b/test/configCases/context-modules/multiple-alias-2/index.js @@ -0,0 +1,6 @@ +const load = id => import(`app/${id}?query#hash`); + + +it("show override request", async () => { + expect((await load("a")).default).toBe("override/a"); +}); diff --git a/test/configCases/context-modules/multiple-alias-2/src/foo/a.js b/test/configCases/context-modules/multiple-alias-2/src/foo/a.js new file mode 100644 index 000000000..b589a567a --- /dev/null +++ b/test/configCases/context-modules/multiple-alias-2/src/foo/a.js @@ -0,0 +1 @@ +export default "foo/a"; diff --git a/test/configCases/context-modules/multiple-alias-2/src/main/a.js b/test/configCases/context-modules/multiple-alias-2/src/main/a.js new file mode 100644 index 000000000..c88d9dc1d --- /dev/null +++ b/test/configCases/context-modules/multiple-alias-2/src/main/a.js @@ -0,0 +1 @@ +export default "main/a"; diff --git a/test/configCases/context-modules/multiple-alias-2/src/override/a.js b/test/configCases/context-modules/multiple-alias-2/src/override/a.js new file mode 100644 index 000000000..7b71725f1 --- /dev/null +++ b/test/configCases/context-modules/multiple-alias-2/src/override/a.js @@ -0,0 +1 @@ +export default "override/a"; diff --git a/test/configCases/context-modules/multiple-alias-2/webpack.config.js b/test/configCases/context-modules/multiple-alias-2/webpack.config.js new file mode 100644 index 000000000..fdeebc672 --- /dev/null +++ b/test/configCases/context-modules/multiple-alias-2/webpack.config.js @@ -0,0 +1,14 @@ +"use strict"; + +const path = require("path"); +const webpack = require("../../../../"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + resolve: { + alias: { + app: [path.join(__dirname, "src/main"), path.join(__dirname, "src/foo")] + } + }, + plugins: [new webpack.ContextReplacementPlugin(/main/, "../override")] +}; diff --git a/test/configCases/context-modules/multiple-alias/index.js b/test/configCases/context-modules/multiple-alias/index.js new file mode 100644 index 000000000..dd75643df --- /dev/null +++ b/test/configCases/context-modules/multiple-alias/index.js @@ -0,0 +1,6 @@ +const load = id => import(`app/${id}?query#hash`); + + +it("show override request", async () => { + expect((await load("a")).default).toBe("override/a"); +}); diff --git a/test/configCases/context-modules/multiple-alias/src/foo/a.js b/test/configCases/context-modules/multiple-alias/src/foo/a.js new file mode 100644 index 000000000..b589a567a --- /dev/null +++ b/test/configCases/context-modules/multiple-alias/src/foo/a.js @@ -0,0 +1 @@ +export default "foo/a"; diff --git a/test/configCases/context-modules/multiple-alias/src/main/a.js b/test/configCases/context-modules/multiple-alias/src/main/a.js new file mode 100644 index 000000000..c88d9dc1d --- /dev/null +++ b/test/configCases/context-modules/multiple-alias/src/main/a.js @@ -0,0 +1 @@ +export default "main/a"; diff --git a/test/configCases/context-modules/multiple-alias/src/override/a.js b/test/configCases/context-modules/multiple-alias/src/override/a.js new file mode 100644 index 000000000..7b71725f1 --- /dev/null +++ b/test/configCases/context-modules/multiple-alias/src/override/a.js @@ -0,0 +1 @@ +export default "override/a"; diff --git a/test/configCases/context-modules/multiple-alias/webpack.config.js b/test/configCases/context-modules/multiple-alias/webpack.config.js new file mode 100644 index 000000000..9f7eaa6b5 --- /dev/null +++ b/test/configCases/context-modules/multiple-alias/webpack.config.js @@ -0,0 +1,20 @@ +"use strict"; + +const path = require("path"); +const webpack = require("../../../../"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + resolve: { + alias: { + app: [path.join(__dirname, "src/main"), path.join(__dirname, "src/foo")] + } + }, + plugins: [ + new webpack.ContextReplacementPlugin(/main/, (context) => { + Object.assign(context, { + resource: ["../override"] // resolved relatively + }); + }) + ] +}; diff --git a/test/configCases/loaders-and-plugins-falsy/basic/webpack.config.js b/test/configCases/loaders-and-plugins-falsy/basic/webpack.config.js index 22efe7529..eb78579df 100644 --- a/test/configCases/loaders-and-plugins-falsy/basic/webpack.config.js +++ b/test/configCases/loaders-and-plugins-falsy/basic/webpack.config.js @@ -1,5 +1,7 @@ "use strict"; +/** @typedef {import("../../../../").Compiler} Compiler */ + const DefinePlugin = require("../../../../").DefinePlugin; const nullValue = null; @@ -16,19 +18,15 @@ class FailPlugin { class TestChildCompilationPlugin { /** - * @param {TODO} compiler compiler + * @param {Compiler} compiler compiler */ apply(compiler) { compiler.hooks.make.tapAsync( "TestChildCompilationFailurePlugin", - /** - * @param {TODO} compilation compilation - * @param {TODO} cb cb - */ (compilation, cb) => { const child = compilation.createChildCompiler( "name", - compiler.outputOptions, + compilation.outputOptions, [ undefinedValue && new FailPlugin(), nullValue && new FailPlugin(), @@ -38,7 +36,9 @@ class TestChildCompilationPlugin { ] ); - child.runAsChild(cb); + child.runAsChild((err) => { + cb(err); + }); } ); } diff --git a/types.d.ts b/types.d.ts index cb9ea1523..5df86a155 100644 --- a/types.d.ts +++ b/types.d.ts @@ -15,7 +15,6 @@ import { AssignmentPattern, AssignmentProperty, AwaitExpression, - BaseNode, BigIntLiteral, BinaryExpression, BlockStatement, @@ -32,9 +31,9 @@ import { Directive, DoWhileStatement, EmptyStatement, - ExportAllDeclaration as ExportAllDeclarationImport, + ExportAllDeclaration, ExportDefaultDeclaration, - ExportNamedDeclaration as ExportNamedDeclarationImport, + ExportNamedDeclaration, ExportSpecifier, ExpressionStatement, ForInStatement, @@ -44,7 +43,7 @@ import { FunctionExpression, Identifier, IfStatement, - ImportDeclaration as ImportDeclarationImport, + ImportDeclaration, ImportDefaultSpecifier, ImportExpression as ImportExpressionImport, ImportNamespaceSpecifier, @@ -196,7 +195,7 @@ declare interface AdditionalData { } type AfterContextResolveData = ContextResolveData & ContextOptions & { - resource: any; + resource: string | string[]; resourceQuery?: string; resourceFragment?: string; resolveDependencies: ( @@ -205,7 +204,7 @@ type AfterContextResolveData = ContextResolveData & callback: ( err: null | Error, dependencies?: ContextElementDependency[] - ) => any + ) => void ) => void; }; declare class AggressiveMergingPlugin { @@ -623,9 +622,9 @@ declare abstract class BasicEvaluatedExpression { getMemberRanges?: () => [number, number][]; expression?: | Program - | ImportDeclarationImport - | ExportNamedDeclarationImport - | ExportAllDeclarationImport + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | ImportExpressionImport | UnaryExpression | ArrayExpression @@ -854,9 +853,9 @@ declare abstract class BasicEvaluatedExpression { setExpression( expression?: | Program - | ImportDeclarationImport - | ExportNamedDeclarationImport - | ExportAllDeclarationImport + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | ImportExpressionImport | UnaryExpression | ArrayExpression @@ -2037,6 +2036,10 @@ declare interface ColorsOptions { */ useColor?: boolean; } +declare interface CommonJsImportSettings { + name?: string; + context: string; +} declare interface Comparator { (a: T, b: T): 0 | 1 | -1; } @@ -2044,6 +2047,15 @@ declare class CompatSource extends Source { constructor(sourceLike: SourceLike); static from(sourceLike: SourceLike): Source; } +declare interface CompatibilitySettings { + name: string; + declaration: CompatibilitySettingsDeclaration; +} +declare interface CompatibilitySettingsDeclaration { + updated: boolean; + loc: DependencyLocation; + range: [number, number]; +} declare class Compilation { /** * Creates an instance of Compilation. @@ -2748,7 +2760,7 @@ declare class Compiler { err: null | Error, entries?: Chunk[], compilation?: Compilation - ) => any + ) => void ): void; purgeInputFileSystem(): void; emitAssets( @@ -3320,12 +3332,11 @@ declare abstract class ContextDependency extends Dependency { userRequest: string; critical?: string | false; hadGlobalOrStickyRegExp: boolean; - request: any; - range: any; - valueRange: any; + request?: string; + range?: [number, number]; + valueRange?: [number, number]; inShorthand?: string | boolean; - replaces: any; - prepend: any; + replaces?: { value: string; range: [number, number] }[]; } type ContextDependencyOptions = ContextOptions & { request: string }; declare abstract class ContextElementDependency extends ModuleDependency { @@ -3390,7 +3401,7 @@ declare abstract class ContextModuleFactory extends ModuleFactory { callback: ( err: null | Error, dependencies?: ContextElementDependency[] - ) => any + ) => void ): void; } type ContextModuleOptions = ContextOptions & ContextModuleOptionsExtras; @@ -4342,7 +4353,7 @@ declare interface EffectData { assertions?: ImportAttributes; mimetype?: string; dependency: string; - descriptionData?: Record; + descriptionData?: JsonObjectTypes; compiler?: string; issuer: string; issuerLayer: string; @@ -4943,9 +4954,6 @@ declare interface ExperimentsNormalizedExtra { */ lazyCompilation?: false | LazyCompilationOptions; } -type ExportAllDeclarationJavascriptParser = ExportAllDeclarationImport & { - attributes?: ImportAttribute[]; -}; declare abstract class ExportInfo { name: string; @@ -5045,9 +5053,6 @@ declare abstract class ExportInfo { | "not provided"; getRenameInfo(): string; } -type ExportNamedDeclarationJavascriptParser = ExportNamedDeclarationImport & { - attributes?: ImportAttribute[]; -}; type ExportPresenceMode = false | 0 | 1 | 2 | 3; declare interface ExportSpec { /** @@ -6120,6 +6125,15 @@ declare class HarmonyImportDependencyTemplate extends DependencyTemplate { referencedModule: Module ): undefined | string | boolean | SortableSet; } +declare interface HarmonySettings { + ids: string[]; + source: string; + sourceOrder: number; + name: string; + await: boolean; + attributes?: ImportAttributes; + defer?: boolean; +} declare class Hash { constructor(); @@ -6341,16 +6355,7 @@ type IgnorePluginOptions = */ checkResource: (resource: string, context: string) => boolean; }; -type ImportAttribute = BaseNode & { - type: "ImportAttribute"; - key: Identifier | SimpleLiteral | RegExpLiteral | BigIntLiteral; - value: Literal; -}; type ImportAttributes = Record & {}; -type ImportDeclarationJavascriptParser = ImportDeclarationImport & { - attributes?: ImportAttribute[]; - phase?: "defer"; -}; declare interface ImportDependencyMeta { attributes?: ImportAttributes; externalType?: "import" | "module"; @@ -6403,6 +6408,10 @@ declare interface ImportModuleOptions { */ baseUri?: string; } +declare interface ImportSettings { + references: string[][]; + expression: ImportExpressionJavascriptParser; +} type ImportSource = | undefined | null @@ -6765,9 +6774,9 @@ declare class JavascriptParser extends ParserClass { >; preStatement: SyncBailHook< [ - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -6798,9 +6807,9 @@ declare class JavascriptParser extends ParserClass { >; blockPreStatement: SyncBailHook< [ - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -6831,9 +6840,9 @@ declare class JavascriptParser extends ParserClass { >; statement: SyncBailHook< [ - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -6886,33 +6895,24 @@ declare class JavascriptParser extends ParserClass { boolean | void >; label: HookMap>; - import: SyncBailHook< - [ImportDeclarationJavascriptParser, ImportSource], - boolean | void - >; + import: SyncBailHook<[ImportDeclaration, ImportSource], boolean | void>; importSpecifier: SyncBailHook< - [ImportDeclarationJavascriptParser, ImportSource, null | string, string], + [ImportDeclaration, ImportSource, null | string, string], boolean | void >; export: SyncBailHook< - [ExportNamedDeclarationJavascriptParser | ExportDefaultDeclaration], + [ExportNamedDeclaration | ExportDefaultDeclaration], boolean | void >; exportImport: SyncBailHook< - [ - ( - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser - ), - ImportSource - ], + [ExportNamedDeclaration | ExportAllDeclaration, ImportSource], boolean | void >; exportDeclaration: SyncBailHook< [ ( - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ExportNamedDeclaration + | ExportAllDeclaration | ExportDefaultDeclaration ), Declaration @@ -6959,8 +6959,8 @@ declare class JavascriptParser extends ParserClass { exportSpecifier: SyncBailHook< [ ( - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ExportNamedDeclaration + | ExportAllDeclaration | ExportDefaultDeclaration ), string, @@ -6971,10 +6971,7 @@ declare class JavascriptParser extends ParserClass { >; exportImportSpecifier: SyncBailHook< [ - ( - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser - ), + ExportNamedDeclaration | ExportAllDeclaration, ImportSource, null | string, null | string, @@ -7099,9 +7096,9 @@ declare class JavascriptParser extends ParserClass { semicolons?: Set; statementPath?: StatementPathItem[]; prevStatement?: - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | ImportExpressionImport | UnaryExpression | ArrayExpression @@ -7158,7 +7155,12 @@ declare class JavascriptParser extends ParserClass { Expression, Set >; - currentTagData?: TagData; + currentTagData?: + | (TopLevelSymbol & Record) + | (HarmonySettings & Record) + | (ImportSettings & Record) + | (CommonJsImportSettings & Record) + | (CompatibilitySettings & Record); magicCommentContext: Context; destructuringAssignmentPropertiesFor( node: Expression @@ -7203,9 +7205,9 @@ declare class JavascriptParser extends ParserClass { */ modulePreWalkStatements( statements: ( - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | VariableDeclaration | ClassDeclaration @@ -7237,9 +7239,9 @@ declare class JavascriptParser extends ParserClass { */ preWalkStatements( statements: ( - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | VariableDeclaration | ClassDeclaration @@ -7271,9 +7273,9 @@ declare class JavascriptParser extends ParserClass { */ blockPreWalkStatements( statements: ( - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | VariableDeclaration | ClassDeclaration @@ -7305,9 +7307,9 @@ declare class JavascriptParser extends ParserClass { */ walkStatements( statements: ( - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | VariableDeclaration | ClassDeclaration @@ -7339,9 +7341,9 @@ declare class JavascriptParser extends ParserClass { */ preWalkStatement( statement: - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -7370,9 +7372,9 @@ declare class JavascriptParser extends ParserClass { ): void; blockPreWalkStatement( statement: - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -7401,9 +7403,9 @@ declare class JavascriptParser extends ParserClass { ): void; walkStatement( statement: - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | MaybeNamedFunctionDeclaration | VariableDeclaration @@ -7503,29 +7505,19 @@ declare class JavascriptParser extends ParserClass { | ThisExpression | UpdateExpression | YieldExpression; - modulePreWalkImportDeclaration( - statement: ImportDeclarationJavascriptParser - ): void; + modulePreWalkImportDeclaration(statement: ImportDeclaration): void; enterDeclaration( declaration: Declaration, onIdent: (ident: string, identifier: Identifier) => void ): void; - modulePreWalkExportNamedDeclaration( - statement: ExportNamedDeclarationJavascriptParser - ): void; - blockPreWalkExportNamedDeclaration( - statement: ExportNamedDeclarationJavascriptParser - ): void; - walkExportNamedDeclaration( - statement: ExportNamedDeclarationJavascriptParser - ): void; + modulePreWalkExportNamedDeclaration(statement: ExportNamedDeclaration): void; + blockPreWalkExportNamedDeclaration(statement: ExportNamedDeclaration): void; + walkExportNamedDeclaration(statement: ExportNamedDeclaration): void; blockPreWalkExportDefaultDeclaration( statement: ExportDefaultDeclaration ): void; walkExportDefaultDeclaration(statement: ExportDefaultDeclaration): void; - modulePreWalkExportAllDeclaration( - statement: ExportAllDeclarationJavascriptParser - ): void; + modulePreWalkExportAllDeclaration(statement: ExportAllDeclaration): void; preWalkVariableDeclaration(statement: VariableDeclaration): void; blockPreWalkVariableDeclaration(statement: VariableDeclaration): void; preWalkVariableDeclarator(declarator: VariableDeclarator): void; @@ -7735,7 +7727,7 @@ declare class JavascriptParser extends ParserClass { hookMap: HookMap>, info: ExportedVariableInfo, fallback: undefined | ((name: string) => undefined | R), - defined: undefined | ((result?: string) => any), + defined: undefined | ((result?: string) => undefined | R), ...args: AsArray ): undefined | R; callHooksForNameWithFallback( @@ -7775,9 +7767,9 @@ declare class JavascriptParser extends ParserClass { inBlockScope(fn: () => void, inExecutedPath?: boolean): void; detectMode( statements: ( - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | FunctionDeclaration | VariableDeclaration | ClassDeclaration @@ -7928,11 +7920,25 @@ declare class JavascriptParser extends ParserClass { setAsiPosition(pos: number): void; unsetAsiPosition(pos: number): void; isStatementLevelExpression(expr: Expression): boolean; - getTagData(name: string, tag: symbol): undefined | TagData; + getTagData( + name: string, + tag: symbol + ): + | undefined + | (TopLevelSymbol & Record) + | (HarmonySettings & Record) + | (ImportSettings & Record) + | (CommonJsImportSettings & Record) + | (CompatibilitySettings & Record); tagVariable( name: string, tag: symbol, - data?: TagData, + data?: + | (TopLevelSymbol & Record) + | (HarmonySettings & Record) + | (ImportSettings & Record) + | (CommonJsImportSettings & Record) + | (CompatibilitySettings & Record), flags?: 0 | 1 | 2 | 4 ): void; defineVariable(name: string): void; @@ -8071,9 +8077,9 @@ declare class JavascriptParser extends ParserClass { }>; static getImportAttributes: ( node: - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | ImportExpressionJavascriptParser ) => undefined | ImportAttributes; } @@ -8718,9 +8724,9 @@ declare interface KnownStatsChunk { hash: string; childrenByOrder: Record; id?: string | number; - siblings?: (string | number)[]; - parents?: (string | number)[]; - children?: (string | number)[]; + siblings?: ChunkId[]; + parents?: ChunkId[]; + children?: ChunkId[]; modules?: StatsModule[]; filteredModules?: number; origins?: StatsChunkOrigin[]; @@ -8734,8 +8740,8 @@ declare interface KnownStatsChunkGroup { auxiliaryAssets?: { name: string; size?: number }[]; filteredAuxiliaryAssets?: number; auxiliaryAssetsSize?: number; - children?: { [index: string]: StatsChunkGroup[] }; - childAssets?: { [index: string]: string[] }; + children?: Record; + childAssets?: Record; isOverSizeLimit?: boolean; } declare interface KnownStatsChunkOrigin { @@ -8827,7 +8833,7 @@ declare interface KnownStatsModule { index2?: number; postOrderIndex?: number; size?: number; - sizes?: { [index: string]: number }; + sizes?: Record; cacheable?: boolean; built?: boolean; codeGenerated?: boolean; @@ -9295,7 +9301,6 @@ declare interface LimitChunkCountPluginOptions { */ maxChunks: number; } -type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral; declare interface LoadScriptCompilationHooks { createScript: SyncWaterfallHook<[string, Chunk], string>; } @@ -9432,7 +9437,7 @@ declare interface LoaderPluginLoaderContext { importModule( request: string, options: undefined | ImportModuleOptions, - callback: (err?: null | Error, exports?: any) => any + callback: (err?: null | Error, exports?: any) => void ): void; importModule(request: string, options?: ImportModuleOptions): Promise; } @@ -10871,7 +10876,7 @@ declare class MultiCompiler { fn: ( compiler: Compiler, callback: CallbackWebpackFunction_2 - ) => any, + ) => void, callback: CallbackWebpackFunction_2 ): void; watch( @@ -13162,7 +13167,7 @@ declare class Profiler { startProfiling(): Promise | Promise<[any, any, any]>; sendCommand(method: string, params?: object): Promise; destroy(): Promise; - stopProfiling(): Promise<{ profile: any }>; + stopProfiling(): Promise<{ profile: { startTime: number; endTime: number } }>; } declare class ProfilingPlugin { constructor(options?: ProfilingPluginOptions); @@ -16726,9 +16731,9 @@ type Statement = | ForInStatement | ForOfStatement; type StatementPathItem = - | ImportDeclarationJavascriptParser - | ExportNamedDeclarationJavascriptParser - | ExportAllDeclarationJavascriptParser + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration | ImportExpressionImport | UnaryExpression | ArrayExpression @@ -17425,12 +17430,14 @@ declare interface SyntheticDependencyLocation { declare const TOMBSTONE: unique symbol; declare const TRANSITIVE: unique symbol; declare const TRANSITIVE_ONLY: unique symbol; -declare interface TagData { - [index: string]: any; -} declare interface TagInfo { tag: symbol; - data?: TagData; + data?: + | (TopLevelSymbol & Record) + | (HarmonySettings & Record) + | (ImportSettings & Record) + | (CommonJsImportSettings & Record) + | (CompatibilitySettings & Record); next?: TagInfo; } declare interface TargetItemWithConnection {