(js: NodeCompiler)
| 158 | } |
| 159 | |
| 160 | jsExpression(js: NodeCompiler): string | undefined { |
| 161 | const key = js.serialize(this.key) |
| 162 | const value = `data${js.prop(this.key)}` |
| 163 | // a value no branch of which allows undefined fails a missing key too |
| 164 | if ( |
| 165 | this.is("required") && |
| 166 | (js.trav === "Allows" || (!this.value.tfs && !this.value.entersAlias)) && |
| 167 | this.value.branches.every(branch => { |
| 168 | // Allows checks a morph's input |
| 169 | const input = branch.is("morph") ? branch.head : branch |
| 170 | const basis = input?.is("intersection") ? input.basis : input |
| 171 | return ( |
| 172 | !!basis?.isBasis() && !(basis.is("unit") && basis.unit === undefined) |
| 173 | ) |
| 174 | }) |
| 175 | ) { |
| 176 | if (js.trav === "Apply") { |
| 177 | // a value a condition decides is checked by it before it's applied, |
| 178 | // a union by its branches |
| 179 | const condition = |
| 180 | isDecidedByAllows(this.value) && this.value.jsCond?.(js, value) |
| 181 | const site = condition && js.failingSiteOf?.(this) |
| 182 | const fails = |
| 183 | this.value.isBasis() ? `!${js.error(this, key)}` |
| 184 | : site ? `!${js.failsSite(site, "data", key)}` |
| 185 | : `!${js.failsIn(`${(condition && js.failingApplyOf?.(this.value)) || js.traversal(this.value, "Apply")}, data, ${js.applied(key, value, js.site(this))}`)}` |
| 186 | return condition ? `${condition} || ${fails}` : fails |
| 187 | } |
| 188 | // a value whose predicates read ctx is checked at its key's path |
| 189 | if (this.value.allowsCtx && this.value.checksCtx) return |
| 190 | return ( |
| 191 | this.value.jsCond?.(js, value) ?? js.inv(this.value, { arg: value }) |
| 192 | ) |
| 193 | } |
| 194 | const fails = js.keyFails(key, value, this.value) |
| 195 | if (fails === undefined) return |
| 196 | return ( |
| 197 | this.is("optional") ? `!(${key} in data) || !(${fails})` |
| 198 | : js.trav === "Apply" ? |
| 199 | `${key} in data ? !(${fails}) : !${js.error(this, key)}` |
| 200 | : `${key} in data && !(${fails})` |
| 201 | ) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | const formatPropKey = (key: string): string => |
nothing calls this directly
no test coverage detected