(structure: StructureNode, refs: string[])
| 681 | // false where a key's check fails, stopping at the first as a walker does, then |
| 682 | // where data holds a key it rejects, for...in also reaching inherited keys |
| 683 | const writeSitedAllows = (structure: StructureNode, refs: string[]): string => { |
| 684 | const fails = structure.inOrder |
| 685 | .map((prop, i) => { |
| 686 | const has = `${JSON.stringify(prop.key)} in data` |
| 687 | // keys holding the same check call the same checker |
| 688 | const checker = |
| 689 | /^runtime\.\w+$/.test(refs[i]) ? |
| 690 | refs[i] |
| 691 | : `checkers[${refs.indexOf(refs[i])}]` |
| 692 | const fail = `!${checker}(data${writeAccess(prop.key as string)})` |
| 693 | return ( |
| 694 | prop.is("optional") ? `(${has} && ${fail})` |
| 695 | : failsUndefined(prop.value) ? fail |
| 696 | : `(!(${has}) || ${fail})` |
| 697 | ) |
| 698 | }) |
| 699 | .join(" || ") |
| 700 | if (structure.handlesUndeclared !== "reject") |
| 701 | return `(data, checkers) => !(${fails})` |
| 702 | const declared = structure.inOrder |
| 703 | .map(prop => `case ${JSON.stringify(prop.key)}:`) |
| 704 | .join(" ") |
| 705 | return `(data, checkers) => { if (${fails}) return false; for (const k in data) switch (k) { ${declared} break; default: if (Object.prototype.hasOwnProperty.call(data, k)) return false; } return true; }` |
| 706 | } |
| 707 | |
| 708 | // what a key reads through its checker's transform, where it has one |
| 709 | const writeHeld = (prop: Prop.Node, i: number, failing: boolean): string => { |
no test coverage detected