( js: CombinatorCompiler, structure: StructureNode, failing: boolean )
| 763 | // changes: in order where nothing can fail, else each transform, then each default |
| 764 | // where none failed |
| 765 | const writeSitedKeep = ( |
| 766 | js: CombinatorCompiler, |
| 767 | structure: StructureNode, |
| 768 | failing: boolean |
| 769 | ): string => { |
| 770 | const transforms: string[] = [] |
| 771 | const defaults: string[] = [] |
| 772 | const out = "(out = out === data ? copy(data) : out)" |
| 773 | for (const [i, prop] of structure.inOrder.entries()) { |
| 774 | const access = writeAccess(prop.key as string) |
| 775 | const read = `data${access}` |
| 776 | const holds = writeHolds(prop) |
| 777 | const held = writeHeld(prop, i, failing) |
| 778 | if (prop.value.tfs) { |
| 779 | // data's allowed before it's transformed, so holds each key it requires |
| 780 | const guard = prop.is("optional") ? `${holds} && ` : "" |
| 781 | transforms.push( |
| 782 | failing ? |
| 783 | `if (${guard}!Object.is(v = ${held}, ${read})) ${out}${access} = v;` |
| 784 | : `if (${guard}(v = ${held}) !== void 0 && v !== ${read}) ${out}${access} = v;` |
| 785 | ) |
| 786 | } |
| 787 | if (!prop.is("optional") || !prop.hasDef()) continue |
| 788 | ;(failing ? defaults : transforms).push( |
| 789 | isLiteralDefault(prop) ? |
| 790 | `if (!(${holds})) ${out}${access} = ${writeLiteral(js, prop.default)};` |
| 791 | : `if (!(${holds})) values.defaulted(checkers[${i}].w, ${out});` |
| 792 | ) |
| 793 | } |
| 794 | return `(data, checkers, values, copy) => { let out = data, v; ${transforms.join(" ")} ${defaults.length ? `if (!values.failed()) { ${defaults.join(" ")} }` : ""} return out; }` |
| 795 | } |
| 796 | |
| 797 | // a required key's checker, wrapped where what the missing key expects or says |
| 798 | // isn't what its value's checker does |
no test coverage detected