Skip to content

Commit 0f8b31b

Browse files
fix: reduce type duplications
1 parent 36ffbd4 commit 0f8b31b

32 files changed

+250
-109
lines changed

.changeset/proud-worms-promise.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+
Improve types

lib/ChunkGroup.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,19 @@ class ChunkGroup {
9191
this.chunks = [];
9292
/** @type {OriginRecord[]} */
9393
this.origins = [];
94+
95+
/** @typedef {Map<Module, number>} OrderIndices */
96+
9497
/** Indices in top-down order */
9598
/**
9699
* @private
97-
* @type {Map<Module, number>}
100+
* @type {OrderIndices}
98101
*/
99102
this._modulePreOrderIndices = new Map();
100103
/** Indices in bottom-up order */
101104
/**
102105
* @private
103-
* @type {Map<Module, number>}
106+
* @type {OrderIndices}
104107
*/
105108
this._modulePostOrderIndices = new Map();
106109
/** @type {number | undefined} */

lib/CleanPlugin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ const mergeAssets = (as1, as2) => {
6363
}
6464
};
6565

66+
/** @typedef {Map<string, number>} CurrentAssets */
67+
6668
/**
67-
* @param {Map<string, number>} assets current assets
69+
* @param {CurrentAssets} assets current assets
6870
* @returns {Set<string>} Set of directory paths
6971
*/
7072
function getDirectories(assets) {
@@ -92,12 +94,13 @@ function getDirectories(assets) {
9294
/**
9395
* @param {OutputFileSystem} fs filesystem
9496
* @param {string} outputPath output path
95-
* @param {Map<string, number>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
97+
* @param {CurrentAssets} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
9698
* @param {(err?: Error | null, set?: Diff) => void} callback returns the filenames of the assets that shouldn't be there
9799
* @returns {void}
98100
*/
99101
const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
100102
const directories = getDirectories(currentAssets);
103+
/** @type {Diff} */
101104
const diff = new Set();
102105
asyncLib.forEachLimit(
103106
directories,

lib/Compilation.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,19 @@ const { isSourceEqual } = require("./util/source");
224224
* @property {EntryOptions=} entryOptions
225225
*/
226226

227+
/** @typedef {LazySet<string>} FileSystemDependencies */
228+
227229
/** @typedef {EXPECTED_ANY} ExecuteModuleExports */
228230

229231
/**
230232
* @typedef {object} ExecuteModuleResult
231233
* @property {ExecuteModuleExports} exports
232234
* @property {boolean} cacheable
233-
* @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
234-
* @property {LazySet<string>} fileDependencies
235-
* @property {LazySet<string>} contextDependencies
236-
* @property {LazySet<string>} missingDependencies
237-
* @property {LazySet<string>} buildDependencies
235+
* @property {ExecuteModuleAssets} assets
236+
* @property {FileSystemDependencies} fileDependencies
237+
* @property {FileSystemDependencies} contextDependencies
238+
* @property {FileSystemDependencies} missingDependencies
239+
* @property {FileSystemDependencies} buildDependencies
238240
*/
239241

240242
/**
@@ -261,9 +263,11 @@ const { isSourceEqual } = require("./util/source");
261263
* @property {WebpackRequire} require require function
262264
*/
263265

266+
/** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */
267+
264268
/**
265269
* @typedef {object} ExecuteModuleContext
266-
* @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
270+
* @property {ExecuteModuleAssets} assets
267271
* @property {Chunk} chunk
268272
* @property {ChunkGraph} chunkGraph
269273
* @property {WebpackRequire=} __webpack_require__
@@ -1223,20 +1227,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
12231227
this.emittedAssets = new Set();
12241228
/** @type {Set<string>} */
12251229
this.comparedForEmitAssets = new Set();
1226-
/** @type {LazySet<string>} */
1230+
/** @type {FileSystemDependencies} */
12271231
this.fileDependencies = new LazySet();
1228-
/** @type {LazySet<string>} */
1232+
/** @type {FileSystemDependencies} */
12291233
this.contextDependencies = new LazySet();
1230-
/** @type {LazySet<string>} */
1234+
/** @type {FileSystemDependencies} */
12311235
this.missingDependencies = new LazySet();
1232-
/** @type {LazySet<string>} */
1236+
/** @type {FileSystemDependencies} */
12331237
this.buildDependencies = new LazySet();
12341238
// TODO webpack 6 remove
12351239
this.compilationDependencies = {
12361240
add: util.deprecate(
12371241
/**
12381242
* @param {string} item item
1239-
* @returns {LazySet<string>} file dependencies
1243+
* @returns {FileSystemDependencies} file dependencies
12401244
*/
12411245
(item) => this.fileDependencies.add(item),
12421246
"Compilation.compilationDependencies is deprecated (used Compilation.fileDependencies instead)",

lib/ContextModuleFactory.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ const { cachedSetProperty } = require("./util/cleverMerge");
1515
const { createFakeHook } = require("./util/deprecation");
1616
const { join } = require("./util/fs");
1717

18+
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
19+
/** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
1820
/** @typedef {import("./ContextModule").ContextModuleOptions} ContextModuleOptions */
1921
/** @typedef {import("./ContextModule").ResolveDependenciesCallback} ResolveDependenciesCallback */
2022
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
2123
/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
2224
/** @typedef {import("./ResolverFactory")} ResolverFactory */
2325
/** @typedef {import("./dependencies/ContextDependency")} ContextDependency */
2426
/** @typedef {import("./dependencies/ContextDependency").ContextOptions} ContextOptions */
25-
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
27+
2628
/**
2729
* @template T
2830
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
@@ -36,9 +38,9 @@ const { join } = require("./util/fs");
3638
* @property {string} context
3739
* @property {string} request
3840
* @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
39-
* @property {LazySet<string>} fileDependencies
40-
* @property {LazySet<string>} missingDependencies
41-
* @property {LazySet<string>} contextDependencies
41+
* @property {FileSystemDependencies} fileDependencies
42+
* @property {FileSystemDependencies} missingDependencies
43+
* @property {FileSystemDependencies} contextDependencies
4244
* @property {ContextDependency[]} dependencies
4345
*/
4446

lib/Module.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const makeSerializable = require("./util/makeSerializable");
2828
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
2929
/** @typedef {import("./Compilation")} Compilation */
3030
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
31+
/** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
3132
/** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
3233
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
3334
/** @typedef {import("./Dependency")} Dependency */
@@ -138,8 +139,6 @@ const makeSerializable = require("./util/makeSerializable");
138139
* @property {Map<RuntimeSpec, string>=} exportsSourceByRuntime
139140
*/
140141

141-
/** @typedef {LazySet<string>} FileSystemDependencies */
142-
143142
/**
144143
* @typedef {object} KnownBuildInfo
145144
* @property {boolean=} cacheable

lib/NormalModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ class NormalModule extends Module {
13081308
/** @type {undefined | Set<string>} */
13091309
let nonAbsoluteDependencies;
13101310
/**
1311-
* @param {LazySet<string>} deps deps
1311+
* @param {FileSystemDependencies} deps deps
13121312
*/
13131313
const checkDependencies = (deps) => {
13141314
for (const dep of deps) {

lib/NormalModuleFactory.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const {
3838
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
3939
/** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
4040
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
41+
/** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
4142
/** @typedef {import("./Generator")} Generator */
4243
/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
4344
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
@@ -74,9 +75,9 @@ const {
7475
* @property {ModuleDependency[]} dependencies
7576
* @property {string} dependencyType
7677
* @property {CreateData} createData
77-
* @property {LazySet<string>} fileDependencies
78-
* @property {LazySet<string>} missingDependencies
79-
* @property {LazySet<string>} contextDependencies
78+
* @property {FileSystemDependencies} fileDependencies
79+
* @property {FileSystemDependencies} missingDependencies
80+
* @property {FileSystemDependencies} contextDependencies
8081
* @property {Module=} ignoredModule
8182
* @property {boolean} cacheable allow to use the unsafe cache
8283
*/

lib/Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @property {WebpackOptions} options
2121
*/
2222

23-
/** @typedef {Record<string, EXPECTED_ANY> & ParserStateBase} ParserState */
23+
/** @typedef {ParserStateBase & Record<string, EXPECTED_ANY>} ParserState */
2424

2525
class Parser {
2626
/* istanbul ignore next */

lib/buildChunkGraph.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,12 @@ const visitModules = (
352352
/** @type {Map<ChunkGroupInfo, Set<DependenciesBlock>>} */
353353
const blocksByChunkGroups = new Map();
354354

355-
/** @type {Map<string, ChunkGroupInfo>} */
355+
/** @typedef {Map<string, ChunkGroupInfo>} NamedChunkGroup */
356+
357+
/** @type {NamedChunkGroup} */
356358
const namedChunkGroups = new Map();
357359

358-
/** @type {Map<string, ChunkGroupInfo>} */
360+
/** @type {NamedChunkGroup} */
359361
const namedAsyncEntrypoints = new Map();
360362

361363
/** @type {Set<ChunkGroupInfo>} */

0 commit comments

Comments
 (0)