MCPcopy Index your code
hub / github.com/nodejs/node / forEachChildRecursively

Function forEachChildRecursively

test/fixtures/snapshot/typescript.js:31248–31288  ·  view source on GitHub ↗

* Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; additionally, * unlike `forEachChild`, embedded arrays are flattened and the 'cbNode'

(rootNode, cbNode, cbNodes)

Source from the content-addressed store, hash-verified

31246 * and while doing so, handles traversing the structure without relying on the callstack to encode the tree structure.
31247 */
31248 function forEachChildRecursively(rootNode, cbNode, cbNodes) {
31249 var queue = gatherPossibleChildren(rootNode);
31250 var parents = []; // tracks parent references for elements in queue
31251 while (parents.length < queue.length) {
31252 parents.push(rootNode);
31253 }
31254 while (queue.length !== 0) {
31255 var current = queue.pop();
31256 var parent = parents.pop();
31257 if (ts.isArray(current)) {
31258 if (cbNodes) {
31259 var res = cbNodes(current, parent);
31260 if (res) {
31261 if (res === "skip")
31262 continue;
31263 return res;
31264 }
31265 }
31266 for (var i = current.length - 1; i >= 0; --i) {
31267 queue.push(current[i]);
31268 parents.push(parent);
31269 }
31270 }
31271 else {
31272 var res = cbNode(current, parent);
31273 if (res) {
31274 if (res === "skip")
31275 continue;
31276 return res;
31277 }
31278 if (current.kind >= 161 /* SyntaxKind.FirstNode */) {
31279 // add children in reverse order to the queue, so popping gives the first child
31280 for (var _i = 0, _a = gatherPossibleChildren(current); _i < _a.length; _i++) {
31281 var child = _a[_i];
31282 queue.push(child);
31283 parents.push(current);
31284 }
31285 }
31286 }
31287 }
31288 }
31289 ts.forEachChildRecursively = forEachChildRecursively;
31290 function gatherPossibleChildren(node) {
31291 var children = [];

Callers

nothing calls this directly

Calls 3

gatherPossibleChildrenFunction · 0.85
popMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected