From 5d554a6b31dfa6a6b20cf39d55bb2597ac164d45 Mon Sep 17 00:00:00 2001 From: "chaofan.jiang" Date: Thu, 16 Jul 2020 01:24:17 +0800 Subject: [PATCH] Add arrow functions --- extract.ts | 14 ++++++++++++++ package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extract.ts b/extract.ts index 04d6415..549481a 100644 --- a/extract.ts +++ b/extract.ts @@ -34,6 +34,20 @@ function extractFunctionCalls(node: ts.Node, sourceFile: ts.SourceFile, indentLe }); } + // Arrow function + if ( + ts.isVariableDeclaration(node) && + node.initializer && + ts.isArrowFunction(node.initializer) && + indentLevel === 3 + ) { + const child = node.getChildAt(0, sourceFile); + if (ts.isIdentifier(child)) { + const declaredFunction: string = child.getText(sourceFile); + updateDeclaredFunctions(declaredFunction); + } + } + // First child must be `Identifier` // examples of what gets skipped: `fs.readFile('lol.json')` or `ipc.on('something', () => {})` if (ts.isCallExpression(node)) { diff --git a/package.json b/package.json index 351fed0..0c9472e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-call-graph", - "version": "0.0.2", + "version": "0.0.3", "description": "Create a call graph of your TypeScript files", "keywords": [ "TypeScript",