Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 24, 2024
1 parent e237b58 commit 0d5476d
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 46 deletions.
3 changes: 1 addition & 2 deletions lib/CleanPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const processAsyncTree = require("./util/processAsyncTree");

/**
* @typedef {object} CleanPluginCompilationHooks
* @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
* @property {SyncBailHook<[string], boolean | void>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
*/

/**
Expand Down Expand Up @@ -310,7 +310,6 @@ class CleanPlugin {
let hooks = compilationHooksMap.get(compilation);
if (hooks === undefined) {
hooks = {
/** @type {SyncBailHook<[string], boolean>} */
keep: new SyncBailHook(["ignore"])
};
compilationHooksMap.set(compilation, hooks);
Expand Down
15 changes: 9 additions & 6 deletions lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
optimizeChunkModules: new AsyncSeriesBailHook(["chunks", "modules"]),
/** @type {SyncHook<[Iterable<Chunk>, Iterable<Module>]>} */
afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
/** @type {SyncBailHook<[], boolean | undefined>} */
/** @type {SyncBailHook<[], boolean | void>} */
shouldRecord: new SyncBailHook([]),

/** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
Expand Down Expand Up @@ -796,7 +796,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si

/** @type {SyncHook<[]>} */
beforeModuleAssets: new SyncHook([]),
/** @type {SyncBailHook<[], boolean>} */
/** @type {SyncBailHook<[], boolean | void>} */
shouldGenerateChunkAssets: new SyncBailHook([]),
/** @type {SyncHook<[]>} */
beforeChunkAssets: new SyncHook([]),
Expand Down Expand Up @@ -844,7 +844,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
/** @type {AsyncSeriesHook<[CompilationAssets]>} */
processAdditionalAssets: new AsyncSeriesHook(["assets"]),

/** @type {SyncBailHook<[], boolean | undefined>} */
/** @type {SyncBailHook<[], boolean | void>} */
needAdditionalSeal: new SyncBailHook([]),
/** @type {AsyncSeriesHook<[]>} */
afterSeal: new AsyncSeriesHook([]),
Expand All @@ -865,7 +865,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
/** @type {SyncWaterfallHook<[string, object, AssetInfo | undefined]>} */
assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),

/** @type {SyncBailHook<[], boolean>} */
/** @type {SyncBailHook<[], boolean | void>} */
needAdditionalPass: new SyncBailHook([]),

/** @type {SyncHook<[Compiler, string, number]>} */
Expand All @@ -875,7 +875,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
"compilerIndex"
]),

/** @type {SyncBailHook<[string, LogEntry], true>} */
/** @type {SyncBailHook<[string, LogEntry], boolean | void>} */
log: new SyncBailHook(["origin", "logEntry"]),

