MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / normalizeValue

Function normalizeValue

src/extraction/function-ref.ts:554–626  ·  view source on GitHub ↗

* Normalize one value expression to zero or more function names. Recursion is * bounded (wrapper layers only); anything that isn't a recognized * function-value shape yields [].

(
  node: SyntaxNode,
  spec: FnRefSpec,
  source: string,
  depth: number
)

Source from the content-addressed store, hash-verified

552 * function-value shape yields [].
553 */
554function normalizeValue(
555 node: SyntaxNode,
556 spec: FnRefSpec,
557 source: string,
558 depth: number
559): NormalizedRef[] {
560 if (depth > 4) return [];
561 const type = node.type;
562
563 // Bare identifier
564 if (spec.idTypes.has(type)) {
565 return [{ name: getNodeText(node, source), node }];
566 }
567
568 // Transparent layers (argument, value_argument, literal_element,
569 // expression_list, block_argument). expression_list fans out (Go `a, b = f, g`).
570 const layerField = spec.layers?.get(type);
571 if (spec.layers?.has(type)) {
572 // Labeled-argument param-forward skip (Swift/Kotlin): `value: value` /
573 // `delay: delay` — when the label EQUALS the value identifier, the value
574 // is a forwarded local/parameter, not a function reference (Alamofire
575 // A/B finding; same rationale as the `this.x = x` assignment skip).
576 if (type === 'value_argument') {
577 const label = getChildByField(node, 'name');
578 const value = getChildByField(node, 'value') ?? node.namedChild(node.namedChildCount - 1);
579 if (
580 label &&
581 value &&
582 getNodeText(label, source).trim() === getNodeText(value, source).trim()
583 ) {
584 return [];
585 }
586 }
587 if (layerField) {
588 const inner = getChildByField(node, layerField);
589 return inner ? normalizeValue(inner, spec, source, depth + 1) : [];
590 }
591 const results: NormalizedRef[] = [];
592 for (let i = 0; i < node.namedChildCount; i++) {
593 const child = node.namedChild(i);
594 if (child) results.push(...normalizeValue(child, spec, source, depth + 1));
595 }
596 return results;
597 }
598
599 // Unary wrappers: &fn / @Fn / `fn _`
600 const unwrapField = spec.unwrap?.get(type);
601 if (spec.unwrap?.has(type)) {
602 // C-family `pointer_expression` covers BOTH `&x` (address-of — a function
603 // value) and `*x` (dereference — a data read, never a function value).
604 // Only `&` qualifies; without this, fmt's `*begin` reads resolved to its
605 // free `begin()` functions.
606 if (type === 'pointer_expression' && node.child(0)?.type !== '&') return [];
607 const inner = unwrapField ? getChildByField(node, unwrapField) : node.namedChild(0);
608 if (!inner) return [];
609 // C++ `&Widget::on_click` — keep the QUALIFIED name. Resolution scopes the
610 // method to that class (more precise than a bare-name match, and exempt
611 // from the cpp bare-ids-are-free-functions rule since `&Cls::m` is an

Callers 1

captureFnRefCandidatesFunction · 0.85

Calls 6

getNodeTextFunction · 0.90
getChildByFieldFunction · 0.90
normalizeSpecialFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected