@@ -99,8 +99,8 @@ const INVALID = Symbol("invalid");
9999 * @typedef {Object } SnapshotOptimizationEntry
100100 * @property {Snapshot } snapshot
101101 * @property {number } shared
102- * @property {Set<string> } snapshotContent
103- * @property {Set<SnapshotOptimizationEntry> } children
102+ * @property {Set<string> | undefined } snapshotContent
103+ * @property {Set<SnapshotOptimizationEntry> | undefined } children
104104 */
105105
106106/**
@@ -115,6 +115,12 @@ const INVALID = Symbol("invalid");
115115 * @property {Set<string> } resolveDependencies.missing list of missing entries
116116 */
117117
118+ /**
119+ * @typedef {Object } SnapshotOptions
120+ * @property {boolean= } hash should use hash to snapshot
121+ * @property {boolean= } timestamp should use timestamp to snapshot
122+ */
123+
118124const DONE_ITERATOR_RESULT = new Set ( ) . keys ( ) . next ( ) ;
119125
120126// cspell:word tshs
@@ -137,7 +143,7 @@ class SnapshotIterable {
137143 let state = 0 ;
138144 /** @type {IterableIterator<string> } */
139145 let it ;
140- /** @type {(Snapshot) => (Map<string, any> | Set<string>)[] } */
146+ /** @type {(snapshot: Snapshot) => (Map<string, any> | Set<string>)[] } */
141147 let getMaps ;
142148 /** @type {(Map<string, any> | Set<string>)[] } */
143149 let maps ;
@@ -552,7 +558,7 @@ class SnapshotOptimization {
552558 }
553559 } ;
554560
555- /** @type {SnapshotOptimizationEntry } */
561+ /** @type {SnapshotOptimizationEntry | undefined } */
556562 let newOptimizationEntry = undefined ;
557563
558564 const capturedFilesSize = capturedFiles . size ;
@@ -757,10 +763,9 @@ const mergeMaps = (a, b) => {
757763
758764/**
759765 * @template T
760- * @template K
761- * @param {Set<T, K> } a source map
762- * @param {Set<T, K> } b joining map
763- * @returns {Set<T, K> } joined map
766+ * @param {Set<T> } a source map
767+ * @param {Set<T> } b joining map
768+ * @returns {Set<T> } joined map
764769 */
765770const mergeSets = ( a , b ) => {
766771 if ( ! b || b . size === 0 ) return a ;
@@ -858,8 +863,8 @@ const getManagedItem = (managedPath, path) => {
858863
859864/**
860865 * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
861- * @param {T } entry entry
862- * @returns {T["resolved"] | undefined } the resolved entry
866+ * @param {T | null } entry entry
867+ * @returns {T["resolved"] | null | undefined } the resolved entry
863868 */
864869const getResolvedTimestamp = entry => {
865870 if ( entry === null ) return null ;
@@ -868,15 +873,20 @@ const getResolvedTimestamp = entry => {
868873} ;
869874
870875/**
871- * @param {ContextHash } entry entry
872- * @returns {string | undefined } the resolved entry
876+ * @param {ContextHash | null } entry entry
877+ * @returns {string | null | undefined } the resolved entry
873878 */
874879const getResolvedHash = entry => {
875880 if ( entry === null ) return null ;
876881 if ( entry . resolved !== undefined ) return entry . resolved ;
877882 return entry . symlinks === undefined ? entry . hash : undefined ;
878883} ;
879884
885+ /**
886+ * @template T
887+ * @param {Set<T> } source source
888+ * @param {Set<T> } target target
889+ */
880890const addAll = ( source , target ) => {
881891 for ( const key of source ) target . add ( key ) ;
882892} ;
@@ -1145,6 +1155,11 @@ class FileSystemInfo {
11451155 ) ;
11461156 }
11471157
1158+ /**
1159+ * @param {string } path path
1160+ * @param {string } reason reason
1161+ * @param {any[] } args arguments
1162+ */
11481163 _log ( path , reason , ...args ) {
11491164 const key = path + reason ;
11501165 if ( this . _loggedPaths . has ( key ) ) return ;
@@ -1258,7 +1273,7 @@ class FileSystemInfo {
12581273
12591274 /**
12601275 * @param {string } path file path
1261- * @param {function((WebpackError | null)=, string=): void } callback callback function
1276+ * @param {function((WebpackError | null)=, ( string | null) =): void } callback callback function
12621277 * @returns {void }
12631278 */
12641279 getFileHash ( path , callback ) {
@@ -1289,7 +1304,7 @@ class FileSystemInfo {
12891304
12901305 /**
12911306 * @param {string } path context path
1292- * @param {function((WebpackError | null)=, ContextHash=): void } callback callback function
1307+ * @param {function((WebpackError | null)=, ( ContextHash | null) =): void } callback callback function
12931308 * @returns {void }
12941309 */
12951310 _getUnresolvedContextHash ( path , callback ) {
@@ -1320,7 +1335,7 @@ class FileSystemInfo {
13201335
13211336 /**
13221337 * @param {string } path context path
1323- * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void } callback callback function
1338+ * @param {function((WebpackError | null)=, ( ContextTimestampAndHash | null) =): void } callback callback function
13241339 * @returns {void }
13251340 */
13261341 _getUnresolvedContextTsh ( path , callback ) {
@@ -1383,14 +1398,18 @@ class FileSystemInfo {
13831398 const resolveDirectories = new Set ( ) ;
13841399 /** @type {Set<string> } */
13851400 const resolveMissing = new Set ( ) ;
1386- /** @type {Map<string, string | false> } */
1401+ /** @type {Map<string, string | false | undefined > } */
13871402 const resolveResults = new Map ( ) ;
13881403 const invalidResolveResults = new Set ( ) ;
13891404 const resolverContext = {
13901405 fileDependencies : resolveFiles ,
13911406 contextDependencies : resolveDirectories ,
13921407 missingDependencies : resolveMissing
13931408 } ;
1409+ /**
1410+ * @param {string } expected expected result
1411+ * @returns {string } expected result
1412+ */
13941413 const expectedToString = expected => {
13951414 return expected ? ` (expected ${ expected } )` : "" ;
13961415 } ;
@@ -1610,7 +1629,7 @@ class FileSystemInfo {
16101629 break ;
16111630 }
16121631 // Check commonjs cache for the module
1613- /** @type {NodeModule } */
1632+ /** @type {NodeModule | undefined } */
16141633 const module = require . cache [ path ] ;
16151634 if ( module && Array . isArray ( module . children ) ) {
16161635 children: for ( const child of module . children ) {
@@ -1910,13 +1929,11 @@ class FileSystemInfo {
19101929
19111930 /**
19121931 *
1913- * @param {number } startTime when processing the files has started
1932+ * @param {number | null | undefined } startTime when processing the files has started
19141933 * @param {Iterable<string> } files all files
19151934 * @param {Iterable<string> } directories all directories
19161935 * @param {Iterable<string> } missing all missing files or directories
1917- * @param {Object } options options object (for future extensions)
1918- * @param {boolean= } options.hash should use hash to snapshot
1919- * @param {boolean= } options.timestamp should use timestamp to snapshot
1936+ * @param {SnapshotOptions | null | undefined } options options object (for future extensions)
19201937 * @param {function((WebpackError | null)=, (Snapshot | null)=): void } callback callback function
19211938 * @returns {void }
19221939 */
@@ -2053,6 +2070,9 @@ class FileSystemInfo {
20532070 }
20542071 return capturedItems ;
20552072 } ;
2073+ /**
2074+ * @param {Set<string> } capturedFiles captured files
2075+ */
20562076 const processCapturedFiles = capturedFiles => {
20572077 switch ( mode ) {
20582078 case 3 :
@@ -2639,6 +2659,10 @@ class FileSystemInfo {
26392659 }
26402660 }
26412661 }
2662+ /**
2663+ * @param {string } path file path
2664+ * @param {string } hash hash
2665+ */
26422666 const processFileHashSnapshot = ( path , hash ) => {
26432667 const cache = this . _fileHashes . get ( path ) ;
26442668 if ( cache !== undefined ) {
@@ -2921,7 +2945,7 @@ class FileSystemInfo {
29212945
29222946 const hash = createHash ( this . _hashFunction ) ;
29232947
2924- hash . update ( content ) ;
2948+ hash . update ( /** @type { string | Buffer } */ ( content ) ) ;
29252949
29262950 const digest = /** @type {string } */ ( hash . digest ( "hex" ) ) ;
29272951
@@ -2985,7 +3009,7 @@ class FileSystemInfo {
29853009 * @param {function(string, IStats, function(Error=, ItemType=): void): void } options.fromFile called when context item is a file
29863010 * @param {function(string, IStats, function(Error=, ItemType=): void): void } options.fromDirectory called when context item is a directory
29873011 * @param {function(string[], ItemType[]): T } options.reduce called from all context items
2988- * @param {function((Error | null)=, (T)=): void } callback callback
3012+ * @param {function((Error | null)=, (T | null )=): void } callback callback
29893013 */
29903014 _readContext (
29913015 {
@@ -3172,6 +3196,7 @@ class FileSystemInfo {
31723196 * @returns {void }
31733197 */
31743198 _resolveContextTimestamp ( entry , callback ) {
3199+ /** @type {string[] } */
31753200 const hashes = [ ] ;
31763201 let safeTime = 0 ;
31773202 processAsyncTree (
@@ -3280,6 +3305,7 @@ class FileSystemInfo {
32803305 * @returns {void }
32813306 */
32823307 _resolveContextHash ( entry , callback ) {
3308+ /** @type {string[] } */
32833309 const hashes = [ ] ;
32843310 processAsyncTree (
32853311 entry . symlinks ,
@@ -3436,7 +3462,9 @@ class FileSystemInfo {
34363462 * @returns {void }
34373463 */
34383464 _resolveContextTsh ( entry , callback ) {
3465+ /** @type {string[] } */
34393466 const hashes = [ ] ;
3467+ /** @type {string[] } */
34403468 const tsHashes = [ ] ;
34413469 let safeTime = 0 ;
34423470 processAsyncTree (
@@ -3554,7 +3582,7 @@ class FileSystemInfo {
35543582 }
35553583 let data ;
35563584 try {
3557- data = JSON . parse ( content . toString ( "utf-8" ) ) ;
3585+ data = JSON . parse ( /** @type { Buffer } */ ( content ) . toString ( "utf-8" ) ) ;
35583586 } catch ( e ) {
35593587 return callback ( e ) ;
35603588 }
0 commit comments