Section 2.5.4Source:
server/src/parser/extractors/SymbolExtractor.tsVariables & Destructuring Patterns
Extracting declared variables across plain identifiers, ObjectPattern destructuring with aliases, and ArrayPattern unpacking.
Source:
server/src/parser/extractors/SymbolExtractor.tsThe 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
12345678910111213141516171819202122232425262728293031private 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.