ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
35 lines (34 loc) • 1.78 kB
JavaScript
;
var __assign = (this && this.__assign)/* istanbul ignore next */ || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var verifyAndGetIndex_1 = require("./../verifyAndGetIndex");
var fillAndGetChildren_1 = require("./../fillAndGetChildren");
var 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 [];
var startChildren = opts.getIndexedChildren();
var parentSyntaxList = opts.parent.getChildSyntaxListOrThrow();
var index = verifyAndGetIndex_1.verifyAndGetIndex(opts.index, startChildren.length);
var childIndex = getChildIndex();
insertIntoBracesOrSourceFile_1.insertIntoBracesOrSourceFile(__assign({}, opts, { children: parentSyntaxList.getChildren(), separator: opts.sourceFile.global.manipulationSettings.getNewLineKind(), index: childIndex }));
return fillAndGetChildren_1.fillAndGetChildren(__assign({}, opts, { allChildren: opts.getIndexedChildren(), index: 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;