@@ -66,6 +66,13 @@ const {
6666 * @property {SyncBailHook<[CallExpression, string[]], void> } hotAcceptWithoutCallback
6767 */
6868
69+ /** @typedef {number } HotIndex */
70+ /** @typedef {Record<string, string> } FullHashChunkModuleHashes */
71+ /** @typedef {Record<string, string> } ChunkModuleHashes */
72+ /** @typedef {Record<ChunkId, string> } ChunkHashes */
73+ /** @typedef {Record<ChunkId, string> } ChunkRuntime */
74+ /** @typedef {Record<ChunkId, ModuleId[]> } ChunkModuleIds */
75+
6976/** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo } } HotUpdateMainContentByRuntimeItem */
7077/** @typedef {Map<string, HotUpdateMainContentByRuntimeItem> } HotUpdateMainContentByRuntime */
7178
@@ -344,10 +351,11 @@ class HotModuleReplacementPlugin {
344351 ) ;
345352 // #endregion
346353
354+ /** @type {HotIndex } */
347355 let hotIndex = 0 ;
348- /** @type {Record<string, string> } */
356+ /** @type {FullHashChunkModuleHashes } */
349357 const fullHashChunkModuleHashes = { } ;
350- /** @type {Record<string, string> } */
358+ /** @type {ChunkModuleHashes } */
351359 const chunkModuleHashes = { } ;
352360
353361 compilation . hooks . record . tap ( PLUGIN_NAME , ( compilation , records ) => {
@@ -361,19 +369,20 @@ class HotModuleReplacementPlugin {
361369 records . chunkRuntime = { } ;
362370 for ( const chunk of compilation . chunks ) {
363371 const chunkId = /** @type {ChunkId } */ ( chunk . id ) ;
364- records . chunkHashes [ chunkId ] = chunk . hash ;
372+ records . chunkHashes [ chunkId ] = /** @type { string } */ ( chunk . hash ) ;
365373 records . chunkRuntime [ chunkId ] = getRuntimeKey ( chunk . runtime ) ;
366374 }
367375 records . chunkModuleIds = { } ;
368376 for ( const chunk of compilation . chunks ) {
369- records . chunkModuleIds [ /** @type {ChunkId } */ ( chunk . id ) ] =
370- Array . from (
371- chunkGraph . getOrderedChunkModulesIterable (
372- chunk ,
373- compareModulesById ( chunkGraph )
374- ) ,
375- m => chunkGraph . getModuleId ( m )
376- ) ;
377+ const chunkId = /** @type {ChunkId } */ ( chunk . id ) ;
378+
379+ records . chunkModuleIds [ chunkId ] = Array . from (
380+ chunkGraph . getOrderedChunkModulesIterable (
381+ chunk ,
382+ compareModulesById ( chunkGraph )
383+ ) ,
384+ m => /** @type {ModuleId } */ ( chunkGraph . getModuleId ( m ) )
385+ ) ;
377386 }
378387 } ) ;
379388 /** @type {TupleSet<Module, Chunk> } */
@@ -418,10 +427,14 @@ class HotModuleReplacementPlugin {
418427 const hash = getModuleHash ( module ) ;
419428 if (
420429 fullHashModulesInThisChunk . has (
421- /** @type {RuntimeModule } */ ( module )
430+ /** @type {RuntimeModule } */
431+ ( module )
422432 )
423433 ) {
424- if ( records . fullHashChunkModuleHashes [ key ] !== hash ) {
434+ if (
435+ /** @type {FullHashChunkModuleHashes } */
436+ ( records . fullHashChunkModuleHashes ) [ key ] !== hash
437+ ) {
425438 updatedModules . add ( module , chunk ) ;
426439 }
427440 fullHashChunkModuleHashes [ key ] = hash ;
@@ -504,8 +517,11 @@ class HotModuleReplacementPlugin {
504517 /** @type {HotUpdateMainContentByRuntime } */
505518 const hotUpdateMainContentByRuntime = new Map ( ) ;
506519 let allOldRuntime ;
507- for ( const key of Object . keys ( records . chunkRuntime ) ) {
508- const runtime = keyToRuntime ( records . chunkRuntime [ key ] ) ;
520+ const chunkRuntime =
521+ /** @type {ChunkRuntime } */
522+ ( records . chunkRuntime ) ;
523+ for ( const key of Object . keys ( chunkRuntime ) ) {
524+ const runtime = keyToRuntime ( chunkRuntime [ key ] ) ;
509525 allOldRuntime = mergeRuntimeOwned ( allOldRuntime , runtime ) ;
510526 }
511527 forEachRuntime ( allOldRuntime , runtime => {
@@ -532,7 +548,7 @@ class HotModuleReplacementPlugin {
532548 if ( hotUpdateMainContentByRuntime . size === 0 ) return ;
533549
534550 // Create a list of all active modules to verify which modules are removed completely
535- /** @type {Map<number| string, Module> } */
551+ /** @type {Map<number | string, Module> } */
536552 const allModules = new Map ( ) ;
537553 for ( const module of compilation . modules ) {
538554 const id =
@@ -546,7 +562,10 @@ class HotModuleReplacementPlugin {
546562 const completelyRemovedModules = new Set ( ) ;
547563
548564 for ( const key of Object . keys ( records . chunkHashes ) ) {
549- const oldRuntime = keyToRuntime ( records . chunkRuntime [ key ] ) ;
565+ const oldRuntime = keyToRuntime (
566+ /** @type {ChunkRuntime } */
567+ ( records . chunkRuntime ) [ key ]
568+ ) ;
550569 /** @type {Module[] } */
551570 const remainingModules = [ ] ;
552571 // Check which modules are removed
@@ -706,8 +725,8 @@ class HotModuleReplacementPlugin {
706725 }
707726 const renderManifest = compilation . getRenderManifest ( {
708727 chunk : hotUpdateChunk ,
709- hash : records . hash ,
710- fullHash : records . hash ,
728+ hash : /** @type { string } */ ( records . hash ) ,
729+ fullHash : /** @type { string } */ ( records . hash ) ,
711730 outputOptions : compilation . outputOptions ,
712731 moduleTemplates : compilation . moduleTemplates ,
713732 dependencyTemplates : compilation . dependencyTemplates ,
0 commit comments