@@ -1007,45 +1007,44 @@ class Compilation extends Tapable {
1007
1007
}
1008
1008
1009
1009
assignDepth ( module ) {
1010
- const assignDepthToModule = ( module , depth ) => {
1011
- // enter module
1012
- if ( typeof module . depth === "number" && module . depth <= depth ) return ;
1013
- module . depth = depth ;
1010
+ const queue = new Set ( [ module ] ) ;
1011
+ let depth ;
1014
1012
1015
- // enter it as block
1016
- assignDepthToDependencyBlock ( module , depth + 1 ) ;
1013
+ module . depth = 0 ;
1014
+
1015
+ const enqueueJob = module => {
1016
+ const d = module . depth ;
1017
+ if ( typeof d === "number" && d <= depth ) return ;
1018
+ queue . add ( module ) ;
1019
+ module . depth = depth ;
1017
1020
} ;
1018
1021
1019
1022
const assignDepthToDependency = ( dependency , depth ) => {
1020
1023
if ( dependency . module ) {
1021
- queue . push ( ( ) => assignDepthToModule ( dependency . module , depth ) ) ;
1024
+ enqueueJob ( dependency . module ) ;
1022
1025
}
1023
1026
} ;
1024
1027
1025
- const assignDepthToDependencyBlock = ( block , depth ) => {
1026
- const iteratorDependency = d => assignDepthToDependency ( d , depth ) ;
1027
-
1028
- const iteratorBlock = b => assignDepthToDependencyBlock ( b , depth ) ;
1029
-
1028
+ const assignDepthToDependencyBlock = block => {
1030
1029
if ( block . variables ) {
1031
- iterationBlockVariable ( block . variables , iteratorDependency ) ;
1030
+ iterationBlockVariable ( block . variables , assignDepthToDependency ) ;
1032
1031
}
1033
1032
1034
1033
if ( block . dependencies ) {
1035
- iterationOfArrayCallback ( block . dependencies , iteratorDependency ) ;
1034
+ iterationOfArrayCallback ( block . dependencies , assignDepthToDependency ) ;
1036
1035
}
1037
1036
1038
1037
if ( block . blocks ) {
1039
- iterationOfArrayCallback ( block . blocks , iteratorBlock ) ;
1038
+ iterationOfArrayCallback ( block . blocks , assignDepthToDependencyBlock ) ;
1040
1039
}
1041
1040
} ;
1042
1041
1043
- const queue = [ ( ) => {
1044
- assignDepthToModule ( module , 0 ) ;
1045
- } ] ;
1042
+ for ( module of queue ) {
1043
+ queue . delete ( module ) ;
1044
+ depth = module . depth ;
1046
1045
1047
- while ( queue . length ) {
1048
- queue . pop ( ) ( ) ;
1046
+ depth ++ ;
1047
+ assignDepthToDependencyBlock ( module ) ;
1049
1048
}
1050
1049
}
1051
1050
0 commit comments