MCPcopy
hub / github.com/facebook/react / findPaths

Function findPaths

packages/react-reconciler/src/ReactTestSelectors.js:229–266  ·  view source on GitHub ↗
(root: Fiber, selectors: Array<Selector>)

Source from the content-addressed store, hash-verified

227}
228
229function findPaths(root: Fiber, selectors: Array<Selector>): Array<Fiber> {
230 const matchingFibers: Array<Fiber> = [];
231
232 const stack = [root, 0];
233 let index = 0;
234 while (index < stack.length) {
235 const fiber = ((stack[index++]: any): Fiber);
236 const tag = fiber.tag;
237 let selectorIndex = ((stack[index++]: any): number);
238 let selector = selectors[selectorIndex];
239
240 if (
241 (tag === HostComponent ||
242 tag === HostHoistable ||
243 tag === HostSingleton) &&
244 isHiddenSubtree(fiber)
245 ) {
246 continue;
247 } else {
248 while (selector != null && matchSelector(fiber, selector)) {
249 selectorIndex++;
250 selector = selectors[selectorIndex];
251 }
252 }
253
254 if (selectorIndex === selectors.length) {
255 matchingFibers.push(fiber);
256 } else {
257 let child = fiber.child;
258 while (child !== null) {
259 stack.push(child, selectorIndex);
260 child = child.sibling;
261 }
262 }
263 }
264
265 return matchingFibers;
266}
267
268// Same as findPaths but with eager bailout on first match
269function hasMatchingPaths(root: Fiber, selectors: Array<Selector>): boolean {

Callers 2

findAllNodesFunction · 0.85
focusWithinFunction · 0.85

Calls 3

isHiddenSubtreeFunction · 0.90
matchSelectorFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected