( trav: TraversalKind, data: object, ctx: InternalTraversal, transformsKeys = true, // whether code compiled to write in place called it inPlace = false )
| 602 | } |
| 603 | |
| 604 | protected _traverse( |
| 605 | trav: TraversalKind, |
| 606 | data: object, |
| 607 | ctx: InternalTraversal, |
| 608 | transformsKeys = true, |
| 609 | // whether code compiled to write in place called it |
| 610 | inPlace = false |
| 611 | ): boolean { |
| 612 | const errN = ctx?.errN ?? 0 |
| 613 | const valueOf = (node: BaseRoot): BaseNode => |
| 614 | inPlace ? inPlaceShapeOf(node) : node |
| 615 | const props = trav === "Allows" ? this.allowsProps : this.inOrder |
| 616 | for (let i = 0; i < props.length; i++) { |
| 617 | const prop = props[i] |
| 618 | if (trav === "Allows") { |
| 619 | if (!prop.tAllows(data, ctx)) return false |
| 620 | } else { |
| 621 | // a prop's Apply would transform before an index signature checks it |
| 622 | if (transformsKeys) prop.tApply(data as never, ctx) |
| 623 | else if (prop.key in data) { |
| 624 | travKey( |
| 625 | prop.key, |
| 626 | () => |
| 627 | applyValue( |
| 628 | valueOf(prop.value), |
| 629 | data[prop.key as never], |
| 630 | ctx, |
| 631 | false |
| 632 | ), |
| 633 | ctx |
| 634 | ) |
| 635 | } else if (prop.is("required")) |
| 636 | travKey(prop.key, () => ctx.nodeError(prop.errorCtx, data), ctx) |
| 637 | |
| 638 | if (ctx.failFast && ctx.errN > errN) return false |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if (this.sequence) { |
| 643 | if (trav === "Allows") { |
| 644 | if (!this.sequence.tAllows(data as never, ctx)) return false |
| 645 | } else { |
| 646 | this.sequence.tApply(data as never, ctx) |
| 647 | if (ctx.failFast && ctx.errN > errN) return false |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | if (this.index || this.undeclared === "reject") { |
| 652 | const keys = this.index ? ownKeysOf(data) : Object.keys(data) |
| 653 | const isArray = Array.isArray(data) |
| 654 | |
| 655 | for (let i = 0; i < keys.length; i++) { |
| 656 | const k = keys[i] |
| 657 | |
| 658 | if (this.index) { |
| 659 | const pathKey = isArray ? arrayPathKeyOf(k) : k |
| 660 | for (const node of this.index) { |
| 661 | if (node.allowsKey(k, ctx)) { |
no test coverage detected