1 import type {KeywordErrorDefinition, KeywordErrorCxt} from "../../types"
2 import type {SchemaCxt} from ".."
3 import {reportError} from "../errors"
4 import {_, Name} from "../codegen"
5 import N from "../names"
7 const boolError: KeywordErrorDefinition = {
8 message: "boolean schema is false",
11 export function topBoolOrEmptySchema(it: SchemaCxt): void {
12 const {gen, schema, validateName} = it
13 if (schema === false) {
14 falseSchemaError(it, false)
15 } else if (typeof schema == "object" && schema.$async === true) {
18 gen.assign(_`${validateName}.errors`, null)
23 export function boolOrEmptySchema(it: SchemaCxt, valid: Name): void {
24 const {gen, schema} = it
25 if (schema === false) {
26 gen.var(valid, false) // TODO var
29 gen.var(valid, true) // TODO var
33 function falseSchemaError(it: SchemaCxt, overrideAllErrors?: boolean): void {
34 const {gen, data} = it
35 // TODO maybe some other interface should be used for non-keyword validation errors...
36 const cxt: KeywordErrorCxt = {
38 keyword: "false schema",
46 reportError(cxt, boolError, undefined, overrideAllErrors)