Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
976 bytes
|
Line | |
---|
1 | import type {CodeKeywordDefinition, SchemaObject} from "../../types"
|
---|
2 | import type {KeywordCxt} from "../../compile/validate"
|
---|
3 | import {alwaysValidSchema} from "../../compile/util"
|
---|
4 | import {validateArray} from "../code"
|
---|
5 | import {_, not} from "../../compile/codegen"
|
---|
6 | import {checkMetadata} from "./metadata"
|
---|
7 | import {checkNullable} from "./nullable"
|
---|
8 | import {typeError, _JTDTypeError} from "./error"
|
---|
9 |
|
---|
10 | export type JTDElementsError = _JTDTypeError<"elements", "array", SchemaObject>
|
---|
11 |
|
---|
12 | const def: CodeKeywordDefinition = {
|
---|
13 | keyword: "elements",
|
---|
14 | schemaType: "object",
|
---|
15 | error: typeError("array"),
|
---|
16 | code(cxt: KeywordCxt) {
|
---|
17 | checkMetadata(cxt)
|
---|
18 | const {gen, data, schema, it} = cxt
|
---|
19 | if (alwaysValidSchema(it, schema)) return
|
---|
20 | const [valid] = checkNullable(cxt)
|
---|
21 | gen.if(not(valid), () =>
|
---|
22 | gen.if(
|
---|
23 | _`Array.isArray(${data})`,
|
---|
24 | () => gen.assign(valid, validateArray(cxt)),
|
---|
25 | () => cxt.error()
|
---|
26 | )
|
---|
27 | )
|
---|
28 | cxt.ok(valid)
|
---|
29 | },
|
---|
30 | }
|
---|
31 |
|
---|
32 | export default def
|
---|
Note:
See
TracBrowser
for help on using the repository browser.