Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2b0f9b

Browse files
fix: ts types
1 parent cb6ffaf commit a2b0f9b

21 files changed

+419
-202
lines changed

lib/BannerPlugin.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const createSchemaValidation = require("./util/create-schema-validation");
1414
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */
1515
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
1616
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
17+
/** @typedef {import("./Compilation").PathData} PathData */
1718
/** @typedef {import("./Compiler")} Compiler */
19+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
1820

1921
const validate = createSchemaValidation(
2022
require("../schemas/plugins/BannerPlugin.check.js"),
@@ -59,13 +61,15 @@ class BannerPlugin {
5961
const bannerOption = options.banner;
6062
if (typeof bannerOption === "function") {
6163
const getBanner = bannerOption;
64+
/** @type {BannerFunction} */
6265
this.banner = this.options.raw
6366
? getBanner
6467
: /** @type {BannerFunction} */ data => wrapComment(getBanner(data));
6568
} else {
6669
const banner = this.options.raw
6770
? bannerOption
6871
: wrapComment(bannerOption);
72+
/** @type {BannerFunction} */
6973
this.banner = () => banner;
7074
}
7175
}
@@ -103,12 +107,14 @@ class BannerPlugin {
103107
continue;
104108
}
105109

106-
const data = {
107-
chunk,
108-
filename: file
109-
};
110+
/** @type {PathData} */
111+
const data = { chunk, filename: file };
110112

111-
const comment = compilation.getPath(banner, data);
113+
const comment = compilation.getPath(
114+
/** @type {TemplatePath} */
115+
(banner),
116+
data
117+
);
112118

113119
compilation.updateAsset(file, old => {
114120
const cached = cache.get(old);

lib/ChunkGraph.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,12 @@ class ChunkGraph {
10161016
this.getChunkEntryModulesWithChunkGroupIterable(chunkB)
10171017
)) {
10181018
this.disconnectChunkAndEntryModule(chunkB, module);
1019-
this.connectChunkAndEntryModule(chunkA, module, chunkGroup);
1019+
this.connectChunkAndEntryModule(
1020+
chunkA,
1021+
module,
1022+
/** @type {Entrypoint} */
1023+
(chunkGroup)
1024+
);
10201025
}
10211026

10221027
for (const chunkGroup of chunkB.groupsIterable) {
@@ -1057,7 +1062,7 @@ class ChunkGraph {
10571062
/**
10581063
* @param {Chunk} chunk the new chunk
10591064
* @param {Module} module the entry module
1060-
* @param {Entrypoint=} entrypoint the chunk group which must be loaded before the module is executed
1065+
* @param {Entrypoint} entrypoint the chunk group which must be loaded before the module is executed
10611066
* @returns {void}
10621067
*/
10631068
connectChunkAndEntryModule(chunk, module, entrypoint) {

lib/Compilation.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const { isSourceEqual } = require("./util/source");
9494
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
9595
/** @typedef {import("./Cache")} Cache */
9696
/** @typedef {import("./CacheFacade")} CacheFacade */
97+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
9798
/** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
9899
/** @typedef {import("./Compiler")} Compiler */
99100
/** @typedef {import("./Compiler").CompilationParams} CompilationParams */
@@ -134,7 +135,7 @@ const { isSourceEqual } = require("./util/source");
134135
/**
135136
* @callback ModuleCallback
136137
* @param {(WebpackError | null)=} err
137-
* @param {Module=} result
138+
* @param {(Module | null)=} result
138139
* @returns {void}
139140
*/
140141

@@ -247,7 +248,7 @@ const { isSourceEqual } = require("./util/source");
247248
/**
248249
* @typedef {object} LogEntry
249250
* @property {string} type
250-
* @property {any[]} args
251+
* @property {any[]=} args
251252
* @property {number} time
252253
* @property {string[]=} trace
253254
*/
@@ -1055,6 +1056,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
10551056
this.dependencyTemplates = new DependencyTemplates(
10561057
this.outputOptions.hashFunction
10571058
);
1059+
/** @type {Record<string, number>} */
10581060
this.childrenCounters = {};
10591061
/** @type {Set<number|string>} */
10601062
this.usedChunkIds = null;
@@ -1222,7 +1224,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
12221224
logEntry.type === LogType.profileEnd &&
12231225
typeof console.profileEnd === "function"
12241226
) {
1225-
console.profileEnd(`[${name}] ${logEntry.args[0]}`);
1227+
console.profileEnd(
1228+
`[${name}] ${/** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]}`
1229+
);
12261230
}
12271231
if (logEntries === undefined) {
12281232
logEntries = this.logging.get(name);
@@ -1236,7 +1240,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
12361240
logEntry.type === LogType.profile &&
12371241
typeof console.profile === "function"
12381242
) {
1239-
console.profile(`[${name}] ${logEntry.args[0]}`);
1243+
console.profile(
1244+
`[${name}] ${/** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]}`
1245+
);
12401246
}
12411247
}
12421248
},
@@ -2979,11 +2985,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
29792985

29802986
this.assignDepths(entryModules);
29812987

2988+
/**
2989+
* @param {Dependency[]} deps deps
2990+
* @returns {Module[]} sorted deps
2991+
*/
29822992
const mapAndSort = deps =>
2983-
deps
2984-
.map(dep => this.moduleGraph.getModule(dep))
2985-
.filter(Boolean)
2986-
.sort(compareModulesByIdentifier);
2993+
/** @type {Module[]} */
2994+
(deps.map(dep => this.moduleGraph.getModule(dep)).filter(Boolean)).sort(
2995+
compareModulesByIdentifier
2996+
);
29872997
const includedModules = [
29882998
...mapAndSort(this.globalEntry.includeDependencies),
29892999
...mapAndSort(includeDependencies)
@@ -3355,7 +3365,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
33553365
let delayedModules = new Set();
33563366
asyncLib.eachLimit(
33573367
jobs,
3358-
this.options.parallelism,
3368+
/** @type {number} */
3369+
(this.options.parallelism),
33593370
(job, callback) => {
33603371
const { module } = job;
33613372
const { codeGenerationDependencies } = module;
@@ -3734,13 +3745,24 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
37343745
if (chunkGroup !== undefined) {
37353746
chunkGroup.addOptions(groupOptions);
37363747
if (module) {
3737-
chunkGroup.addOrigin(module, loc, request);
3748+
chunkGroup.addOrigin(
3749+
module,
3750+
/** @type {DependencyLocation} */
3751+
(loc),
3752+
request
3753+
);
37383754
}
37393755
return chunkGroup;
37403756
}
37413757
}
37423758
const chunkGroup = new ChunkGroup(groupOptions);
3743-
if (module) chunkGroup.addOrigin(module, loc, request);
3759+
if (module)
3760+
chunkGroup.addOrigin(
3761+
module,
3762+
/** @type {DependencyLocation} */
3763+
(loc),
3764+
request
3765+
);
37443766
const chunk = this.addChunk(name);
37453767

37463768
connectChunkGroupAndChunk(chunkGroup, chunk);
@@ -4400,9 +4422,9 @@ This prevents using hashes of each other and should be avoided.`);
44004422
const chunkHash = createHash(hashFunction);
44014423
chunkHash.update(chunk.hash);
44024424
chunkHash.update(this.hash);
4403-
const chunkHashDigest = /** @type {string} */ (
4404-
chunkHash.digest(hashDigest)
4405-
);
4425+
const chunkHashDigest =
4426+
/** @type {string} */
4427+
(chunkHash.digest(hashDigest));
44064428
chunk.hash = chunkHashDigest;
44074429
chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
44084430
this.hooks.contentHash.call(chunk);
@@ -4861,7 +4883,7 @@ This prevents using hashes of each other and should be avoided.`);
48614883
}
48624884
} catch (err) {
48634885
if (!inTry) throw err;
4864-
errorAndCallback(err);
4886+
errorAndCallback(/** @type {Error} */ (err));
48654887
}
48664888
});
48674889
},
@@ -5001,7 +5023,7 @@ This prevents using hashes of each other and should be avoided.`);
50015023
const runtimeTemplate = this.runtimeTemplate;
50025024

50035025
const chunk = new Chunk("build time chunk", this._backCompat);
5004-
chunk.id = chunk.name;
5026+
chunk.id = /** @type {ChunkId} */ (chunk.name);
50055027
chunk.ids = [chunk.id];
50065028
chunk.runtime = runtime;
50075029

lib/ContextReplacementPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ContextReplacementPlugin {
1616
* @param {RegExp} resourceRegExp A regular expression that determines which files will be selected
1717
* @param {TODO=} newContentResource A new resource to replace the match
1818
* @param {TODO=} newContentRecursive If true, all subdirectories are searched for matches
19-
* @param {TODO=} newContentRegExp A regular expression that determines which files will be selected
19+
* @param {RegExp=} newContentRegExp A regular expression that determines which files will be selected
2020
*/
2121
constructor(
2222
resourceRegExp,

lib/Dependency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const memoize = require("./util/memoize");
6767
* @typedef {object} ExportsSpec
6868
* @property {(string | ExportSpec)[] | true | null} exports exported names, true for unknown exports or null for no exports
6969
* @property {Set<string>=} excludeExports when exports = true, list of unaffected exports
70-
* @property {Set<string>=} hideExports list of maybe prior exposed, but now hidden exports
70+
* @property {(Set<string> | null)=} hideExports list of maybe prior exposed, but now hidden exports
7171
* @property {ModuleGraphConnection=} from when reexported: from which module
7272
* @property {number=} priority when reexported: with which priority
7373
* @property {boolean=} canMangle can the export be renamed (defaults to true)

0 commit comments

Comments
 (0)