writes the checks of data's elements
( js: NodeCompiler, compileElement: (keyExpr: string, node: BaseRoot) => NodeCompiler )
| 463 | |
| 464 | /** writes the checks of data's elements */ |
| 465 | private jsElements( |
| 466 | js: NodeCompiler, |
| 467 | compileElement: (keyExpr: string, node: BaseRoot) => NodeCompiler |
| 468 | ): void { |
| 469 | // a transform skips each element that would return its input |
| 470 | const reaches = (node: BaseRoot) => js.trav !== "Transform" || node.tfs |
| 471 | |
| 472 | if (this.prefix) { |
| 473 | for (const [i, node] of this.prefix.entries()) |
| 474 | if (reaches(node)) compileElement(`${i}`, node) |
| 475 | } |
| 476 | |
| 477 | for (const [i, node] of this.maybes.entries()) { |
| 478 | const dataIndex = `${i + this.preLen}` |
| 479 | if (js.trav === "Transform") { |
| 480 | if (node.tfs) { |
| 481 | js.if(this.jsHoldsElement(i < this.defLen, dataIndex), () => |
| 482 | compileElement(dataIndex, node) |
| 483 | ) |
| 484 | } |
| 485 | continue |
| 486 | } |
| 487 | js.if(`${dataIndex} >= data.length`, () => js.return(true)) |
| 488 | compileElement(dataIndex, node) |
| 489 | } |
| 490 | |
| 491 | const variadic = this.variadic |
| 492 | const postfix = this.postfix ?? [] |
| 493 | if (!variadic || (!reaches(variadic) && !postfix.some(reaches))) return |
| 494 | if (postfix.length) |
| 495 | js.const("firstPostfixIndex", `data.length - ${postfix.length}`) |
| 496 | if (reaches(variadic)) { |
| 497 | js.for( |
| 498 | `i < ${postfix.length ? "firstPostfixIndex" : "data.length"}`, |
| 499 | () => compileElement("i", variadic), |
| 500 | this.leading.length |
| 501 | ) |
| 502 | } |
| 503 | for (const [i, node] of postfix.entries()) |
| 504 | if (reaches(node)) compileElement(`firstPostfixIndex + ${i}`, node) |
| 505 | } |
| 506 | |
| 507 | protected override _tf( |
| 508 | mapper: DeepNodeTransformation, |