parses a definition in this scope to a node
(def: unknown, opts: BaseParseOptions = {})
| 1095 | |
| 1096 | /** parses a definition in this scope to a node */ |
| 1097 | parseDef(def: unknown, opts: BaseParseOptions = {}): BaseRoot { |
| 1098 | if (hasArkKind(def, "root") && isInstanceOf(def, BaseRoot)) |
| 1099 | return this.bindRef(def.internal) |
| 1100 | |
| 1101 | const ctxInputOrNode = this.preparseOwn(def, opts) |
| 1102 | if (hasArkKind(ctxInputOrNode, "root")) return this.bindRef(ctxInputOrNode) |
| 1103 | |
| 1104 | const ctx = registerParseContext(this.createParseCtx(ctxInputOrNode)) |
| 1105 | let node: BaseRoot |
| 1106 | try { |
| 1107 | node = this.parseOpenDef(def, ctx) |
| 1108 | node = resolving(() => { |
| 1109 | if (node.topAlias && !inProgress.definitions) |
| 1110 | node = resolveShallowAliases(node) |
| 1111 | |
| 1112 | // if the node is recursive e.g. { box: "this" }, we need to make sure it |
| 1113 | // has the original id from context so that its references compile correctly |
| 1114 | if (ctx.isReferencedById) node = publishNode(ctx, withId(node, ctx.id)) |
| 1115 | else nodesById.delete(ctx.id) |
| 1116 | return node |
| 1117 | }) |
| 1118 | } catch (e) { |
| 1119 | nodesById.delete(ctx.id) |
| 1120 | throw e |
| 1121 | } |
| 1122 | if (!ctx.isReferencedAsThis || ctx.name) return node |
| 1123 | // parsed again, since the nodes that reference it have printed `this` |
| 1124 | return printSelfAsThis( |
| 1125 | this.parseDef(def, { |
| 1126 | ...opts, |
| 1127 | name: `${ctx.prefix}${hashOf(withoutHoleNames(node.expression))}` |
| 1128 | }), |
| 1129 | node |
| 1130 | ) |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * parses the definition `define` returns to the node of `id`, which what |
nothing calls this directly
no test coverage detected