propertyNames.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const codegen_1 = require("../../compile/codegen");
  4. const util_1 = require("../../compile/util");
  5. const error = {
  6. message: ({ params }) => codegen_1.str `property name '${params.propertyName}' is invalid`,
  7. params: ({ params }) => codegen_1._ `{propertyName: ${params.propertyName}}`,
  8. };
  9. const def = {
  10. keyword: "propertyNames",
  11. type: "object",
  12. schemaType: ["object", "boolean"],
  13. error,
  14. code(cxt) {
  15. const { gen, schema, data, it } = cxt;
  16. if (util_1.alwaysValidSchema(it, schema))
  17. return;
  18. const valid = gen.name("valid");
  19. gen.forIn("key", data, (key) => {
  20. cxt.setParams({ propertyName: key });
  21. cxt.subschema({
  22. keyword: "propertyNames",
  23. data: key,
  24. dataTypes: ["string"],
  25. propertyName: key,
  26. compositeRule: true,
  27. strictSchema: it.strictSchema,
  28. }, valid);
  29. gen.if(codegen_1.not(valid), () => {
  30. cxt.error(true);
  31. if (!it.allErrors)
  32. gen.break();
  33. });
  34. });
  35. cxt.ok(valid);
  36. },
  37. };
  38. exports.default = def;
  39. //# sourceMappingURL=propertyNames.js.map