* Resolve a token reference with chained resolution and cycle detection. * Returns null if the reference cannot be resolved (not found or circular).
( symbolTable: Map<string, ResolvedValue>, path: string, visited: Set<string>, depth: number = 0, )
| 375 | * Returns null if the reference cannot be resolved (not found or circular). |
| 376 | */ |
| 377 | function resolveReference( |
| 378 | symbolTable: Map<string, ResolvedValue>, |
| 379 | path: string, |
| 380 | visited: Set<string>, |
| 381 | depth: number = 0, |
| 382 | ): ResolvedValue | null { |
| 383 | if (depth > MAX_REFERENCE_DEPTH) return null; |
| 384 | if (visited.has(path)) return null; // Circular reference |
| 385 | visited.add(path); |
| 386 | |
| 387 | const value = symbolTable.get(path); |
| 388 | if (value === undefined) return null; |
| 389 | |
| 390 | // If the value is itself a reference string, follow the chain |
| 391 | if (typeof value === 'string' && isTokenReference(value)) { |
| 392 | const innerPath = value.slice(1, -1); |
| 393 | return resolveReference(symbolTable, innerPath, visited, depth + 1); |
| 394 | } |
| 395 | |
| 396 | return value; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * WCAG 2.1 contrast ratio between two resolved colors. |
no test coverage detected
searching dependent graphs…