Skip to content

Commit 16660c1

Browse files
authored
Merge pull request #17272 from webpack/more-types
refactor(types): more
2 parents 6d8d96b + 1df0148 commit 16660c1

35 files changed

Lines changed: 283 additions & 128 deletions

lib/ContextModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
8080

8181
/**
8282
* @param {ModuleFactoryCreateData} data data object
83-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
83+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
8484
* @returns {void}
8585
*/
8686
create(data, callback) {

lib/DllModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DllModuleFactory extends ModuleFactory {
1919
}
2020
/**
2121
* @param {ModuleFactoryCreateData} data data object
22-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
22+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
2323
* @returns {void}
2424
*/
2525
create(data, callback) {

lib/HookWebpackError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const tryRunOrWebpackError = (fn, hook) => {
8585
if (err instanceof WebpackError) {
8686
throw err;
8787
}
88-
throw new HookWebpackError(err, hook);
88+
throw new HookWebpackError(/** @type {Error} */ (err), hook);
8989
}
9090
return r;
9191
};

lib/IgnoreErrorModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IgnoreErrorModuleFactory extends ModuleFactory {
2626

2727
/**
2828
* @param {ModuleFactoryCreateData} data data object
29-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
29+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
3030
* @returns {void}
3131
*/
3232
create(data, callback) {

lib/Module.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ const deprecatedNeedRebuild = util.deprecate(
130130

131131
class Module extends DependenciesBlock {
132132
/**
133-
* @param {ModuleTypes} type the module type, when deserializing the type is not known and is an empty string
134-
* @param {string=} context an optional context
135-
* @param {string=} layer an optional layer in which the module is
133+
* @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
134+
* @param {(string | null)=} context an optional context
135+
* @param {(string | null)=} layer an optional layer in which the module is
136136
*/
137137
constructor(type, context = null, layer = null) {
138138
super();
@@ -151,7 +151,7 @@ class Module extends DependenciesBlock {
151151
this.debugId = debugId++;
152152

153153
// Info from Factory
154-
/** @type {ResolveOptions} */
154+
/** @type {ResolveOptions | undefined} */
155155
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
156156
/** @type {object | undefined} */
157157
this.factoryMeta = undefined;
@@ -167,9 +167,9 @@ class Module extends DependenciesBlock {
167167
this._warnings = undefined;
168168
/** @type {WebpackError[] | undefined} */
169169
this._errors = undefined;
170-
/** @type {BuildMeta} */
170+
/** @type {BuildMeta | undefined} */
171171
this.buildMeta = undefined;
172-
/** @type {Record<string, any>} */
172+
/** @type {Record<string, any> | undefined} */
173173
this.buildInfo = undefined;
174174
/** @type {Dependency[] | undefined} */
175175
this.presentationalDependencies = undefined;
@@ -331,6 +331,10 @@ class Module extends DependenciesBlock {
331331
);
332332
}
333333

334+
/**
335+
* @param {Chunk} chunk the chunk
336+
* @returns {boolean} true, when the module was added
337+
*/
334338
addChunk(chunk) {
335339
const chunkGraph = ChunkGraph.getChunkGraphForModule(
336340
this,
@@ -342,6 +346,10 @@ class Module extends DependenciesBlock {
342346
return true;
343347
}
344348

349+
/**
350+
* @param {Chunk} chunk the chunk
351+
* @returns {void}
352+
*/
345353
removeChunk(chunk) {
346354
return ChunkGraph.getChunkGraphForModule(
347355
this,
@@ -350,6 +358,10 @@ class Module extends DependenciesBlock {
350358
).disconnectChunkAndModule(chunk, this);
351359
}
352360

361+
/**
362+
* @param {Chunk} chunk the chunk
363+
* @returns {boolean} true, when the module is in the chunk
364+
*/
353365
isInChunk(chunk) {
354366
return ChunkGraph.getChunkGraphForModule(
355367
this,
@@ -435,7 +447,7 @@ class Module extends DependenciesBlock {
435447
case "namespace":
436448
return "namespace";
437449
case "default":
438-
switch (this.buildMeta.defaultObject) {
450+
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
439451
case "redirect":
440452
return "default-with-named";
441453
case "redirect-warn":
@@ -447,7 +459,7 @@ class Module extends DependenciesBlock {
447459
if (strict) return "default-with-named";
448460
// Try to figure out value of __esModule by following reexports
449461
const handleDefault = () => {
450-
switch (this.buildMeta.defaultObject) {
462+
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
451463
case "redirect":
452464
case "redirect-warn":
453465
return "default-with-named";
@@ -664,7 +676,7 @@ class Module extends DependenciesBlock {
664676
] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
665677
if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
666678
for (const originChunk of chunkGraph.getModuleChunksIterable(
667-
fromModule
679+
/** @type {Module} */ (fromModule)
668680
)) {
669681
// return true if module this is not reachable from originChunk when ignoring chunk
670682
if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))

lib/ModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ModuleFactory {
3838
/**
3939
* @abstract
4040
* @param {ModuleFactoryCreateData} data data object
41-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
41+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
4242
* @returns {void}
4343
*/
4444
create(data, callback) {

lib/NormalModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ class NormalModuleFactory extends ModuleFactory {
753753

754754
/**
755755
* @param {ModuleFactoryCreateData} data data object
756-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
756+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
757757
* @returns {void}
758758
*/
759759
create(data, callback) {

lib/NullFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ModuleFactory = require("./ModuleFactory");
1313
class NullFactory extends ModuleFactory {
1414
/**
1515
* @param {ModuleFactoryCreateData} data data object
16-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
16+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
1717
* @returns {void}
1818
*/
1919
create(data, callback) {

lib/container/ContainerEntryModule.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ class ContainerEntryModule extends Module {
273273
super.serialize(context);
274274
}
275275

276+
/**
277+
* @param {ObjectDeserializerContext} context context
278+
* @returns {ContainerEntryModule} deserialized container entry module
279+
*/
276280
static deserialize(context) {
277281
const { read } = context;
278282
const obj = new ContainerEntryModule(read(), read(), read());

lib/container/ContainerEntryModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ContainerEntryModule = require("./ContainerEntryModule");
1515
module.exports = class ContainerEntryModuleFactory extends ModuleFactory {
1616
/**
1717
* @param {ModuleFactoryCreateData} data data object
18-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
18+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
1919
* @returns {void}
2020
*/
2121
create({ dependencies: [dependency] }, callback) {

0 commit comments

Comments
 (0)