UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

29 lines (27 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const verifyAndGetIndex_1 = require("./../verifyAndGetIndex"); const fillAndGetChildren_1 = require("./../fillAndGetChildren"); const insertIntoBracesOrSourceFile_1 = require("./insertIntoBracesOrSourceFile"); /** * Glues together insertIntoBracesOrSourceFile and fillAndGetChildren. * @param opts - Options to do this operation. */ function insertIntoBracesOrSourceFileWithFillAndGetChildren(opts) { if (opts.structures.length === 0) return []; const startChildren = opts.getIndexedChildren(); const parentSyntaxList = opts.parent.getChildSyntaxListOrThrow(); const index = verifyAndGetIndex_1.verifyAndGetIndex(opts.index, startChildren.length); const childIndex = getChildIndex(); insertIntoBracesOrSourceFile_1.insertIntoBracesOrSourceFile(Object.assign({}, opts, { children: parentSyntaxList.getChildren(), separator: opts.sourceFile.global.manipulationSettings.getNewLineKind(), index: childIndex })); return fillAndGetChildren_1.fillAndGetChildren(Object.assign({}, opts, { allChildren: opts.getIndexedChildren(), index })); function getChildIndex() { if (index === 0) return 0; // get the previous member in order to get the implementation signature + 1 return startChildren[index - 1].getChildIndex() + 1; } } exports.insertIntoBracesOrSourceFileWithFillAndGetChildren = insertIntoBracesOrSourceFileWithFillAndGetChildren; //# sourceMappingURL=insertIntoBracesOrSourceFileWithFillAndGetChildren.js.map