diff --git a/lib/APIPlugin.js b/lib/APIPlugin.js index 16e187265..cc13392b8 100644 --- a/lib/APIPlugin.js +++ b/lib/APIPlugin.js @@ -24,9 +24,9 @@ const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule"); const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule"); /** @typedef {import("./Compiler")} Compiler */ +/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */ /** @typedef {import("./javascript/JavascriptParser").Range} Range */ -/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ /** * @param {boolean | undefined} module true if ES module @@ -251,7 +251,7 @@ class APIPlugin { ? new BasicEvaluatedExpression().setNull() : new BasicEvaluatedExpression().setString( parser.state.module.layer - ) + ) ).setRange(/** @type {Range} */ (expr.range)) ); parser.hooks.evaluateTypeof diff --git a/lib/Compilation.js b/lib/Compilation.js index c17748d5c..1c23bbfa5 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -1087,7 +1087,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si } /** - * @param {StatsOptions | string} optionsOrPreset stats option value + * @param {StatsOptions | string | undefined} optionsOrPreset stats option value * @param {CreateStatsOptionsContext} context context * @returns {NormalizedStatsOptions} normalized options */ diff --git a/lib/ConditionalInitFragment.js b/lib/ConditionalInitFragment.js index 93402f5b5..54abfd7c7 100644 --- a/lib/ConditionalInitFragment.js +++ b/lib/ConditionalInitFragment.js @@ -62,8 +62,8 @@ class ConditionalInitFragment extends InitFragment { } /** - * @param {Context} context context - * @returns {string|Source} the source code that will be included as initialization code + * @param {GenerateContext} context context + * @returns {string | Source} the source code that will be included as initialization code */ getContent(context) { if (this.runtimeCondition === false || !this.content) return ""; @@ -79,7 +79,7 @@ class ConditionalInitFragment extends InitFragment { } /** - * @param {Context} context context + * @param {GenerateContext} context context * @returns {string|Source=} the source code that will be included at the end of the module */ getEndContent(context) { diff --git a/lib/DefinePlugin.js b/lib/DefinePlugin.js index f604523ec..ed02a3cbd 100644 --- a/lib/DefinePlugin.js +++ b/lib/DefinePlugin.js @@ -23,9 +23,11 @@ const createHash = require("./util/createHash"); /** @typedef {import("estree").Expression} Expression */ /** @typedef {import("./Compiler")} Compiler */ +/** @typedef {import("./Module").BuildInfo} BuildInfo */ /** @typedef {import("./NormalModule")} NormalModule */ /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */ +/** @typedef {import("./javascript/JavascriptParser").Range} Range */ /** @typedef {import("./logging/Logger").Logger} Logger */ /** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */ @@ -66,7 +68,7 @@ class RuntimeValue { * @returns {CodeValuePrimitive} code */ exec(parser, valueCacheVersions, key) { - const buildInfo = parser.state.module.buildInfo; + const buildInfo = /** @type {BuildInfo} */ (parser.state.module.buildInfo); if (this.options === true) { buildInfo.cacheable = false; } else { @@ -136,19 +138,21 @@ const stringifyObj = ( let code; let arr = Array.isArray(obj); if (arr) { - code = `[${obj - .map(code => - toCode( - code, - parser, - valueCacheVersions, - key, - runtimeTemplate, - logger, - null + code = `[${ + /** @type {any[]} */ (obj) + .map(code => + toCode( + code, + parser, + valueCacheVersions, + key, + runtimeTemplate, + logger, + null + ) ) - ) - .join(",")}]`; + .join(",") + }]`; } else { let keys = Object.keys(obj); if (objKeys) { @@ -157,7 +161,7 @@ const stringifyObj = ( } code = `{${keys .map(key => { - const code = obj[key]; + const code = /** @type {{[k: string]: any}} */ (obj)[key]; return ( JSON.stringify(key) + ":" + @@ -263,6 +267,10 @@ const toCode = ( return strCode; }; +/** + * @param {CodeValue} code code + * @returns {string | undefined} result + */ const toCacheVersion = code => { if (code === null) { return "null"; @@ -285,7 +293,7 @@ const toCacheVersion = code => { if (typeof code === "object") { const items = Object.keys(code).map(key => ({ key, - value: toCacheVersion(code[key]) + value: toCacheVersion(/** @type {Record} */ (code)[key]) })); if (items.some(({ value }) => value === undefined)) return undefined; return `{${items.map(({ key, value }) => `${key}: ${value}`).join(", ")}}`; @@ -353,14 +361,21 @@ class DefinePlugin { const handler = parser => { const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN); parser.hooks.program.tap(PLUGIN_NAME, () => { - const { buildInfo } = parser.state.module; + const buildInfo = /** @type {BuildInfo} */ ( + parser.state.module.buildInfo + ); if (!buildInfo.valueDependencies) buildInfo.valueDependencies = new Map(); buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue); }); + /** + * @param {string} key key + */ const addValueDependency = key => { - const { buildInfo } = parser.state.module; + const buildInfo = /** @type {BuildInfo} */ ( + parser.state.module.buildInfo + ); buildInfo.valueDependencies.set( VALUE_DEP_PREFIX + key, compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key) @@ -376,7 +391,7 @@ class DefinePlugin { /** * Walk definitions - * @param {Object} definitions Definitions map + * @param {Record} definitions Definitions map * @param {string} prefix Prefix string * @returns {void} */ @@ -389,7 +404,10 @@ class DefinePlugin { !(code instanceof RuntimeValue) && !(code instanceof RegExp) ) { - walkDefinitions(code, prefix + key + "."); + walkDefinitions( + /** @type {Record} */ (code), + prefix + key + "." + ); applyObjectDefine(prefix + key, code); return; } @@ -458,7 +476,7 @@ class DefinePlugin { ) ); recurse = false; - res.setRange(expr.range); + res.setRange(/** @type {Range} */ (expr.range)); return res; }); parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => { @@ -470,7 +488,7 @@ class DefinePlugin { originalKey, runtimeTemplate, logger, - !parser.isAsiPosition(expr.range[0]), + !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]), parser.destructuringAssignmentPropertiesFor(expr) ); @@ -517,7 +535,7 @@ class DefinePlugin { : "typeof (" + codeCode + ")"; const res = parser.evaluate(typeofCode); recurseTypeof = false; - res.setRange(expr.range); + res.setRange(/** @type {Range} */ (expr.range)); return res; }); parser.hooks.typeof.for(key).tap(PLUGIN_NAME, expr => { @@ -559,7 +577,7 @@ class DefinePlugin { return new BasicEvaluatedExpression() .setTruthy() .setSideEffects(false) - .setRange(expr.range); + .setRange(/** @type {Range} */ (expr.range)); }); parser.hooks.evaluateTypeof .for(key) @@ -576,7 +594,7 @@ class DefinePlugin { key, runtimeTemplate, logger, - !parser.isAsiPosition(expr.range[0]), + !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]), parser.destructuringAssignmentPropertiesFor(expr) ); @@ -622,7 +640,7 @@ class DefinePlugin { /** * Walk definitions - * @param {Object} definitions Definitions map + * @param {Record} definitions Definitions map * @param {string} prefix Prefix string * @returns {void} */ @@ -649,7 +667,10 @@ class DefinePlugin { !(code instanceof RuntimeValue) && !(code instanceof RegExp) ) { - walkDefinitionsForValues(code, prefix + key + "."); + walkDefinitionsForValues( + /** @type {Record} */ (code), + prefix + key + "." + ); } }); }; diff --git a/lib/EvalSourceMapDevToolPlugin.js b/lib/EvalSourceMapDevToolPlugin.js index 6cbd7035b..4ef3dc28c 100644 --- a/lib/EvalSourceMapDevToolPlugin.js +++ b/lib/EvalSourceMapDevToolPlugin.js @@ -129,7 +129,7 @@ class EvalSourceMapDevToolPlugin { // Clone (flat) the sourcemap to ensure that the mutations below do not persist. sourceMap = { ...sourceMap }; - const context = compiler.options.context; + const context = /** @type {string} */ (compiler.options.context); const root = compiler.root; const modules = sourceMap.sources.map(source => { if (!source.startsWith("webpack://")) return source; diff --git a/lib/InitFragment.js b/lib/InitFragment.js index f97b184bc..5440670d9 100644 --- a/lib/InitFragment.js +++ b/lib/InitFragment.js @@ -36,11 +36,11 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => { }; /** - * @template Context + * @template GenerateContext */ class InitFragment { /** - * @param {string | Source | undefined} content the source code that will be included as initialization code + * @param {string | Source} content the source code that will be included as initialization code * @param {number} stage category of initialization code (contribute to order) * @param {number} position position in the category (contribute to order) * @param {string=} key unique key to avoid emitting the same initialization code twice @@ -55,15 +55,15 @@ class InitFragment { } /** - * @param {Context} context context - * @returns {string | Source | undefined} the source code that will be included as initialization code + * @param {GenerateContext} context context + * @returns {string | Source} the source code that will be included as initialization code */ getContent(context) { return this.content; } /** - * @param {Context} context context + * @param {GenerateContext} context context * @returns {string|Source=} the source code that will be included at the end of the module */ getEndContent(context) { diff --git a/lib/Stats.js b/lib/Stats.js index 567683b7b..efb4d95ba 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -65,6 +65,10 @@ class Stats { }); } + /** + * @param {(string|StatsOptions)=} options stats options + * @returns {string} string output + */ toString(options) { options = this.compilation.createStatsOptions(options, { forToString: true diff --git a/lib/async-modules/AwaitDependenciesInitFragment.js b/lib/async-modules/AwaitDependenciesInitFragment.js index 2bec90769..7a991ab5a 100644 --- a/lib/async-modules/AwaitDependenciesInitFragment.js +++ b/lib/async-modules/AwaitDependenciesInitFragment.js @@ -42,8 +42,8 @@ class AwaitDependenciesInitFragment extends InitFragment { } /** - * @param {Context} context context - * @returns {string|Source} the source code that will be included as initialization code + * @param {GenerateContext} context context + * @returns {string | Source} the source code that will be included as initialization code */ getContent({ runtimeRequirements }) { runtimeRequirements.add(RuntimeGlobals.module); diff --git a/lib/dependencies/AMDPlugin.js b/lib/dependencies/AMDPlugin.js index f91781620..2ae03b78b 100644 --- a/lib/dependencies/AMDPlugin.js +++ b/lib/dependencies/AMDPlugin.js @@ -35,7 +35,9 @@ const UnsupportedDependency = require("./UnsupportedDependency"); /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */ /** @typedef {import("../Compiler")} Compiler */ +/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ /** @typedef {import("../javascript/JavascriptParser")} Parser */ +/** @typedef {import("../javascript/JavascriptParser").Range} Range */ const PLUGIN_NAME = "AMDPlugin"; @@ -135,6 +137,11 @@ class AMDPlugin { const handler = (parser, parserOptions) => { if (parserOptions.amd !== undefined && !parserOptions.amd) return; + /** + * @param {string} optionExpr option expression + * @param {string} rootName root name + * @param {function(): TODO} getMembers callback + */ const tapOptionsHooks = (optionExpr, rootName, getMembers) => { parser.hooks.expression .for(optionExpr) @@ -177,10 +184,10 @@ class AMDPlugin { parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => { const dep = new ConstDependency( RuntimeGlobals.amdDefine, - expr.range, + /** @type {Range} */ (expr.range), [RuntimeGlobals.amdDefine] ); - dep.loc = expr.loc; + dep.loc = /** @type {DependencyLocation} */ (expr.loc); parser.state.module.addPresentationalDependency(dep); return true; }); @@ -197,10 +204,10 @@ class AMDPlugin { parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => { const dep = new ConstDependency( RuntimeGlobals.amdDefine, - expr.range, + /** @type {Range} */ (expr.range), [RuntimeGlobals.amdDefine] ); - dep.loc = expr.loc; + dep.loc = /** @type {DependencyLocation} */ (expr.loc); parser.state.module.addPresentationalDependency(dep); return false; }); diff --git a/lib/dependencies/AMDRequireArrayDependency.js b/lib/dependencies/AMDRequireArrayDependency.js index 96dc54bdf..6726661df 100644 --- a/lib/dependencies/AMDRequireArrayDependency.js +++ b/lib/dependencies/AMDRequireArrayDependency.js @@ -18,7 +18,7 @@ const NullDependency = require("./NullDependency"); class AMDRequireArrayDependency extends NullDependency { /** - * @param {TODO} depsArray deps array + * @param {TODO[]} depsArray deps array * @param {Range} range range */ constructor(depsArray, range) { @@ -81,6 +81,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext source.replace(dep.range[0], dep.range[1] - 1, content); } + /** + * @param {AMDRequireArrayDependency} dep the dependency for which the template should be applied + * @param {DependencyTemplateContext} templateContext the context object + * @returns {string} content + */ getContent(dep, templateContext) { const requires = dep.depsArray.map(dependency => { return this.contentForDependency(dependency, templateContext); @@ -88,6 +93,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext return `[${requires.join(", ")}]`; } + /** + * @param {TODO} dep the dependency for which the template should be applied + * @param {DependencyTemplateContext} templateContext the context object + * @returns {string} content + */ contentForDependency( dep, { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements } diff --git a/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js b/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js index 39ab56c55..916d0f50a 100644 --- a/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +++ b/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js @@ -19,13 +19,22 @@ const { getLocalModule } = require("./LocalModulesHelpers"); const UnsupportedDependency = require("./UnsupportedDependency"); const getFunctionExpression = require("./getFunctionExpression"); +/** @typedef {import("estree").Expression} Expression */ +/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ +/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ +/** @typedef {import("../javascript/JavascriptParser").Range} Range */ class AMDRequireDependenciesBlockParserPlugin { constructor(options) { this.options = options; } + /** + * @param {JavascriptParser} parser the parser + * @param {Expression} expression expression + * @returns {boolean} need bind this + */ processFunctionArgument(parser, expression) { let bindThis = true; const fnData = getFunctionExpression(expression); @@ -259,9 +268,22 @@ class AMDRequireDependenciesBlockParserPlugin { } } + /** + * @param {DependencyLocation} loc location + * @param {string} request request + * @returns {AMDRequireDependenciesBlock} AMDRequireDependenciesBlock + */ newRequireDependenciesBlock(loc, request) { return new AMDRequireDependenciesBlock(loc, request); } + + /** + * @param {Range} outerRange outer range + * @param {Range} arrayRange array range + * @param {Range} functionRange function range + * @param {Range} errorCallbackRange error callback range + * @returns {AMDRequireDependency} dependency + */ newRequireDependency( outerRange, arrayRange, @@ -275,9 +297,21 @@ class AMDRequireDependenciesBlockParserPlugin { errorCallbackRange ); } + + /** + * @param {string} request request + * @param {Range=} range range + * @returns {AMDRequireItemDependency} AMDRequireItemDependency + */ newRequireItemDependency(request, range) { return new AMDRequireItemDependency(request, range); } + + /** + * @param {TODO[]} depsArray deps array + * @param {Range} range range + * @returns {AMDRequireArrayDependency} AMDRequireArrayDependency + */ newRequireArrayDependency(depsArray, range) { return new AMDRequireArrayDependency(depsArray, range); } diff --git a/lib/dependencies/AMDRequireItemDependency.js b/lib/dependencies/AMDRequireItemDependency.js index 2218eba3e..614633ad3 100644 --- a/lib/dependencies/AMDRequireItemDependency.js +++ b/lib/dependencies/AMDRequireItemDependency.js @@ -14,7 +14,7 @@ const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateA class AMDRequireItemDependency extends ModuleDependency { /** * @param {string} request the request string - * @param {Range} range location in source code + * @param {Range=} range location in source code */ constructor(request, range) { super(request); diff --git a/lib/dependencies/ExternalModuleInitFragment.js b/lib/dependencies/ExternalModuleInitFragment.js index 70adbac58..2b8ec4c92 100644 --- a/lib/dependencies/ExternalModuleInitFragment.js +++ b/lib/dependencies/ExternalModuleInitFragment.js @@ -71,7 +71,7 @@ class ExternalModuleInitFragment extends InitFragment { /** * @param {GenerateContext} context context - * @returns {string|Source} the source code that will be included as initialization code + * @returns {string | Source} the source code that will be included as initialization code */ getContent({ runtimeRequirements }) { const namedImports = []; diff --git a/lib/dependencies/HarmonyExportInitFragment.js b/lib/dependencies/HarmonyExportInitFragment.js index bddeabfb2..b69e94399 100644 --- a/lib/dependencies/HarmonyExportInitFragment.js +++ b/lib/dependencies/HarmonyExportInitFragment.js @@ -130,8 +130,8 @@ class HarmonyExportInitFragment extends InitFragment { } /** - * @param {Context} context context - * @returns {string|Source} the source code that will be included as initialization code + * @param {GenerateContext} context context + * @returns {string | Source} the source code that will be included as initialization code */ getContent({ runtimeTemplate, runtimeRequirements }) { runtimeRequirements.add(RuntimeGlobals.exports); diff --git a/lib/dependencies/LocalModuleDependency.js b/lib/dependencies/LocalModuleDependency.js index 93aee8d21..2cde22fe1 100644 --- a/lib/dependencies/LocalModuleDependency.js +++ b/lib/dependencies/LocalModuleDependency.js @@ -19,7 +19,7 @@ const NullDependency = require("./NullDependency"); class LocalModuleDependency extends NullDependency { /** * @param {LocalModule} localModule local module - * @param {Range} range range + * @param {Range | undefined} range range * @param {boolean} callNew true, when the local module should be called with new */ constructor(localModule, range, callNew) { diff --git a/lib/dependencies/WorkerPlugin.js b/lib/dependencies/WorkerPlugin.js index 779956468..d36d76d96 100644 --- a/lib/dependencies/WorkerPlugin.js +++ b/lib/dependencies/WorkerPlugin.js @@ -184,8 +184,9 @@ class WorkerPlugin { } } const insertType = expr.properties.length > 0 ? "comma" : "single"; - const insertLocation = - expr.properties[expr.properties.length - 1].range[1]; + const insertLocation = /** @type {Range} */ ( + expr.properties[expr.properties.length - 1].range + )[1]; return { expressions, otherElements, diff --git a/lib/dependencies/getFunctionExpression.js b/lib/dependencies/getFunctionExpression.js index f99123180..5bd2ad2b2 100644 --- a/lib/dependencies/getFunctionExpression.js +++ b/lib/dependencies/getFunctionExpression.js @@ -10,7 +10,7 @@ /** * @param {Expression} expr expressions - * @returns {{fn: TODO, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined }} function expression with additional information + * @returns {{fn: TODO, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information */ module.exports = expr => { // diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index b1d98accb..30d887b7e 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -2355,8 +2355,8 @@ class JavascriptParser extends Parser { } /** - * @param {Declaration} declaration - * @param {TODO} onIdent + * @param {Declaration} declaration declaration + * @param {TODO} onIdent on ident callback */ enterDeclaration(declaration, onIdent) { switch (declaration.type) { @@ -4347,7 +4347,7 @@ class JavascriptParser extends Parser { /** * @param {string} name name * @param {TODO} tag tag info - * @param {TODO} data data + * @param {TODO=} data data */ tagVariable(name, tag, data) { const oldInfo = this.scope.definitions.get(name); diff --git a/lib/util/chainedImports.js b/lib/util/chainedImports.js index 2463cc020..686e5d9e5 100644 --- a/lib/util/chainedImports.js +++ b/lib/util/chainedImports.js @@ -6,6 +6,7 @@ "use strict"; /** @typedef {import("../Dependency")} Dependency */ +/** @typedef {import("../Module")} Module */ /** @typedef {import("../ModuleGraph")} ModuleGraph */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ @@ -17,7 +18,7 @@ * because minifiers treat quoted accessors differently. e.g. import { a } from "./module"; a["b"] vs a.b * @param {string[]} untrimmedIds chained ids * @param {Range} untrimmedRange range encompassing allIds - * @param {Range[]} ranges cumulative range of ids for each of allIds + * @param {Range[] | undefined} ranges cumulative range of ids for each of allIds * @param {ModuleGraph} moduleGraph moduleGraph * @param {Dependency} dependency dependency * @returns {{trimmedIds: string[], trimmedRange: Range}} computed trimmed ids and cumulative range of those ids @@ -44,7 +45,7 @@ exports.getTrimmedIdsAndRange = ( ranges === undefined ? -1 /* trigger failure case below */ : ranges.length + (trimmedIds.length - untrimmedIds.length); - if (idx < 0 || idx >= ranges.length) { + if (idx < 0 || idx >= /** @type {Range[]} */ (ranges).length) { // cspell:ignore minifiers // Should not happen but we can't throw an error here because of backward compatibility with // external plugins in wp5. Instead, we just disable trimming for now. This may break some minifiers. @@ -52,7 +53,7 @@ exports.getTrimmedIdsAndRange = ( // TODO webpack 6 remove the "trimmedIds = ids" above and uncomment the following line instead. // throw new Error("Missing range starts data for id replacement trimming."); } else { - trimmedRange = ranges[idx]; + trimmedRange = /** @type {Range[]} */ (ranges)[idx]; } } @@ -68,11 +69,11 @@ exports.getTrimmedIdsAndRange = ( * @returns {string[]} trimmed ids */ function trimIdsToThoseImported(ids, moduleGraph, dependency) { + /** @type {string[]} */ let trimmedIds = []; - const exportsInfo = moduleGraph.getExportsInfo( - moduleGraph.getModule(dependency) + let currentExportsInfo = moduleGraph.getExportsInfo( + /** @type {Module} */ (moduleGraph.getModule(dependency)) ); - let currentExportsInfo = /** @type {ExportsInfo=} */ exportsInfo; for (let i = 0; i < ids.length; i++) { if (i === 0 && ids[i] === "default") { continue; // ExportInfo for the next level under default is still at the root ExportsInfo, so don't advance currentExportsInfo diff --git a/types.d.ts b/types.d.ts index 457d382ff..ab074d583 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1857,7 +1857,7 @@ declare class Compilation { compilationDependencies: { add: (item?: any) => LazySet }; getStats(): Stats; createStatsOptions( - optionsOrPreset: string | StatsOptions, + optionsOrPreset?: string | StatsOptions, context?: CreateStatsOptionsContext ): NormalizedStatsOptions; createStatsFactory(options?: any): StatsFactory; @@ -5237,14 +5237,14 @@ declare interface InfrastructureLogging { */ stream?: NodeJS.WritableStream; } -declare abstract class InitFragment { +declare abstract class InitFragment { content: string | Source; stage: number; position: number; key?: string; endContent?: string | Source; - getContent(context: Context): string | Source; - getEndContent(context: Context): undefined | string | Source; + getContent(context: GenerateContext): string | Source; + getEndContent(context: GenerateContext): undefined | string | Source; serialize(context: ObjectSerializerContext): void; deserialize(context: ObjectDeserializerContext): void; merge: any; @@ -5680,63 +5680,9 @@ declare class JavascriptParser extends Parser { sourceType: "module" | "auto" | "script"; scope: ScopeInfo; state: ParserState; - comments: any; - semicolons: any; - statementPath: ( - | UnaryExpression - | ArrayExpression - | ArrowFunctionExpression - | AssignmentExpression - | AwaitExpression - | BinaryExpression - | SimpleCallExpression - | NewExpression - | ChainExpression - | ClassExpression - | ConditionalExpression - | FunctionExpression - | Identifier - | ImportExpression - | SimpleLiteral - | RegExpLiteral - | BigIntLiteral - | LogicalExpression - | MemberExpression - | MetaProperty - | ObjectExpression - | SequenceExpression - | TaggedTemplateExpression - | TemplateLiteral - | ThisExpression - | UpdateExpression - | YieldExpression - | FunctionDeclaration - | VariableDeclaration - | ClassDeclaration - | ExpressionStatement - | BlockStatement - | StaticBlock - | EmptyStatement - | DebuggerStatement - | WithStatement - | ReturnStatement - | LabeledStatement - | BreakStatement - | ContinueStatement - | IfStatement - | SwitchStatement - | ThrowStatement - | TryStatement - | WhileStatement - | DoWhileStatement - | ForStatement - | ForInStatement - | ForOfStatement - | ImportDeclaration - | ExportNamedDeclaration - | ExportDefaultDeclaration - | ExportAllDeclaration - )[]; + comments?: Comment[]; + semicolons?: Set; + statementPath: StatementPathItem[]; prevStatement?: | UnaryExpression | ArrayExpression @@ -5791,7 +5737,7 @@ declare class JavascriptParser extends Parser { | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration; - destructuringAssignmentProperties: WeakMap>; + destructuringAssignmentProperties?: WeakMap>; currentTagData: any; destructuringAssignmentPropertiesFor( node: Expression @@ -6031,7 +5977,7 @@ declare class JavascriptParser extends Parser { blockPreWalkExpressionStatement(statement: ExpressionStatement): void; preWalkAssignmentExpression(expression: AssignmentExpression): void; blockPreWalkImportDeclaration(statement?: any): void; - enterDeclaration(declaration?: any, onIdent?: any): void; + enterDeclaration(declaration: Declaration, onIdent?: any): void; blockPreWalkExportNamedDeclaration(statement?: any): void; walkExportNamedDeclaration(statement: ExportNamedDeclaration): void; blockPreWalkExportDefaultDeclaration(statement?: any): void; @@ -6113,16 +6059,20 @@ declare class JavascriptParser extends Parser { walkCallExpression(expression?: any): void; walkMemberExpression(expression: MemberExpression): void; walkMemberExpressionWithExpressionName( - expression?: any, - name?: any, - rootInfo?: any, - members?: any, + expression: any, + name: string, + rootInfo: string | VariableInfo, + members: string[], onUnhandled?: any ): void; walkThisExpression(expression: ThisExpression): void; walkIdentifier(expression: Identifier): void; walkMetaProperty(metaProperty: MetaProperty): void; - callHooksForExpression(hookMap: any, expr: any, ...args: any[]): any; + callHooksForExpression( + hookMap: HookMap>, + expr: any, + ...args: AsArray + ): undefined | R; callHooksForExpressionWithFallback( hookMap: HookMap>, expr: MemberExpression, @@ -6195,8 +6145,29 @@ declare class JavascriptParser extends Parser { | Directive )[] ): void; - enterPatterns(patterns?: any, onIdent?: any): void; - enterPattern(pattern?: any, onIdent?: any): void; + enterPatterns( + patterns: ( + | Identifier + | MemberExpression + | ObjectPattern + | ArrayPattern + | RestElement + | AssignmentPattern + | Property + )[], + onIdent?: any + ): void; + enterPattern( + pattern: + | Identifier + | MemberExpression + | ObjectPattern + | ArrayPattern + | RestElement + | AssignmentPattern + | Property, + onIdent?: any + ): void; enterIdentifier(pattern: Identifier, onIdent?: any): void; enterObjectPattern(pattern: ObjectPattern, onIdent?: any): void; enterArrayPattern(pattern: ArrayPattern, onIdent?: any): void; @@ -6243,12 +6214,12 @@ declare class JavascriptParser extends Parser { | PrivateIdentifier, commentsStartPos: number ): boolean; - getComments(range: [number, number]): any[]; + getComments(range: [number, number]): Comment[]; isAsiPosition(pos: number): boolean; unsetAsiPosition(pos: number): void; isStatementLevelExpression(expr: Expression): boolean; - getTagData(name?: any, tag?: any): any; - tagVariable(name?: any, tag?: any, data?: any): void; + getTagData(name: string, tag?: any): any; + tagVariable(name: string, tag?: any, data?: any): void; defineVariable(name: string): void; undefineVariable(name: string): void; isVariableDefined(name: string): boolean; @@ -12323,6 +12294,60 @@ type Statement = | ForStatement | ForInStatement | ForOfStatement; +type StatementPathItem = + | UnaryExpression + | ArrayExpression + | ArrowFunctionExpression + | AssignmentExpression + | AwaitExpression + | BinaryExpression + | SimpleCallExpression + | NewExpression + | ChainExpression + | ClassExpression + | ConditionalExpression + | FunctionExpression + | Identifier + | ImportExpression + | SimpleLiteral + | RegExpLiteral + | BigIntLiteral + | LogicalExpression + | MemberExpression + | MetaProperty + | ObjectExpression + | SequenceExpression + | TaggedTemplateExpression + | TemplateLiteral + | ThisExpression + | UpdateExpression + | YieldExpression + | FunctionDeclaration + | VariableDeclaration + | ClassDeclaration + | ExpressionStatement + | BlockStatement + | StaticBlock + | EmptyStatement + | DebuggerStatement + | WithStatement + | ReturnStatement + | LabeledStatement + | BreakStatement + | ContinueStatement + | IfStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | WhileStatement + | DoWhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | ImportDeclaration + | ExportNamedDeclaration + | ExportDefaultDeclaration + | ExportAllDeclaration; declare class Stats { constructor(compilation: Compilation); compilation: Compilation; @@ -12332,7 +12357,7 @@ declare class Stats { hasWarnings(): boolean; hasErrors(): boolean; toJson(options?: string | StatsOptions): StatsCompilation; - toString(options?: any): string; + toString(options?: string | StatsOptions): string; } type StatsAsset = KnownStatsAsset & Record; type StatsChunk = KnownStatsChunk & Record;