| 300 | } |
| 301 | |
| 302 | function getRefFromAlias( |
| 303 | query: QueryIR, |
| 304 | alias: string, |
| 305 | ): CollectionRef | QueryRef | void { |
| 306 | if (query.from.type === `unionFrom`) { |
| 307 | for (const source of query.from.sources) { |
| 308 | if (source.alias === alias) { |
| 309 | return source |
| 310 | } |
| 311 | } |
| 312 | } else if (query.from.type !== `unionAll` && query.from.alias === alias) { |
| 313 | return query.from |
| 314 | } |
| 315 | |
| 316 | for (const join of query.join || []) { |
| 317 | if (join.from.alias === alias) { |
| 318 | return join.from |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Follows the given reference in a query |