CodeGraph/docs
Section 2.6.3

Instantiation Resolution

Extracting object construction via new expressions and attributing source ownership to variable declarations and function return statements.

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

Source Attribution for `NewExpression`

When an object is instantiated with new Foo(), CodeGraph determines the appropriate source entity:

server/src/parser/extractors/RelationshipExtractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
private resolveSourceSymbolForInstantiates(parsedFile: ParsedFile, path: NodePath<NewExpression>): ParsedSymbol | undefined { // Case 1: Assigned to a variable (e.g., const client = new RedisClient()) if (path.parentPath?.isVariableDeclarator()) { return this.findSymbolForNode(parsedFile, path.parentPath.node); } // Case 2: Returned from a function (e.g., return new UserSession()) if (path.parentPath?.isReturnStatement()) { return this.symbolStack.at(-1); // Active enclosing function/method } return undefined; // Arbitrary inline argument instantiations are skipped }

Target Class Binding

The callee must be a named identifier (e.g., new AppService()). The extractor resolves the class binding in the current file scope or across imported modules to create:

(sourceSymbol) --[instantiates]--> (classSymbol)