(
leftSide: TSNode,
callNode: TSNode,
code: string,
ctx: NodeParseContext,
loopIteration?: number,
subgraphs?: { [parent: string]: string[] }
)
| 313 | * @param subgraphs - Optional subgraphs map to track parent-child relationships |
| 314 | */ |
| 315 | export function parseCreateNode( |
| 316 | leftSide: TSNode, |
| 317 | callNode: TSNode, |
| 318 | code: string, |
| 319 | ctx: NodeParseContext, |
| 320 | loopIteration?: number, |
| 321 | subgraphs?: { [parent: string]: string[] } |
| 322 | ): void { |
| 323 | // Get variable name (e.g., self._dag_designer_agent or test_loop) |
| 324 | const variableName = getNodeText(leftSide, code); |
| 325 | |
| 326 | // Check if this is a subgraph node by examining the function call |
| 327 | const functionNode = callNode.childForFieldName('function'); |
| 328 | if (!functionNode) {return;} |
| 329 | |
| 330 | const functionText = getNodeText(functionNode, code); |
| 331 | let parentGraph = ''; |
| 332 | |
| 333 | // Extract parent graph from function call using unified utility |
| 334 | const methodCall = extractMethodCall(functionText); |
| 335 | if (methodCall && methodCall.method === 'create_node') { |
| 336 | const parentVar = methodCall.caller; |
| 337 | if (parentVar !== 'self') { |
| 338 | // Try to resolve the parent variable |
| 339 | console.log(`[Parser] Looking up parent variable: ${parentVar}, variableToNodeName keys: ${Object.keys(ctx.variableToNodeName).join(', ')}`); |
| 340 | if (ctx.variableToNodeName[parentVar]) { |
| 341 | parentGraph = ctx.variableToNodeName[parentVar]; |
| 342 | console.log(`[Parser] Found parent mapping: ${parentVar} -> ${parentGraph}`); |
| 343 | } else if (parentVar.startsWith('self._')) { |
| 344 | // Handle self._xxx pattern - try looking up the full variable name first |
| 345 | const fullVar = parentVar; |
| 346 | if (ctx.variableToNodeName[fullVar]) { |
| 347 | parentGraph = ctx.variableToNodeName[fullVar]; |
| 348 | console.log(`[Parser] Found parent via full variable: ${fullVar} -> ${parentGraph}`); |
| 349 | } else { |
| 350 | // Fallback to stripped name |
| 351 | parentGraph = parentVar.replace('self._', ''); |
| 352 | console.log(`[Parser] Using stripped parent name: ${parentGraph}`); |
| 353 | } |
| 354 | } else if (parentVar.startsWith('self.')) { |
| 355 | // Handle self.xxx pattern |
| 356 | if (ctx.variableToNodeName[parentVar]) { |
| 357 | parentGraph = ctx.variableToNodeName[parentVar]; |
| 358 | } else { |
| 359 | parentGraph = parentVar.replace('self.', ''); |
| 360 | } |
| 361 | } else { |
| 362 | parentGraph = parentVar; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | // Get arguments |
| 368 | const argsNode = callNode.childForFieldName('arguments'); |
| 369 | if (!argsNode) {return;} |
| 370 | |
| 371 | const args = argsNode.namedChildren.filter(isNonNullNode); |
| 372 | if (args.length === 0) {return;} |
no test coverage detected