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