Skip to content

Commit 848f47a

Browse files
fix: types
1 parent 7dd5e42 commit 848f47a

File tree

94 files changed

+356
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+356
-94
lines changed

.changeset/six-cheetahs-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fix typescript types.

lib/BannerPlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
1111
const Template = require("./Template");
1212
const createSchemaValidation = require("./util/create-schema-validation");
1313

14+
/** @typedef {import("webpack-sources").Source} Source */
1415
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */
1516
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
1617
/** @typedef {import("./Compilation").PathData} PathData */
@@ -88,6 +89,7 @@ class BannerPlugin {
8889
undefined,
8990
options
9091
);
92+
/** @type {WeakMap<Source, { source: ConcatSource, comment: string }>} */
9193
const cache = new WeakMap();
9294
const stage =
9395
this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;

lib/ChunkGraph.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
17401740
} else {
17411741
// cspell:word Tnamespace
17421742
for (const connection of connections) {
1743+
/** @type {Set<ConnectionState>} */
17431744
const states = new Set();
17441745
let stateInfo = "";
17451746
forEachRuntime(
@@ -1754,7 +1755,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
17541755
if (states.size === 1) {
17551756
const state = first(states);
17561757
if (state === false) continue;
1757-
stateInfo = activeStateToString(state);
1758+
stateInfo = activeStateToString(
1759+
/** @type {ConnectionState} */
1760+
(state)
1761+
);
17581762
}
17591763
processConnection(connection, stateInfo);
17601764
}

lib/ChunkGroup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ class ChunkGroup {
429429
* @returns {string[]} the files contained this chunk group
430430
*/
431431
getFiles() {
432+
/** @type {Set<string>} */
432433
const files = new Set();
433434

434435
for (const chunk of this.chunks) {

lib/CleanPlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const mergeAssets = (as1, as2) => {
7070
* @returns {Set<string>} Set of directory paths
7171
*/
7272
function getDirectories(assets) {
73+
/** @type {Set<string>} */
7374
const directories = new Set();
7475
/**
7576
* @param {string} filename asset filename
@@ -143,6 +144,7 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
143144
* @returns {Diff} diff
144145
*/
145146
const getDiffToOldAssets = (currentAssets, oldAssets) => {
147+
/** @type {Diff} */
146148
const diff = new Set();
147149
const now = Date.now();
148150
for (const [asset, ts] of oldAssets) {

lib/Compilation.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ const { isSourceEqual } = require("./util/source");
286286

287287
/**
288288
* @typedef {object} LogEntry
289-
* @property {string} type
289+
* @property {keyof LogType} type
290290
* @property {EXPECTED_ANY[]=} args
291291
* @property {number} time
292292
* @property {string[]=} trace
@@ -514,6 +514,7 @@ class Compilation {
514514
/** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
515515
const processAssetsHook = new AsyncSeriesHook(["assets"]);
516516

517+
/** @type {Set<string>} */
517518
let savedAssets = new Set();
518519
/**
519520
* @param {CompilationAssets} assets assets
@@ -2292,6 +2293,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
22922293
(originModule)
22932294
);
22942295
if (creatingModuleDuringBuildSet === undefined) {
2296+
/** @type {Set<Module>} */
22952297
creatingModuleDuringBuildSet = new Set();
22962298
this.creatingModuleDuringBuild.set(
22972299
/** @type {Module} */
@@ -2598,7 +2600,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
25982600
this.moduleGraph.setModuleMemCaches(this.moduleMemCaches);
25992601
}
26002602
const { moduleGraph, moduleMemCaches } = this;
2603+
/** @type {Set<Module>} */
26012604
const affectedModules = new Set();
2605+
/** @type {Set<Module>} */
26022606
const infectedModules = new Set();
26032607
let statNew = 0;
26042608
let statChanged = 0;
@@ -2714,6 +2718,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
27142718
}
27152719
return affected;
27162720
};
2721+
/** @type {Set<Module>} */
27172722
const directOnlyInfectedModules = new Set();
27182723
for (const module of infectedModules) {
27192724
for (const [
@@ -2732,6 +2737,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
27322737
}
27332738
}
27342739
for (const module of directOnlyInfectedModules) infectedModules.add(module);
2740+
/** @type {Set<Module>} */
27352741
const directOnlyAffectModules = new Set();
27362742
for (const module of affectedModules) {
27372743
for (const [
@@ -2994,6 +3000,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
29943000
* @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
29953001
*/
29963002
const logByLoadersSummary = (category, getDuration, getParallelism) => {
3003+
/** @type {Map<string, { module: Module, profile: ModuleProfile }[]>} */
29973004
const map = new Map();
29983005
for (const [module, profile] of modulesWithProfiles) {
29993006
const list = getOrInsert(
@@ -3205,6 +3212,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
32053212
this.chunkGroups.push(entrypoint);
32063213
connectChunkGroupAndChunk(entrypoint, chunk);
32073214

3215+
/** @type {Set<Module>} */
32083216
const entryModules = new Set();
32093217
for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
32103218
entrypoint.addOrigin(
@@ -3252,6 +3260,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
32523260
modulesList.push(module);
32533261
}
32543262
}
3263+
/** @type {Set<Chunk>} */
32553264
const runtimeChunks = new Set();
32563265
outer: for (const [
32573266
name,
@@ -3625,6 +3634,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
36253634
const runIteration = () => {
36263635
/** @type {CodeGenerationJobs} */
36273636
let delayedJobs = [];
3637+
/** @type {Set<Module>} */
36283638
let delayedModules = new Set();
36293639
asyncLib.eachLimit(
36303640
jobs,
@@ -3746,6 +3756,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
37463756
);
37473757
cache.get((err, cachedResult) => {
37483758
if (err) return callback(/** @type {WebpackError} */ (err));
3759+
/** @type {CodeGenerationResult} */
37493760
let result;
37503761
if (!cachedResult) {
37513762
try {
@@ -3845,6 +3856,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
38453856
continue;
38463857
}
38473858
}
3859+
/** @type {RuntimeRequirements} */
38483860
let set;
38493861
const runtimeRequirements =
38503862
codeGenerationResults.getRuntimeRequirements(module, runtime);
@@ -4574,6 +4586,7 @@ This prevents using hashes of each other and should be avoided.`);
45744586
}
45754587
this.logger.timeEnd("hashing: sort chunks");
45764588

4589+
/** @type {Set<Chunk>} */
45774590
const fullHashChunks = new Set();
45784591
/** @type {CodeGenerationJobs} */
45794592
const codeGenerationJobs = [];
@@ -4702,7 +4715,7 @@ This prevents using hashes of each other and should be avoided.`);
47024715
).hash = moduleHashDigest;
47034716
}
47044717
const chunkHash = createHash(hashFunction);
4705-
chunkHash.update(chunk.hash);
4718+
chunkHash.update(/** @type {string} */ (chunk.hash));
47064719
chunkHash.update(this.hash);
47074720
const chunkHashDigest = chunkHash.digest(hashDigest);
47084721
chunk.hash = chunkHashDigest;
@@ -5026,6 +5039,7 @@ This prevents using hashes of each other and should be avoided.`);
50265039
*/
50275040
createChunkAssets(callback) {
50285041
const outputOptions = this.outputOptions;
5042+
/** @type {WeakMap<Source, CachedSource>} */
50295043
const cachedSourceMap = new WeakMap();
50305044
/** @type {Map<string, {hash: string, source: Source, chunk: Chunk}>} */
50315045
const alreadyWrittenFiles = new Map();

lib/ConcatenationScope.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class ConcatenationScope {
3737
constructor(modulesMap, currentModule, usedNames) {
3838
this._currentModule = currentModule;
3939
if (Array.isArray(modulesMap)) {
40+
/** @type {Map<Module, ConcatenatedModuleInfo>} */
4041
const map = new Map();
4142
for (const info of modulesMap) {
42-
map.set(info.module, info);
43+
map.set(info.module, /** @type {ConcatenatedModuleInfo} */ (info));
4344
}
4445
modulesMap = map;
4546
}

lib/ContextModule.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const makeSerializable = require("./util/makeSerializable");
5454
/** @typedef {import("./Module").LibIdent} LibIdent */
5555
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
5656
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
57+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
58+
/** @typedef {import("./Module").Sources} Sources */
5759
/** @typedef {import("./RequestShortener")} RequestShortener */
5860
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
5961
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -1185,6 +1187,8 @@ module.exports = webpackEmptyAsyncContext;`;
11851187
*/
11861188
codeGeneration(context) {
11871189
const { chunkGraph, compilation } = context;
1190+
1191+
/** @type {Sources} */
11881192
const sources = new Map();
11891193
sources.set(
11901194
JAVASCRIPT_TYPE,
@@ -1193,6 +1197,7 @@ module.exports = webpackEmptyAsyncContext;`;
11931197
compilation
11941198
)
11951199
);
1200+
/** @type {RuntimeRequirements} */
11961201
const set = new Set();
11971202
const allDeps =
11981203
this.dependencies.length > 0

lib/DefinePlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ class DefinePlugin {
418418
* @returns {void}
419419
*/
420420
const handler = (parser) => {
421+
/** @type {Set<string>} */
421422
const hooked = new Set();
422423
const mainValue =
423424
/** @type {ValueCacheVersion} */

lib/DelegatedModule.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const makeSerializable = require("./util/makeSerializable");
3232
/** @typedef {import("./Module").LibIdent} LibIdent */
3333
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
3434
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
35+
/** @typedef {import("./Module").Sources} Sources */
3536
/** @typedef {import("./RequestShortener")} RequestShortener */
3637
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
3738
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -178,6 +179,7 @@ class DelegatedModule extends Module {
178179
str += ";";
179180
}
180181

182+
/** @type {Sources} */
181183
const sources = new Map();
182184
if (this.useSourceMap || this.useSimpleSourceMap) {
183185
sources.set(JAVASCRIPT_TYPE, new OriginalSource(str, this.identifier()));

0 commit comments

Comments
 (0)