/** @type {SyncWaterfallHook<[WebpackError[]]>} */
Expand Down Expand Up @@ -1245,7 +1245,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
typeof console.profile === "function"
) {
console.profile(
`[${name}] ${/** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]}`
`[${name}] ${
/** @type {NonNullable<LogEntry["args"]>} */
(logEntry.args)[0]
}`
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Compiler {
/** @type {SyncHook<[]>} */
initialize: new SyncHook([]),

/** @type {SyncBailHook<[Compilation], boolean | undefined>} */
/** @type {SyncBailHook<[Compilation], boolean | void>} */
shouldEmit: new SyncBailHook(["compilation"]),
/** @type {AsyncSeriesHook<[Stats]>} */
done: new AsyncSeriesHook(["stats"]),
Expand Down Expand Up @@ -201,7 +201,7 @@ class Compiler {
/** @type {AsyncSeriesHook<[]>} */
shutdown: new AsyncSeriesHook([]),

/** @type {SyncBailHook<[string, string, any[] | undefined], true>} */
/** @type {SyncBailHook<[string, string, any[] | undefined], true | void>} */
infrastructureLog: new SyncBailHook(["origin", "type", "args"]),

// TODO the following hooks are weirdly located here
Expand All @@ -214,7 +214,7 @@ class Compiler {
afterPlugins: new SyncHook(["compiler"]),
/** @type {SyncHook<[Compiler]>} */
afterResolvers: new SyncHook(["compiler"]),
/** @type {SyncBailHook<[string, Entry], boolean>} */
/** @type {SyncBailHook<[string, Entry], boolean | void>} */
entryOption: new SyncBailHook(["context", "entry"])
});

Expand Down
10 changes: 5 additions & 5 deletions lib/HotModuleReplacementPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const {

/** @typedef {import("estree").CallExpression} CallExpression */
/** @typedef {import("estree").Expression} Expression */
/** @typedef {import("estree").SpreadElement} SpreadElement */
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
/** @typedef {import("./Chunk")} Chunk */
/** @typedef {import("./Chunk").ChunkId} ChunkId */
Expand All @@ -60,8 +61,8 @@ const {

/**
* @typedef {object} HMRJavascriptParserHooks
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
* @property {SyncBailHook<[CallExpression, string[]], void>} hotAcceptCallback
* @property {SyncBailHook<[Expression | SpreadElement, string[]], void>} hotAcceptWithoutCallback
*/

/** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */
Expand Down Expand Up @@ -133,10 +134,9 @@ class HotModuleReplacementPlugin {
/** @type {BuildInfo} */
(module.buildInfo).moduleConcatenationBailout =
"Hot Module Replacement";

if (expr.arguments.length >= 1) {
const arg = parser.evaluateExpression(
/** @type {Expression} */ (expr.arguments[0])
);
const arg = parser.evaluateExpression(expr.arguments[0]);
/** @type {BasicEvaluatedExpression[]} */
let params = [];
if (arg.isString()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,19 @@ class NormalModuleFactory extends ModuleFactory {
createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData]>} */
module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
/** @type {HookMap<SyncBailHook<[ParserOptions], Parser>>} */
/** @type {HookMap<SyncBailHook<[ParserOptions], Parser | void>>} */
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
/** @type {HookMap<SyncBailHook<[TODO, ParserOptions], void>>} */
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
/** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator>>} */
/** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator | void>>} */
createGenerator: new HookMap(
() => new SyncBailHook(["generatorOptions"])
),
/** @type {HookMap<SyncBailHook<[TODO, GeneratorOptions], void>>} */
generator: new HookMap(
() => new SyncHook(["generator", "generatorOptions"])
),
/** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module>>} */
/** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module | void>>} */
createModuleClass: new HookMap(
() => new SyncBailHook(["createData", "resolveData"])
)
Expand Down
4 changes: 2 additions & 2 deletions lib/javascript/JavascriptModulesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {SyncWaterfallHook<[Source, RenderContext]>} render
* @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
* @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
* @property {SyncBailHook<[Module, RenderBootstrapContext], string>} inlineInRuntimeBailout
* @property {SyncBailHook<[Module, RenderBootstrapContext], string | void>} inlineInRuntimeBailout
* @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
* @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
* @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
* @property {SyncBailHook<[Chunk, RenderContext], boolean>} useSourceMap
* @property {SyncBailHook<[Chunk, RenderContext], boolean | void>} useSourceMap
*/

/** @type {WeakMap<Compilation, CompilationHooks>} */
Expand Down
14 changes: 7 additions & 7 deletions lib/javascript/JavascriptParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,25 @@ class JavascriptParser extends Parser {
constructor(sourceType = "auto") {
super();
this.hooks = Object.freeze({
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | void>>} */
evaluateTypeof: new HookMap(() => new SyncBailHook(["expression"])),
/** @type {HookMap<SyncBailHook<[Expression | SpreadElement | PrivateIdentifier], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[Expression | SpreadElement | PrivateIdentifier], BasicEvaluatedExpression | void>>} */
evaluate: new HookMap(() => new SyncBailHook(["expression"])),
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression | MetaProperty], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression | MetaProperty], BasicEvaluatedExpression | void>>} */
evaluateIdentifier: new HookMap(() => new SyncBailHook(["expression"])),
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[Identifier | ThisExpression | MemberExpression], BasicEvaluatedExpression | void>>} */
evaluateDefinedIdentifier: new HookMap(
() => new SyncBailHook(["expression"])
),
/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | void>>} */
evaluateNewExpression: new HookMap(
() => new SyncBailHook(["expression"])
),
/** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | void>>} */
evaluateCallExpression: new HookMap(
() => new SyncBailHook(["expression"])
),
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression | undefined | null>>} */
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression | void>>} */
evaluateCallExpressionMember: new HookMap(
() => new SyncBailHook(["expression", "param"])
),
Expand Down
2 changes: 1 addition & 1 deletion lib/optimize/ConcatenatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ const TYPES = new Set(["javascript"]);

/**
* @typedef {object} ConcatenateModuleHooks
* @property {SyncBailHook<[Record<string, string>], boolean>} exportsDefinitions
* @property {SyncBailHook<[Record<string, string>], boolean | void>} exportsDefinitions
*/

/** @type {WeakMap<Compilation, ConcatenateModuleHooks>} */
Expand Down
2 changes: 1 addition & 1 deletion lib/optimize/RealContentHashPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const toCachedSource = source => {

/**
* @typedef {object} CompilationHooks
* @property {SyncBailHook<[Buffer[], string], string>} updateHash
* @property {SyncBailHook<[Buffer[], string], string | void>} updateHash
*/

/** @type {WeakMap<Compilation, CompilationHooks>} */
Expand Down
22 changes: 11 additions & 11 deletions lib/stats/StatsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ const smartGrouping = require("../util/smartGrouping");

/**
* @typedef {object} StatsFactoryHooks
* @property {HookMap<SyncBailHook<[ObjectForExtract, FactoryData, StatsFactoryContext], undefined>>} extract
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filter
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], undefined>>} sort
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filterSorted
* @property {HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], undefined>>} groupResults
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], undefined>>} sortResults
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filterResults
* @property {HookMap<SyncBailHook<[FactoryDataItem[], StatsFactoryContext], Result>>} merge
* @property {HookMap<SyncBailHook<[ObjectForExtract, FactoryData, StatsFactoryContext], void>>} extract
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filter
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sort
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterSorted
* @property {HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], void>>} groupResults
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sortResults
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterResults
* @property {HookMap<SyncBailHook<[FactoryDataItem[], StatsFactoryContext], Result | void>>} merge
* @property {HookMap<SyncBailHook<[Result, StatsFactoryContext], Result>>} result
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], string>>} getItemName
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], StatsFactory | undefined>>} getItemFactory
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], string | void>>} getItemName
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], StatsFactory | void>>} getItemFactory
*/

/**
Expand Down Expand Up @@ -128,7 +128,7 @@ class StatsFactory {
* @param {HM} hookMap hook map
* @param {Caches<H>} cache cache
* @param {string} type type
* @param {function(H): R | undefined} fn fn
* @param {function(H): R | void} fn fn
* @returns {R | undefined} hook
* @private
*/
Expand Down
10 changes: 5 additions & 5 deletions lib/stats/StatsPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
/**
* @typedef {object} StatsPrintHooks
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], void>>} sortElements
* @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | undefined>>} printElements
* @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], true>>} sortItems
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string>>} getItemName
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | undefined>>} printItems
* @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | void>>} printElements
* @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], boolean | void>>} sortItems
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} getItemName
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | void>>} printItems
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} print
* @property {HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>} result
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ class StatsPrinter {
* @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
* @param {HM} hookMap hook map
* @param {string} type type
* @param {function(H): R | undefined} fn fn
* @param {function(H): R | void} fn fn
* @returns {R | undefined} hook
*/
_forEachLevel(hookMap, type, fn) {
Expand Down

0 comments on commit 0d5476d

Please sign in to comment.