CodeGraph/docs
Section 2.5.6

Object Properties & Methods

Extracting key-value properties and methods declared inside object literals, handling nested objects, and avoiding pattern conflicts.

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

Object Properties vs Object Patterns

In Babel ASTs, the ObjectProperty node represents both object literal fields (const user = { name: "Alice" }) and destructuring patterns (const { name } = user).

The ObjectProperty visitor explicitly ignores destructuring patterns, which are already handled by the VariableDeclarator visitor:

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
ObjectProperty: { enter: (path: NodePath<ObjectProperty>) => { // Skip destructuring patterns (e.g., const { name } = user) if (path.parentPath?.isObjectPattern()) return; // Skip properties whose value is a function/class expression (handled by expression visitors) if ( path.node.value.type === "ArrowFunctionExpression" || path.node.value.type === "ClassExpression" || path.node.value.type === "FunctionExpression" ) return; const symbol = this.extractSymbol({ path, parsedFile, symbolKind: "objectProperty" }); // If the property value is a nested object, push symbol onto symbolStack if (symbol && path.node.value.type === "ObjectExpression") { this.symbolStack.push(symbol); path.setData("symbolPushed", true); } }, exit: (path: NodePath<ObjectProperty>) => { if (path.getData("symbolPushed")) { this.symbolStack.pop(); } } }

Nested Object Literal Hierarchy

For nested objects like const config = { db: { host: "localhost" } }:

  1. config (variable) is pushed to symbolStack.
  2. db (objectProperty) is extracted with parentSymbolId = config.id and pushed to symbolStack.
  3. host (objectProperty) is extracted with parentSymbolId = db.id.
  4. Exits pop db then config, maintaining perfect hierarchical fidelity.