Skip to content

Commit 42cbb9d

Browse files
refactor(types): replace EXPECTED_ANY with real types outside the JS syntax files
1 parent ffa7ce7 commit 42cbb9d

35 files changed

Lines changed: 246 additions & 171 deletions

‎lib/Compilation.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ const { toError } = ErrorHelpers;
170170
/** @import ModuleGraphConnection from "./graph/ModuleGraphConnection" */
171171
/** @import RequestShortener from "./util/RequestShortener" */
172172
/** @import RuntimeModule from "./runtime/RuntimeModule" */
173-
/** @import { RenderManifestEntry, RenderManifestOptions } from "./template/Template" */
173+
/**
174+
* @import {
175+
* RenderManifestEntry,
176+
* RenderManifestEntryTemplated,
177+
* RenderManifestOptions
178+
* } from "./template/Template"
179+
*/
174180

175181
/**
176182
* One language's source embedded in another's output.
@@ -4106,7 +4112,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
41064112
const warning = new (getModuleDependencyWarning())(
41074113
module,
41084114
w,
4109-
/** @type {EXPECTED_ANY} */ (w).loc || d.loc
4115+
w.loc || d.loc
41104116
);
41114117
this.warnings.push(warning);
41124118
hasProblems = true;
@@ -4118,7 +4124,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
41184124
const error = new (getModuleDependencyError())(
41194125
module,
41204126
e,
4121-
/** @type {EXPECTED_ANY} */ (e).loc || d.loc
4127+
e.loc || d.loc
41224128
);
41234129
this.errors.push(error);
41244130
hasProblems = true;
@@ -4729,9 +4735,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
47294735
* is over. `runtimeRequirementInTree` is a sync hook, so a tap cannot await
47304736
* the load itself; anything the tap reads off the requirement set must be
47314737
* captured before queueing, since `create` runs later.
4738+
* @template T
47324739
* @param {Chunk} chunk target chunk
4733-
* @param {() => Promise<EXPECTED_ANY>} load resolves the runtime module implementation
4734-
* @param {(loaded: EXPECTED_ANY) => RuntimeModule} create builds the runtime module from it
4740+
* @param {() => Promise<T>} load resolves the runtime module implementation
4741+
* @param {(loaded: T) => RuntimeModule} create builds the runtime module from it
47354742
* @param {ChunkGraph} chunkGraph the chunk graph
47364743
* @returns {void}
47374744
*/
@@ -6035,7 +6042,7 @@ This prevents using hashes of each other and should be avoided.`);
60356042
);
60366043

60376044
assetCacheItem.get((err, sourceFromCache) => {
6038-
/** @type {string | import("./template/TemplatedPathPlugin").TemplatePathFn<EXPECTED_ANY>} */
6045+
/** @type {RenderManifestEntryTemplated["filenameTemplate"]} */
60396046
let filenameTemplate;
60406047
/** @type {string} */
60416048
let file;

‎lib/config/normalization.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const getCreatePathGlobRegExp = memoize(
2929
* OptimizationRuntimeChunkNormalized,
3030
* OutputNormalized,
3131
* PluginsNormalized,
32+
* RawDevTool,
3233
* WebpackOptions,
3334
* WebpackOptionsNormalized
3435
* } from "../../declarations/WebpackOptions"
@@ -766,7 +767,7 @@ const applyWebpackOptionsInterception = (options) => {
766767
// Prefer `all`, then `javascript`, then `css`
767768
const match = ["all", "javascript", "css"]
768769
.map((type) =>
769-
/** @type {Extract<WebpackOptionsNormalized["devtool"], EXPECTED_ANY[]>} */ (
770+
/** @type {Exclude<WebpackOptionsNormalized["devtool"], RawDevTool | undefined>} */ (
770771
_devtool
771772
).find((item) => item.type === type)
772773
)

‎lib/css/cssMinify.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @typedef {(source: string, info: { type: string, hostType: string }) => Promise<string | EmbeddedSourceResult | undefined> | string | EmbeddedSourceResult | undefined} AsyncEmbeddedSourceRenderer
1919
*/
2020
/** @import { SourceMap } from "../util/SourceProcessor" */
21+
/** @import { DeferredEmbeddedSource } from "../util/dataURL" */
2122
/** @typedef {import("../util/extractComments").PluginExtractComments} ExtractCommentsOption */
2223
/** @typedef {import("../../declarations/WebpackOptions").OptimizationMinimizeExtractComments} MinimizeExtractComments */
2324

@@ -164,7 +165,10 @@ const cssMinify = async (
164165
const renderer =
165166
renderEmbeddedSource === undefined
166167
? undefined
167-
: (/** @type {string} */ _source, /** @type {EXPECTED_ANY} */ hole) =>
168+
: (
169+
/** @type {string} */ _source,
170+
/** @type {DeferredEmbeddedSource} */ hole
171+
) =>
168172
askEmbeddedRenderer(renderEmbeddedSource, hole, reported).then(
169173
embeddedText
170174
);

‎lib/css/syntax-parser.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,12 +7559,16 @@ const _ALL_TRANSFORMS = Object.freeze({
75597559
* @returns {Required<CssTransformOptions>} every rewrite resolved
75607560
*/
75617561
const _transformsFrom = (options) => {
7562-
/** @type {EXPECTED_ANY} */
7562+
/** @type {Required<CssTransformOptions>} */
75637563
const out = { ..._ALL_TRANSFORMS };
75647564
if (options !== undefined) {
75657565
for (const name of Object.keys(_ALL_TRANSFORMS)) {
7566-
const value = /** @type {EXPECTED_ANY} */ (options)[name];
7567-
if (value !== undefined) out[name] = value;
7566+
const value = options[/** @type {keyof CssTransformOptions} */ (name)];
7567+
if (value !== undefined) {
7568+
/** @type {{ [name: string]: CssTransformOptions[keyof CssTransformOptions] }} */ (
7569+
out
7570+
)[name] = value;
7571+
}
75687572
}
75697573
}
75707574
return out;
@@ -7604,13 +7608,15 @@ const _keptComments = (comments) => {
76047608
* @returns {CssTransformOptions | undefined} the switches, or undefined when none is set
76057609
*/
76067610
const pickTransforms = (options) => {
7607-
/** @type {EXPECTED_ANY} */
7611+
/** @type {CssTransformOptions | undefined} */
76087612
let out;
76097613
for (const name of Object.keys(_ALL_TRANSFORMS)) {
76107614
const value = options[/** @type {keyof CssTransformOptions} */ (name)];
76117615
if (value === undefined) continue;
76127616
if (out === undefined) out = {};
7613-
out[name] = value;
7617+
/** @type {{ [name: string]: CssTransformOptions[keyof CssTransformOptions] }} */ (
7618+
out
7619+
)[name] = value;
76147620
}
76157621
return out;
76167622
};

‎lib/dependencies/context/ContextDependencyHelpers.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const splitContextFromPrefix = (prefix) => {
6464
};
6565

6666
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
67-
/** @typedef {{ new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */
67+
/** @typedef {{ new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: never[]): ContextDependency }} ContextDependencyConstructor */
6868

6969
/**
7070
* Defines the get additional dep args type used by this module.

‎lib/dependencies/core/ImportPhase.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getCommentCompilationWarning = memoize(() =>
2323
* ImportExpression
2424
* } from "../../javascript/JavascriptParser"
2525
*/
26+
/** @import { MagicCommentOptions } from "../../util/magicComment" */
2627

2728
/** @typedef {typeof ImportPhase.Evaluation | typeof ImportPhase.Defer | typeof ImportPhase.Source} ImportPhaseType */
2829

@@ -68,7 +69,7 @@ const ImportPhaseUtils = {
6869

6970
/**
7071
* Defines the get comment options type used by this module.
71-
* @typedef {() => Record<string, EXPECTED_ANY> | null} GetCommentOptions
72+
* @typedef {() => MagicCommentOptions | null} GetCommentOptions
7273
*/
7374

7475
/**

‎lib/dependencies/worker/WorkerAndWorkletPlugin.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const getCommentCompilationWarning = memoize(() =>
6666
* } from "../../javascript/JavascriptParser"
6767
*/
6868
/** @import Parser from "../../javascript/JavascriptParser" */
69+
/** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
6970
/** @import { ESMSettings } from "../esm/ESMImportDependencyParserPlugin" */
7071
/** @import { ResourceHint } from "./WorkerDependency" */
7172

@@ -245,13 +246,13 @@ class WorkerAndWorkletPlugin {
245246
}
246247
};
247248

248-
/** @typedef {Record<string, EXPECTED_ANY>} Values */
249+
/** @typedef {Record<string, ReturnType<BasicEvaluatedExpression["asCompileTimeValue"]>>} Values */
249250

250251
/**
251252
* Parses object expression.
252253
* @param {JavascriptParser} parser the parser
253254
* @param {ObjectExpression} expr expression
254-
* @returns {{ expressions: Record<string, Expression | Pattern>, otherElements: (Property | SpreadElement)[], values: Values, spread: boolean, insertType: "comma" | "single", insertLocation: number }} parsed object
255+
* @returns {{ expressions: Record<string, Expression | Pattern | undefined>, otherElements: (Property | SpreadElement)[], values: Values, spread: boolean, insertType: "comma" | "single", insertLocation: number }} parsed object
255256
*/
256257
const parseObjectExpression = (parser, expr) => {
257258
/** @type {Values} */
@@ -417,10 +418,8 @@ class WorkerAndWorkletPlugin {
417418
) {
418419
continue;
419420
}
420-
/** @type {EXPECTED_ANY} */
421-
(entryOptions)[key] = /** @type {EXPECTED_ANY} */ (
422-
userEntryOptions
423-
)[key];
421+
/** @type {Record<string, EntryOptions[keyof EntryOptions]>} */
422+
(entryOptions)[key] = userEntryOptions[key];
424423
}
425424
}
426425
}
@@ -484,7 +483,7 @@ class WorkerAndWorkletPlugin {
484483
? parseObjectExpression(parser, arg2)
485484
: {
486485
expressions:
487-
/** @type {Record<string, Expression | Pattern>} */ ({}),
486+
/** @type {Record<string, Expression | Pattern | undefined>} */ ({}),
488487
otherElements: [],
489488
/** @type {Values} */
490489
values: {},
@@ -574,8 +573,7 @@ class WorkerAndWorkletPlugin {
574573
);
575574
dep.loc = parser.getLocation(expr);
576575
parser.state.module.addPresentationalDependency(dep);
577-
/** @type {EXPECTED_ANY} */
578-
(expressions).type = undefined;
576+
expressions.type = undefined;
579577
}
580578
} else if (insertType === "comma") {
581579
if (this._module || hasSpreadInOptions) {

‎lib/fs/FileSystemInfo.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class SnapshotIterator {
197197

198198
/**
199199
* Represents SnapshotIterable.
200-
* @template T
200+
* @template {{ keys(): IterableIterator<string> } | undefined} T
201201
*/
202202
class SnapshotIterable {
203203
/**
@@ -237,9 +237,7 @@ class SnapshotIterable {
237237
if (maps.length > 0) {
238238
const map = maps.pop();
239239
if (map !== undefined) {
240-
it =
241-
/** @type {Set<string> | Map<string, EXPECTED_ANY>} */
242-
(map).keys();
240+
it = map.keys();
243241
state = 2;
244242
} else {
245243
break;
@@ -607,7 +605,7 @@ class Snapshot {
607605

608606
/**
609607
* Creates an iterable from the provided get map.
610-
* @template T
608+
* @template {{ keys(): IterableIterator<string> } | undefined} T
611609
* @param {GetMapsFunction<T>} getMaps first
612610
* @returns {SnapshotIterable<T>} iterable
613611
*/

‎lib/fs/fs.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ const { ABSOLUTE_PATH_REGEXP } = require("../util/identifier");
458458
* @typedef {object} StreamOptions
459459
* @property {(string | undefined)=} flags
460460
* @property {(BufferEncoding | undefined)} encoding
461-
* @property {(number | EXPECTED_ANY | undefined)=} fd
461+
* @property {(number | import("fs").promises.FileHandle | undefined)=} fd
462462
* @property {(number | undefined)=} mode
463463
* @property {(boolean | undefined)=} autoClose
464464
* @property {(boolean | undefined)=} emitClose

‎lib/html/HtmlParser.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ const isLinkStylesheet = (attributes) => {
453453
* `constructor`, or `toString` resolve to inherited values at lookup
454454
* time — producing bogus dependencies and letting `sources: false` be
455455
* bypassed.
456-
* @param {...(Record<string, EXPECTED_ANY> | undefined)} bags property bags
457-
* @returns {EXPECTED_ANY} null-prototype dictionary
456+
* @template T
457+
* @param {...(Record<string, T> | undefined)} bags property bags
458+
* @returns {Record<string, T>} null-prototype dictionary
458459
*/
459460
const dict = (...bags) => Object.assign(Object.create(null), ...bags);
460461

@@ -884,8 +885,7 @@ class HtmlParser extends Parser {
884885
// An entry name starts with the page's own path, so two pages never claim
885886
// one — from `resource`, since `identifier()` is `html|<path>`.
886887
/** @type {string} */
887-
const resource =
888-
/** @type {EXPECTED_ANY} */ (module).resource || module.identifier();
888+
const resource = module.resource || module.identifier();
889889
const entryPrefix = entryNamePrefix(
890890
context ? contextify(context, resource) : resource,
891891
hashFunction

0 commit comments

Comments
 (0)