"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertToTree = exports.getFilesAndSizes = exports.sizeKey = void 0;
exports.sizeKey = Symbol('size');
function getFilesAndSizes(modules) {
    const collector = new Map();
    for (const module of modules) {
        if (module.modules) {
            for (const innerModule of module.modules) {
                const name = innerModule.name.split('!').pop();
                collector.set(name, innerModule.size);
            }
        }
        else {
            const name = module.name.split('!').pop();
            collector.set(name, module.size);
        }
    }
    return collector;
}
exports.getFilesAndSizes = getFilesAndSizes;
function convertToTree(filesAndSizes) {
    const tree = {
        name: '<root>',
        children: [],
    };
    for (const [file, size] of filesAndSizes) {
        let pointer = tree;
        const fileParts = file.split('/');
        fileParts.forEach((filePart, index) => {
            let child = pointer.children.find((c) => c.name === filePart);
            if (!child) {
                child = {
                    name: filePart,
                    children: [],
                };
                pointer.children.push(child);
            }
            if (index === fileParts.length - 1) {
                child.value = size;
            }
            pointer = child;
        });
    }
    return tree;
}
exports.convertToTree = convertToTree;
//# sourceMappingURL=parse.js.map