| 1905 | |
| 1906 | // every alias a node reaches resolves before it's compiled |
| 1907 | export const referencesThroughAliases = ( |
| 1908 | references: readonly BaseNode[] |
| 1909 | ): BaseNode[] => { |
| 1910 | // keyed by id, as a node bound to another scope keeps its id |
| 1911 | const reached = new Map<string, BaseNode>( |
| 1912 | references.map(reference => [reference.id, reference]) |
| 1913 | ) |
| 1914 | for (const reference of reached.values()) { |
| 1915 | if (!reference.is("alias")) continue |
| 1916 | const resolved = reference.resolution.byId |
| 1917 | for (const id in resolved) |
| 1918 | if (!reached.has(id)) reached.set(id, resolved[id]) |
| 1919 | } |
| 1920 | return [...reached.values()] |
| 1921 | } |
| 1922 | |
| 1923 | // in the order of `byId`, leaving out each union's cases, which hold nothing its |
| 1924 | // branches don't, so reading what's reached doesn't discriminate |