UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

49 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getChildrenRange = void 0; const isCstNode_1 = require("./isCstNode"); const extractRange = (children, range) => { Object.values(children).forEach(tokens => { if (!Array.isArray(tokens)) return; tokens.forEach(token => { if (isCstNode_1.isCstNode(token)) { extractRange(token.children, range); return; } else { if (!token.startLine || !token.startColumn || !token.endLine || !token.endColumn) { return; } // Start range check if (token.startLine < range.startLine || (token.startLine === range.startLine && token.startColumn < range.startColumn)) { range.startLine = token.startLine; range.startColumn = token.startColumn; } // End range check if (token.endLine > range.endLine || (token.endLine === range.endLine && token.endColumn > range.endColumn)) { range.endLine = token.endLine; range.endColumn = token.endColumn; } } }); }); }; /** * Extract the range for a children dictionnary. * * @param children */ const getChildrenRange = (children) => { const range = { startLine: Infinity, endLine: -Infinity, startColumn: Infinity, endColumn: -Infinity }; extractRange(children, range); // This mutate `range` directly return range; }; exports.getChildrenRange = getChildrenRange; //# sourceMappingURL=getChildrenRange.js.map