INNER CODE UNIT · TypeScript
getMethodBodyEdges
maciejtreder/ng-toolkit · schematics/_utils/index.ts:186
export function getMethodBodyEdges(tree: Tree, filePath: string, name: string): { start: number, end: number } | null {
let fileContent = getFileContent(tree, filePath);
let sourceFile: ts.SourceFile = ts.createSourceFile('temp.ts', fileContent, ts.ScriptTarget.Latest);
let toReturn = null;
sourceFile.forEachChild(node => {
if (ts.isClassDeclaration(node)) {
let methodFound = false;
node.members.forEach(node => {
if (((name === 'constructor' && ts.isConstructorDeclaration(node)) || ts.isMethodDeclaration(node)) && !methodFound) {
methodFound = true;
if (node.body) {
toReturn = { start: fileContent.indexOf('{', node.body.pos) + 1, end: node.body.end - 1 };
}
}
});
}
});