Lines 5301-5380javascript
5301 this.localRefs = env.localRefs;
5302 this.meta = env.meta;
5303 this.$async = schema === null || schema === void 0 ? void 0 : schema.$async;
5307 exports.SchemaEnv = SchemaEnv;
5308 function compileSchema(sch) {
5309 const _sch = getCompilingSchema.call(this, sch);
5310 if (_sch) return _sch;
5311 const rootId = (0, resolve_1.getFullPath)(this.opts.uriResolver, sch.root.baseId);
5312 const { es5, lines } = this.opts.code;
5313 const { ownProperties } = this.opts;
5314 const gen = new codegen_1.CodeGen(this.scope, {
5319 let _ValidationError;
5320 if (sch.$async) _ValidationError = gen.scopeValue("Error", {
5321 ref: validation_error_1.default,
5322 code: (0, codegen_1._)`require("ajv/dist/runtime/validation_error").default`
5323 });
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/bridge-NEdX_EzI.jsView on unpkg · L5321 5324 const validateName = gen.scopeName("validate");
5325 sch.validateName = validateName;
5328 allErrors: this.opts.allErrors,
5329 data: names_1.default.data,
5330 parentData: names_1.default.parentData,
5331 parentDataProperty: names_1.default.parentDataProperty,
5332 dataNames: [names_1.default.data],
5333 dataPathArr: [codegen_1.nil],
5336 definedProperties: /* @__PURE__ */ new Set(),
5337 topSchemaRef: gen.scopeValue("schema", this.opts.code.source === true ? {
5339 code: (0, codegen_1.stringify)(sch.schema)
5340 } : { ref: sch.schema }),
5342 ValidationError: _ValidationError,
5346 baseId: sch.baseId || rootId,
5347 schemaPath: codegen_1.nil,
5348 errSchemaPath: sch.schemaPath || (this.opts.jtd ? "" : "#"),
5349 errorPath: (0, codegen_1._)`""`,
5355 this._compilations.add(sch);
5356 (0, validate_1.validateFunctionCode)(schemaCxt);
5357 gen.optimize(this.opts.code.optimize);
5358 const validateCode = gen.toString();
5359 sourceCode = `${gen.scopeRefs(names_1.default.scope)}return ${validateCode}`;
5360 if (this.opts.code.process) sourceCode = this.opts.code.process(sourceCode, sch);
5361 const validate = new Function(`${names_1.default.self}`, `${names_1.default.scope}`, sourceCode)(this, this.scope.get());
5362 this.scope.value(validateName, { ref: validate });
LowEval
Package source references a known benign dynamic code generation pattern.
dist/bridge-NEdX_EzI.jsView on unpkg · L5360 5363 validate.errors = null;
5364 validate.schema = sch.schema;
5365 validate.schemaEnv = sch;
5366 if (sch.$async) validate.$async = true;
5367 if (this.opts.code.source === true) validate.source = {
5370 scopeValues: gen._values
5372 if (this.opts.unevaluated) {
5373 const { props, items } = schemaCxt;
5374 validate.evaluated = {
5375 props: props instanceof codegen_1.Name ? void 0 : props,
5376 items: items instanceof codegen_1.Name ? void 0 : items,
5377 dynamicProps: props instanceof codegen_1.Name,
5378 dynamicItems: items instanceof codegen_1.Name
5380 if (validate.source) validate.source.evaluated = (0, codegen_1.stringify)(validate.evaluated);