| 204 | } |
| 205 | |
| 206 | private jsTf(js: NodeCompiler): void { |
| 207 | let result = "data" |
| 208 | if (this.head?.tfs) { |
| 209 | js.initTf([this.head]) |
| 210 | .tfKey("transformedIn", "data", [{ node: this.head }]) |
| 211 | .retIfFailed() |
| 212 | result = "transformedIn" |
| 213 | } |
| 214 | const morphs = this.travMorphs |
| 215 | const label = this.meta.label |
| 216 | for (let i = this.head ? 1 : 0; i < morphs.length; i++) { |
| 217 | const morph = morphs[i] |
| 218 | const morphed = `morphed${i}` |
| 219 | if (hasArkKind(morph, "root")) { |
| 220 | js.const( |
| 221 | morphed, |
| 222 | `${js.ref(pipeOf(morph))}(ctx, ${js.ref(morph)}, ${result})` |
| 223 | ).if(`ctx._errors !== undefined && ${morphed} === ctx._errors`, () => |
| 224 | js.return("data") |
| 225 | ) |
| 226 | } else { |
| 227 | const says = this.says[i] |
| 228 | const fn = js.ref(morph) |
| 229 | const call = |
| 230 | this.contextFree[i] ? |
| 231 | `${fn}(${result})` |
| 232 | : `${js.ref(callMorph)}(ctx, ${says ? `(In, at) => ${fn}(In, at, ${JSON.stringify(says)})` : fn}, ${result}${label !== undefined ? `, ${JSON.stringify(label)}` : ""})` |
| 233 | js.const(morphed, call).if( |
| 234 | `${morphed} instanceof ${js.ref(ArkErrors)}`, |
| 235 | () => |
| 236 | js.needsCtx ? |
| 237 | js.line(`${js.ref(addErrors)}(ctx, ${morphed})`).return("data") |
| 238 | : js.return(`new ${js.ref(TransformErrors)}(${morphed}, ${result})`) |
| 239 | ) |
| 240 | } |
| 241 | result = morphed |
| 242 | } |
| 243 | js.return(result) |
| 244 | } |
| 245 | |
| 246 | tAllows(data: unknown, ctx: InternalTraversal | AliasDepth): boolean { |
| 247 | return !this.head || this.head.tAllows(data, ctx) |