@@ -113,9 +113,6 @@ module.exports = (items, getDependencies) => {
113
113
cycle = new Cycle ( ) ;
114
114
cycle . nodes . add ( dependency ) ;
115
115
dependency . cycle = cycle ;
116
- // Assume this is a root cycle
117
- // It will removed if not on node leaving
118
- rootCycles . add ( cycle ) ;
119
116
}
120
117
// set cycle property for each node in the cycle
121
118
// if nodes are already part of a cycle
@@ -129,7 +126,6 @@ module.exports = (items, getDependencies) => {
129
126
if ( node . cycle ) {
130
127
if ( node . cycle !== cycle ) {
131
128
// merge cycles
132
- rootCycles . delete ( node . cycle ) ;
133
129
for ( const cycleNode of node . cycle . nodes ) {
134
130
cycleNode . cycle = cycle ;
135
131
cycle . nodes . add ( cycleNode ) ;
@@ -153,7 +149,8 @@ module.exports = (items, getDependencies) => {
153
149
roots . delete ( dependency ) ;
154
150
break ;
155
151
case DONE_MAYBE_ROOT_CYCLE_MARKER :
156
- // This node has be visited yet and is currently part of a completed root cycle
152
+ // This node has be visited yet and
153
+ // is maybe currently part of a completed root cycle
157
154
// we found a new reference to the cycle
158
155
// so it's not really a root cycle
159
156
// remove the cycle from the root cycles
@@ -167,28 +164,16 @@ module.exports = (items, getDependencies) => {
167
164
// All dependencies of the current node has been visited
168
165
// we leave the node
169
166
stack . pop ( ) ;
170
- const node = topOfStack . node ;
171
- // If the leaving node is part of a cycle
172
- // and parent node is not part of the same cycle
173
- // we have a parent-child-relationship between these cycles
174
- // and remove the child cycle from the rootCycles
175
- const cycle = node . cycle ;
176
- if ( cycle ) {
177
- if ( stack . length > 0 ) {
178
- const parent = stack [ stack . length - 1 ] ;
179
- if ( parent . node . cycle !== cycle ) {
180
- rootCycles . delete ( cycle ) ;
181
- node . marker = DONE_MARKER ;
182
- continue ;
183
- }
184
- }
185
- node . marker = DONE_MAYBE_ROOT_CYCLE_MARKER ;
186
- } else {
187
- node . marker = DONE_MARKER ;
188
- }
167
+ topOfStack . node . marker = DONE_MARKER ;
189
168
}
190
169
}
191
- if ( selectedNode . marker === DONE_MARKER ) {
170
+ const cycle = selectedNode . cycle ;
171
+ if ( cycle ) {
172
+ for ( const node of cycle . nodes ) {
173
+ node . marker = DONE_MAYBE_ROOT_CYCLE_MARKER ;
174
+ }
175
+ rootCycles . add ( cycle ) ;
176
+ } else {
192
177
selectedNode . marker = DONE_AND_ROOT_MARKER ;
193
178
roots . add ( selectedNode ) ;
194
179
}
0 commit comments