Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
649 bytes
|
Line | |
---|
1 | import type {KeywordCxt} from "../../compile/validate"
|
---|
2 | import {_, not, nil, Code, Name} from "../../compile/codegen"
|
---|
3 |
|
---|
4 | export function checkNullable(
|
---|
5 | {gen, data, parentSchema}: KeywordCxt,
|
---|
6 | cond: Code = nil
|
---|
7 | ): [Name, Code] {
|
---|
8 | const valid = gen.name("valid")
|
---|
9 | if (parentSchema.nullable) {
|
---|
10 | gen.let(valid, _`${data} === null`)
|
---|
11 | cond = not(valid)
|
---|
12 | } else {
|
---|
13 | gen.let(valid, false)
|
---|
14 | }
|
---|
15 | return [valid, cond]
|
---|
16 | }
|
---|
17 |
|
---|
18 | export function checkNullableObject(cxt: KeywordCxt, cond: Code): [Name, Code] {
|
---|
19 | const [valid, cond_] = checkNullable(cxt, cond)
|
---|
20 | return [valid, _`${cond_} && typeof ${cxt.data} == "object" && !Array.isArray(${cxt.data})`]
|
---|
21 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.