@@ -23,9 +23,8 @@ function extractFunctionCalls(node, sourceFile, indentLevel) {
2323 if ( ts . isFunctionDeclaration ( node ) ) {
2424 node . forEachChild ( function ( child ) {
2525 if ( ts . isIdentifier ( child ) ) {
26- var functionName = child . getText ( sourceFile ) ;
27- currentFunction = functionName ;
28- allFunctions . push ( functionName ) ;
26+ var declaredFunction = child . getText ( sourceFile ) ;
27+ updateDeclaredFunctions ( declaredFunction ) ;
2928 }
3029 } ) ;
3130 }
@@ -38,13 +37,29 @@ function extractFunctionCalls(node, sourceFile, indentLevel) {
3837 updateCalledFunctions ( calledFunction ) ;
3938 }
4039 }
41- // Optional logging:
42- // const indentation = "-".repeat(indentLevel);
43- // const syntaxKind = ts.SyntaxKind[node.kind];
44- // const nodeText = node.getText(sourceFile).split('\n')[0];
45- // console.log(`${indentation}${syntaxKind}: ${nodeText}`);
40+ logThings ( node , sourceFile , indentLevel ) ;
4641 node . forEachChild ( function ( child ) { return extractFunctionCalls ( child , sourceFile , indentLevel + 1 ) ; } ) ;
4742}
43+ /**
44+ * Log stuff if needed
45+ * @param node
46+ * @param sourceFile
47+ * @param indentLevel
48+ */
49+ function logThings ( node , sourceFile , indentLevel ) {
50+ var indentation = "-" . repeat ( indentLevel ) ;
51+ var syntaxKind = ts . SyntaxKind [ node . kind ] ;
52+ var nodeText = node . getText ( sourceFile ) . split ( '\n' ) [ 0 ] ;
53+ console . log ( "" + indentation + syntaxKind + ": " + nodeText ) ;
54+ }
55+ /**
56+ * Update `allFunctions` and `currentFunction`
57+ * @param declaredFunction
58+ */
59+ function updateDeclaredFunctions ( declaredFunction ) {
60+ currentFunction = declaredFunction ;
61+ allFunctions . push ( declaredFunction ) ;
62+ }
4863/**
4964 * Update `calledFunctions` map with current called function name
5065 * @param calledFunction - name of the function getting called
0 commit comments