mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
export const def = {
|
|
code(cxt) {
|
|
const { gen, schema, parentSchema, data, it } = cxt;
|
|
if (
|
|
it.opts.removeAdditional === "all" &&
|
|
parentSchema.additionalProperties === undefined
|
|
) {
|
|
additionalProperties_1.default.code(
|
|
new validate_1.KeywordCxt(
|
|
it,
|
|
additionalProperties_1.default,
|
|
"additionalProperties"
|
|
)
|
|
);
|
|
}
|
|
const allProps = (0, code_1.allSchemaProperties)(schema);
|
|
for (const prop of allProps) {
|
|
it.definedProperties.add(prop);
|
|
}
|
|
if (it.opts.unevaluated && allProps.length && it.props !== true) {
|
|
it.props = util_1.mergeEvaluated.props(
|
|
gen,
|
|
(0, util_1.toHash)(allProps),
|
|
it.props
|
|
);
|
|
}
|
|
const properties = allProps.filter(
|
|
(p) => !(0, util_1.alwaysValidSchema)(it, schema[p])
|
|
);
|
|
if (properties.length === 0) return;
|
|
const valid = gen.name("valid");
|
|
for (const prop of properties) {
|
|
if (hasDefault(prop)) {
|
|
applyPropertySchema(prop);
|
|
} else {
|
|
gen.if(
|
|
(0, code_1.propertyInData)(
|
|
gen,
|
|
data,
|
|
prop,
|
|
it.opts.ownProperties
|
|
)
|
|
);
|
|
applyPropertySchema(prop);
|
|
if (!it.allErrors) gen.else().var(valid, true);
|
|
gen.endIf();
|
|
}
|
|
cxt.it.definedProperties.add(prop);
|
|
cxt.ok(valid);
|
|
}
|
|
function hasDefault(prop) {
|
|
return (
|
|
it.opts.useDefaults &&
|
|
!it.compositeRule &&
|
|
schema[prop].default !== undefined
|
|
);
|
|
}
|
|
function applyPropertySchema(prop) {
|
|
cxt.subschema(
|
|
{
|
|
keyword: "properties",
|
|
schemaProp: prop,
|
|
dataProp: prop,
|
|
},
|
|
valid
|
|
);
|
|
}
|
|
},
|
|
};
|