CodeGraph/docs
Section 2.5.4

Variables & Destructuring Patterns

Extracting declared variables across plain identifiers, ObjectPattern destructuring with aliases, and ArrayPattern unpacking.

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

The Destructuring Engine: `getVariableName`

In JavaScript/TypeScript, a single VariableDeclarator statement can declare multiple variables via pattern matching. The extractor unpacks each into independent ParsedSymbol records:

server/src/parser/extractors/SymbolExtractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
private getVariableName(path: NodePath<VariableDeclarator>): string[] { const id = path.node.id; // 1. Plain Identifier: const count = 10 if (id.type === "Identifier") { return [id.name]; } // 2. ObjectPattern: const { name, age: userAge } = user if (id.type === "ObjectPattern") { return id.properties .filter(property => property.type === "ObjectProperty") .map(property => { // Incase of aliases ({ age: userAge }), symbol name is "userAge" if (property.value.type === "Identifier") { return property.value.name; } return null; }) .filter((name): name is string => name !== null); } // 3. ArrayPattern: const [first, second] = items if (id.type === "ArrayPattern") { return id.elements .filter(element => element?.type === "Identifier") .map(element => element?.name); } return []; }

Variables Initialized with Object Literals

When a variable is initialized with an ObjectExpression (e.g. const serverConfig = { port: 8080 }), the variable symbol itself acts as a container. It is pushed to symbolStack so that nested ObjectProperty and ObjectMethod declarations can set the variable as their parentSymbolId.