@@ -19,34 +19,38 @@ const ERR_CHUNK_INITIAL =
19
19
/** @typedef {import("webpack-sources").Source } Source */
20
20
21
21
/**
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
24
24
*/
25
25
26
26
/**
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
29
31
*/
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
+ } ;
34
37
35
38
/**
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
38
42
* @returns {-1|0|1 } sort value
39
43
*/
40
- const sortById = ( a , b ) => {
44
+ const sortChunkGroupById = ( a , b ) => {
41
45
if ( a . id < b . id ) return - 1 ;
42
46
if ( b . id < a . id ) return 1 ;
43
47
return 0 ;
44
48
} ;
45
49
46
50
/**
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
50
54
* @returns {-1|0|1 } The order number of the sort
51
55
*/
52
56
const sortByIdentifier = ( a , b ) => {
@@ -70,13 +74,13 @@ const getModulesIdent = set => {
70
74
71
75
/**
72
76
* @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
74
78
* @returns {Array<T> } the array returned from Array.from(set)
75
79
*/
76
80
const getArray = set => Array . from ( set ) ;
77
81
78
82
/**
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
80
84
* @returns {number } the size of the modules
81
85
*/
82
86
const getModulesSize = set => {
@@ -108,12 +112,10 @@ class Chunk {
108
112
this . preventIntegration = false ;
109
113
/** @type {Module= } */
110
114
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> } */
114
116
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 ) ;
117
119
/** @type {Source[] } */
118
120
this . files = [ ] ;
119
121
/** @type {boolean } */
@@ -498,14 +500,14 @@ class Chunk {
498
500
}
499
501
500
502
/**
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
502
504
* @returns {void }
503
505
*/
504
506
sortModules ( sortByFn ) {
505
- this . _modules . sortWith ( sortByFn || sortById ) ;
507
+ this . _modules . sortWith ( sortByFn || sortModuleById ) ;
506
508
}
507
509
508
- sortItems ( sortChunks ) {
510
+ sortItems ( ) {
509
511
this . sortModules ( ) ;
510
512
}
511
513
@@ -661,8 +663,8 @@ class Chunk {
661
663
662
664
/**
663
665
*
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
666
668
* @returns {boolean } return true if module exists in graph
667
669
*/
668
670
hasModuleInGraph ( filterFn , filterChunkFn ) {
0 commit comments