@@ -19,34 +19,38 @@ const ERR_CHUNK_INITIAL =
1919/** @typedef {import("webpack-sources").Source } Source */
2020
2121/**
22- * @typedef {Object } Identifiable an object who contains an identifier function property
23- * @property {() => string } identifier the resource or unique identifier of something
22+ * @typedef {Object } WithId an object who has an id property *
23+ * @property {string | number } id the id of the object
2424 */
2525
2626/**
27- * @typedef {Object } WithId an object who has an id property
28- * @property {string } id the id of the object
27+ * Compare two Modules based on their ids for sorting
28+ * @param {Module } a module
29+ * @param {Module } b module
30+ * @returns {-1|0|1 } sort value
2931 */
30-
31- /** @typedef {(a: Module, b: Module) => -1|0|1 } ModuleSortPredicate */
32- /** @typedef {(m: Module) => boolean } ModuleFilterPredicate */
33- /** @typedef {(c: Chunk) => boolean } ChunkFilterPredicate */
32+ const sortModuleById = ( a , b ) => {
33+ if ( a . id < b . id ) return - 1 ;
34+ if ( b . id < a . id ) return 1 ;
35+ return 0 ;
36+ } ;
3437
3538/**
36- * @param {WithId } a object that contains an ID property
37- * @param {WithId } b object that contains an ID property
39+ * Compare two ChunkGroups based on their ids for sorting
40+ * @param {ChunkGroup } a chunk group
41+ * @param {ChunkGroup } b chunk group
3842 * @returns {-1|0|1 } sort value
3943 */
40- const sortById = ( a , b ) => {
44+ const sortChunkGroupById = ( a , b ) => {
4145 if ( a . id < b . id ) return - 1 ;
4246 if ( b . id < a . id ) return 1 ;
4347 return 0 ;
4448} ;
4549
4650/**
47- *
48- * @param {Identifiable } a first object with ident fn
49- * @param {Identifiable } b second object with ident fn
51+ * Compare two Identifiables , based on their ids for sorting
52+ * @param {Module } a first object with ident fn
53+ * @param {Module } b second object with ident fn
5054 * @returns {-1|0|1 } The order number of the sort
5155 */
5256const sortByIdentifier = ( a , b ) => {
@@ -70,13 +74,13 @@ const getModulesIdent = set => {
7074
7175/**
7276 * @template T
73- * @param {Set <T> } set the set to convert to array
77+ * @param {SortableSet <T> } set the sortable set to convert to array
7478 * @returns {Array<T> } the array returned from Array.from(set)
7579 */
7680const getArray = set => Array . from ( set ) ;
7781
7882/**
79- * @param {Set <Module> } set the Set to get the count/size of
83+ * @param {SortableSet <Module> } set the sortable Set to get the count/size of
8084 * @returns {number } the size of the modules
8185 */
8286const getModulesSize = set => {
@@ -108,12 +112,10 @@ class Chunk {
108112 this . preventIntegration = false ;
109113 /** @type {Module= } */
110114 this . entryModule = undefined ;
111- //TODO make these typed generics for Module[] and ChunkGroup[] and their sort being (T, T): => 1,-1,0
112- //See https://github.com/webpack/webpack/pull/7046
113- /** @private */
115+ /** @private @type {SortableSet<Module> } */
114116 this . _modules = new SortableSet ( undefined , sortByIdentifier ) ;
115- /** @private */
116- this . _groups = new SortableSet ( undefined , sortById ) ;
117+ /** @private @type { SortableSet<ChunkGroup> } */
118+ this . _groups = new SortableSet ( undefined , sortChunkGroupById ) ;
117119 /** @type {Source[] } */
118120 this . files = [ ] ;
119121 /** @type {boolean } */
@@ -498,14 +500,14 @@ class Chunk {
498500 }
499501
500502 /**
501- * @param {ModuleSortPredicate = } sortByFn a predicate function used to sort modules
503+ * @param {function(Module, Module): -1|0|1 = } sortByFn a predicate function used to sort modules
502504 * @returns {void }
503505 */
504506 sortModules ( sortByFn ) {
505- this . _modules . sortWith ( sortByFn || sortById ) ;
507+ this . _modules . sortWith ( sortByFn || sortModuleById ) ;
506508 }
507509
508- sortItems ( sortChunks ) {
510+ sortItems ( ) {
509511 this . sortModules ( ) ;
510512 }
511513
@@ -661,8 +663,8 @@ class Chunk {
661663
662664 /**
663665 *
664- * @param {ModuleFilterPredicate } filterFn predicate function used to filter modules
665- * @param {ChunkFilterPredicate } filterChunkFn predicate function used to filter chunks
666+ * @param {function(Module): boolean } filterFn predicate function used to filter modules
667+ * @param {function(Chunk): boolean } filterChunkFn predicate function used to filter chunks
666668 * @returns {boolean } return true if module exists in graph
667669 */
668670 hasModuleInGraph ( filterFn , filterChunkFn ) {
0 commit comments