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

Method delegateScriptTag

src/extraction/cfml-extractor.ts:635–706  ·  view source on GitHub ↗

* Delegate a ` ... ` tag body to the cfscript grammar. * With `parentClassName` set (the block sits at component scope), functions * declared at the script's top level are the component's methods * (` function configure(){}` — the standard ColdBox

(scriptTag: SyntaxNode, parentId: string | undefined, parentClassName?: string)

Source from the content-addressed store, hash-verified

633 * (closures) keep kind `function`.
634 */
635 private delegateScriptTag(scriptTag: SyntaxNode, parentId: string | undefined, parentClassName?: string): void {
636 const content = scriptTag.namedChildren.find((c: SyntaxNode) => c.type === 'cf_script_content');
637 if (!content) return;
638
639 const inner = this.source.substring(content.startIndex, content.endIndex);
640 const startLine = content.startPosition.row;
641
642 const extractor = new TreeSitterExtractor(this.filePath, inner, 'cfscript');
643 const result = extractor.extract();
644
645 // The inner TreeSitterExtractor always synthesizes its own `file`-kind
646 // node scoped to just this snippet — drop it (and any edges touching it)
647 // since this tag-based file already owns one correctly-ranged file node
648 // (see createFileNode); the per-node `parentId` contains-edge below
649 // already links every emitted symbol into the real tree.
650 const innerFileNodeId = result.nodes.find((n) => n.kind === 'file')?.id;
651 // Snippet-top-level symbols are the ones the inner extractor attached
652 // directly to its (dropped) snippet file node — as opposed to closures
653 // nested inside another function.
654 const topLevelIds = new Set(
655 result.edges
656 .filter((e) => e.kind === 'contains' && e.source === innerFileNodeId)
657 .map((e) => e.target)
658 );
659 // Snippet-top-level non-callables: `var x = …` locals of the enclosing
660 // function that the fragment-as-module parse mints as declarations.
661 const localVarIds = new Set(
662 result.nodes
663 .filter((n) => topLevelIds.has(n.id) && (n.kind === 'variable' || n.kind === 'constant'))
664 .map((n) => n.id)
665 );
666 for (const node of result.nodes) {
667 if (node.kind === 'file') continue;
668 node.startLine += startLine;
669 node.endLine += startLine;
670 node.language = this.language;
671 if (parentClassName) {
672 if (node.kind === 'function' && topLevelIds.has(node.id)) {
673 node.kind = 'method';
674 }
675 node.qualifiedName = `${parentClassName}::${node.qualifiedName}`;
676 }
677 this.nodes.push(node);
678 if (parentId) {
679 this.edges.push({ source: parentId, target: node.id, kind: 'contains' });
680 }
681 }
682 for (const edge of result.edges) {
683 if (edge.source === innerFileNodeId || edge.target === innerFileNodeId) continue;
684 if (edge.line) edge.line += startLine;
685 this.edges.push(edge);
686 }
687 for (const ref of result.unresolvedReferences) {
688 ref.line += startLine;
689 ref.filePath = this.filePath;
690 ref.language = this.language;
691 // Calls inside a <cfscript> body with no enclosing function (rare — a
692 // top-level script in a .cfm template, or any statement directly in

Callers 1

visitTagMethod · 0.95

Calls 5

extractMethod · 0.95
addBlockErrorsMethod · 0.95
mapMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected