( name: string, ctx: BaseParseContext, mark: number | undefined )
| 718 | |
| 719 | // resolves the context of an alias's definition, by the phase a reference finds it in |
| 720 | private resolveDefinition( |
| 721 | name: string, |
| 722 | ctx: BaseParseContext, |
| 723 | mark: number | undefined |
| 724 | ): BaseRoot { |
| 725 | if (ctx.phase === "resolving" || ctx.phase === "member") { |
| 726 | reach(ctx) |
| 727 | if (ctx.phase === "resolving") ctx.closes = true |
| 728 | return this.aliasOf(ctx) |
| 729 | } |
| 730 | if (ctx.phase === "failed") throw ctx.error |
| 731 | // read as its resolution is cached, e.g. by the expression of a node |
| 732 | // its id is written to, which a reference reaches once it is |
| 733 | if (ctx.phase === "resolved") return this.aliasOf(ctx) |
| 734 | registerParseContext(ctx).phase = "resolving" |
| 735 | ctx.index = ctx.lowlink = openDefinitions.push(ctx) - 1 |
| 736 | const membersStart = openMembers.length |
| 737 | const uncheckedStart = uncheckedPending() |
| 738 | let node: BaseRoot |
| 739 | try { |
| 740 | node = this.parseOpenDef(ctx.def, ctx) |
| 741 | } catch (e) { |
| 742 | // reset so the next reference reparses it and throws the same error, |
| 743 | // as is each member of a component it leaves open |
| 744 | for (const open of [ctx, ...openMembers.splice(membersStart)]) { |
| 745 | open.phase = "unresolved" |
| 746 | delete open.resolution |
| 747 | nodesById.delete(open.id) |
| 748 | } |
| 749 | throw e |
| 750 | } finally { |
| 751 | openDefinitions.pop() |
| 752 | } |
| 753 | reach(ctx) |
| 754 | if (ctx.lowlink < ctx.index && !node.topAlias) { |
| 755 | ctx.phase = "member" |
| 756 | ctx.resolution = node |
| 757 | openMembers.push(ctx) |
| 758 | return this.aliasOf(ctx) |
| 759 | } |
| 760 | ctx.phase = "resolved" |
| 761 | const component = [ctx] |
| 762 | // a deferred check failed; reparsing would reuse checked nodes |
| 763 | const fail = (e: unknown) => { |
| 764 | for (const failed of component) { |
| 765 | failed.phase = "failed" |
| 766 | failed.error = e |
| 767 | // registered again, so an alias holding what it resolved to throws too |
| 768 | nodesById.set(failed.id, failed) |
| 769 | failed.$.res[failed.alias!] = failed |
| 770 | } |
| 771 | } |
| 772 | try { |
| 773 | const resolved = resolving(() => { |
| 774 | // it reaches no definition still open, so its component closes with it |
| 775 | if (ctx.lowlink === ctx.index) { |
| 776 | const members = openMembers.splice(membersStart) |
| 777 | component.push(...members) |
nothing calls this directly
no test coverage detected