CodeGraph/docs
Section 2.5.2

Functions & Arrow Functions

Extracting top-level function declarations, variable-assigned arrow functions, and expression functions while avoiding duplicate variable registrations.

Source: server/src/parser/extractors/SymbolExtractor.ts

Function Extraction Forms

JavaScript and TypeScript functions appear in three primary syntactic structures:

Function Syntactic Variants
1
2
3
4
5
6
7
8
// 1. FunctionDeclaration function calculateTax(amount: number) { return amount * 0.2; } // 2. Variable-Assigned ArrowFunctionExpression const formatCurrency = (val: number) => `$${val}`; // 3. Variable-Assigned FunctionExpression const parseHeader = function(raw: string) { return raw.trim(); };

Double-Extraction Guard

In const formatCurrency = () => {}, Babel encounters both a VariableDeclaratornode and an ArrowFunctionExpression node.

If both visitors extracted symbols naively, the symbol list would contain two duplicate symbols for the same line (one as "variable" and one as "function").

CodeGraph resolves this by adding an explicit guard in the VariableDeclarator visitor:

server/src/parser/extractors/SymbolExtractor.ts
1
2
3
4
5
6
7
8
// Inside VariableDeclarator visitor: if ( path.node.init?.type === "ArrowFunctionExpression" || path.node.init?.type === "FunctionExpression" || path.node.init?.type === "ClassExpression" ) { return; // Skip variable extraction — the expression visitor will extract the function symbol }
Name Upward Lookup
When the ArrowFunctionExpression visitor runs, it calls getSymbolName(), which checks path.parentPath.isVariableDeclarator() and retrieves the identifier name from parentPath.node.id.name.