* The `attribute_value` node of a tag attribute — `undefined` when the tag * has no such attribute, `null` when its value isn't plain text (empty, or * a `#hash#` expression). With `wholeValue`, also `null` when only part of * the value is plain text (`template="#dir#/x.cfm"`).
(tag: SyntaxNode, attrName: string, wholeValue = false)
| 778 | * the value is plain text (`template="#dir#/x.cfm"`). |
| 779 | */ |
| 780 | private tagAttrValueNode(tag: SyntaxNode, attrName: string, wholeValue = false): SyntaxNode | null | undefined { |
| 781 | const attrs: SyntaxNode[] = []; |
| 782 | for (let i = 0; i < tag.namedChildCount; i++) { |
| 783 | const child = tag.namedChild(i); |
| 784 | if (!child) continue; |
| 785 | if (child.type === 'cf_attribute') attrs.push(child); |
| 786 | else if (child.type === 'cf_tag_attributes') { |
| 787 | for (let j = 0; j < child.namedChildCount; j++) { |
| 788 | const inner = child.namedChild(j); |
| 789 | if (inner?.type === 'cf_attribute') attrs.push(inner); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | for (const attr of attrs) { |
| 794 | const nameNode = attr.namedChildren.find((c: SyntaxNode) => c.type === 'cf_attribute_name'); |
| 795 | if (!nameNode) continue; |
| 796 | const text = this.source.substring(nameNode.startIndex, nameNode.endIndex); |
| 797 | if (text.toLowerCase() !== attrName.toLowerCase()) continue; |
| 798 | // Values come wrapped as `quoted_cf_attribute_value` (name="init") or bare |
| 799 | // `cf_attribute_value` (name=init — legal and common in older CFML). |
| 800 | const valueWrapper = attr.namedChildren.find( |
| 801 | (c: SyntaxNode) => c.type === 'quoted_cf_attribute_value' || c.type === 'cf_attribute_value' |
| 802 | ); |
| 803 | if (wholeValue && valueWrapper?.namedChildCount !== 1) return null; |
| 804 | return valueWrapper?.namedChildren.find((c: SyntaxNode) => c.type === 'attribute_value') ?? null; |
| 805 | } |
| 806 | return undefined; |
| 807 | } |
| 808 | |
| 809 | private componentNameFromPath(): string { |
| 810 | const fileName = this.filePath.split(/[/\\]/).pop() || this.filePath; |
no test coverage detected