UNPKG

bonsai-analyzer

Version:
35 lines (27 loc) 792 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getParentChunks; var _Stats = require("../types/Stats"); var _getEntryHierarchy = require("./getEntryHierarchy"); function findChunk(root, targetID, history = []) { if (targetID === null) { return null; } if ((0, _Stats.isSameChunk)(root.id, targetID)) { return history.concat(root); } else { for (let i = 0; i < root.children.length; i++) { const nextHistory = root.id !== _getEntryHierarchy.ROOT_ID ? history.concat(root) : history; const found = findChunk(root.children[i], targetID, nextHistory); if (found) { return found; } } } return null; } function getParentChunks(root, chunkId) { return findChunk(root, chunkId); }