( js: CombinatorCompiler, structure: StructureNode )
| 819 | } |
| 820 | |
| 821 | const writeStructure = ( |
| 822 | js: CombinatorCompiler, |
| 823 | structure: StructureNode |
| 824 | ): string => { |
| 825 | const ref = (node: BaseRoot) => readValue(js, node) |
| 826 | if (structure.sequence) { |
| 827 | const element = structure.sequence.variadic! |
| 828 | return writeCall( |
| 829 | !element.tfs ? "elementsOf" |
| 830 | : element.hasAlias || element.hasMorph ? "failingElementsOf" |
| 831 | : "transformingElementsOf", |
| 832 | ref(element), |
| 833 | element.tfs && element.hasAlias ? "1" : undefined |
| 834 | ) |
| 835 | } |
| 836 | const refs = structure.inOrder.map(prop => ref(prop.value)) |
| 837 | // in arktype's order; a required key expects its value's brief, and says its |
| 838 | // value's message, each of which its checker holds |
| 839 | const entries = structure.inOrder.map((prop, i) => { |
| 840 | const checker = refs[i] |
| 841 | return `${writeKey(prop.key as string)}: ${ |
| 842 | prop.is("optional") ? |
| 843 | !prop.hasDef() ? writeCall("optional", checker) |
| 844 | : isLiteralDefault(prop) ? |
| 845 | writeCall( |
| 846 | prop.defaultsUndefined ? "replacingUndefined" : "optional", |
| 847 | checker, |
| 848 | writeLiteral(js, prop.default) |
| 849 | ) |
| 850 | : writeCall( |
| 851 | "writtenBy", |
| 852 | checker, |
| 853 | prop.defMorph.length === 2 ? |
| 854 | `(data, ctx) => ${js.ref(prop.defMorph)}(data, ctx)` |
| 855 | : `data => ${js.ref(prop.defMorph)}(data)`, |
| 856 | prop.defaultsUndefined ? "1" : undefined |
| 857 | ) |
| 858 | : writeRequired(prop, checker) |
| 859 | }` |
| 860 | }) |
| 861 | const declared = writeObject(entries) |
| 862 | if (structure.index) { |
| 863 | const [{ signature, value }] = structure.index |
| 864 | if ( |
| 865 | structure.index.length === 1 && |
| 866 | !entries.length && |
| 867 | !structure.handlesUndeclared && |
| 868 | signature.is("domain") && |
| 869 | signature.domain === "string" |
| 870 | ) |
| 871 | return writeCall("recordOf", ref(value)) |
| 872 | return writeCall( |
| 873 | "indexed", |
| 874 | `[${structure.index.map(({ signature, value }) => `[${readChecker(js, signature)}, ${ref(value)}]`).join(", ")}]`, |
| 875 | entries.length ? declared : structure.handlesUndeclared && "void 0", |
| 876 | structure.handlesUndeclared && |
| 877 | JSON.stringify(removedSiteOf(structure)!.description) |
| 878 | ) |
no test coverage detected