* Resolve a const from the types content (for nested references within the same file).
( constName: string, typesContent: string, toolPrefix: string, depth: number )
| 1535 | * Resolve a const from the types content (for nested references within the same file). |
| 1536 | */ |
| 1537 | function resolveConstFromTypesContent( |
| 1538 | constName: string, |
| 1539 | typesContent: string, |
| 1540 | toolPrefix: string, |
| 1541 | depth: number |
| 1542 | ): Record<string, any> | null { |
| 1543 | if (depth > 10) return null |
| 1544 | |
| 1545 | // Check cache |
| 1546 | const cacheKey = `${toolPrefix}:${constName}` |
| 1547 | if (constResolutionCache.has(cacheKey)) { |
| 1548 | return constResolutionCache.get(cacheKey)! |
| 1549 | } |
| 1550 | |
| 1551 | // Find the const definition in typesContent |
| 1552 | const constRegex = new RegExp( |
| 1553 | `export\\s+const\\s+${constName}\\s*(?::\\s*[^=]+)?\\s*=\\s*\\{`, |
| 1554 | 'g' |
| 1555 | ) |
| 1556 | const constMatch = constRegex.exec(typesContent) |
| 1557 | |
| 1558 | if (!constMatch) { |
| 1559 | return null |
| 1560 | } |
| 1561 | |
| 1562 | const startIndex = constMatch.index + constMatch[0].length - 1 |
| 1563 | const endIndex = findMatchingClose(typesContent, startIndex) |
| 1564 | |
| 1565 | if (endIndex === -1) return null |
| 1566 | |
| 1567 | const constContent = typesContent.substring(startIndex + 1, endIndex - 1).trim() |
| 1568 | |
| 1569 | // Check if this const defines a complete output field (has type property) |
| 1570 | const typeMatch = constContent.match(/^\s*type\s*:\s*['"]([^'"]+)['"]/) |
| 1571 | if (typeMatch) { |
| 1572 | // This is a complete output definition (like ATTENDEES_OUTPUT) |
| 1573 | const result = parseConstFieldContent(constContent, toolPrefix, typesContent, depth) |
| 1574 | if (result) { |
| 1575 | constResolutionCache.set(cacheKey, result) |
| 1576 | } |
| 1577 | return result |
| 1578 | } |
| 1579 | |
| 1580 | // This is a properties object (like ATTENDEE_OUTPUT_PROPERTIES) |
| 1581 | const properties = parseConstProperties(constContent, toolPrefix, typesContent, depth + 1) |
| 1582 | constResolutionCache.set(cacheKey, properties) |
| 1583 | return properties |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Parse a field content from a const, resolving nested const references. |
no test coverage detected