(call: SyntaxNode, source: string)
| 67 | * (`createObject("java", …)`), and for a name built at runtime. |
| 68 | */ |
| 69 | export function cfmlCreatedComponent(call: SyntaxNode, source: string): string | null { |
| 70 | if (call.type !== 'call_expression') return null; |
| 71 | const fn = getChildByField(call, 'function'); |
| 72 | if (fn?.type !== 'identifier' || getNodeText(fn, source).toLowerCase() !== 'createobject') return null; |
| 73 | const args = getChildByField(call, 'arguments')?.namedChildren ?? []; |
| 74 | let type: string | null | undefined; |
| 75 | let name: string | null | undefined; |
| 76 | if (args.length > 0 && args.every((a: SyntaxNode) => a.type === 'assignment_expression')) { |
| 77 | for (const arg of args) { |
| 78 | const key = getNodeText(getChildByField(arg, 'left') ?? arg, source).toLowerCase(); |
| 79 | if (key === 'type') type = literalString(getChildByField(arg, 'right'), source); |
| 80 | else if (key === 'component') name = literalString(getChildByField(arg, 'right'), source); |
| 81 | } |
| 82 | } else if (args.length === 1) { |
| 83 | name = literalString(args[0], source); |
| 84 | } else if (args.length >= 2) { |
| 85 | type = literalString(args[0], source); |
| 86 | name = literalString(args[1], source); |
| 87 | } |
| 88 | if (type !== undefined && type?.toLowerCase() !== 'component') return null; |
| 89 | return name && COMPONENT_PATH.test(name) ? name : null; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * The component an expression constructs, when the expression is a |
no test coverage detected