MCPcopy Create free account
hub / github.com/arktypeio/arktype / evaluateObject

Method evaluateObject

ark/aot/interpreter.ts:791–891  ·  view source on GitHub ↗
(node: ObjectExpression, ctx: Context)

Source from the content-addressed store, hash-verified

789 }
790
791 private evaluateObject(node: ObjectExpression, ctx: Context): unknown {
792 const result: Record<PropertyKey, unknown> = {}
793 for (const property of node.properties) {
794 if (property.type === "SpreadElement") {
795 const spread = this.evaluate(property.argument, ctx)
796 if (isDynamic(spread)) return spread
797 if (
798 spread !== null &&
799 spread !== undefined &&
800 typeof spread !== "string" &&
801 !isPlainContainer(spread) &&
802 !hasArkKind(spread, "module")
803 ) {
804 return this.reject(
805 property,
806 ctx,
807 "spreads a value other than an object literal or Module"
808 )
809 }
810 const copy = this.admit({ ...(spread as object) }, property, ctx)
811 if (isDynamic(copy)) return copy
812 for (const k of Reflect.ownKeys(copy)) {
813 const problem = this.overwriteProblem(result, k, property, ctx)
814 if (problem) return problem
815 defineData(result, k, Reflect.get(copy, k))
816 }
817 if (hasDomain(spread, "object")) {
818 const inherited = this.spreadsByObject.get(spread)
819 if (inherited) this.spreadsByObject.set(result, inherited)
820 const inheritedStrings = this.stringPropsByObject.get(spread)
821 if (inheritedStrings) {
822 let target = this.stringPropsByObject.get(result)
823 if (!target) {
824 target = new Map()
825 this.stringPropsByObject.set(result, target)
826 }
827 for (const [k, source] of inheritedStrings) target.set(k, source)
828 }
829 }
830 continue
831 }
832 if (property.kind !== "init") {
833 return this.reject(
834 property,
835 ctx,
836 "is an accessor, which runs code when arktype reads the definition"
837 )
838 }
839 const key =
840 property.computed ? this.evaluate(property.key, ctx)
841 : property.key.type === "Identifier" ? property.key.name
842 : String((property.key as { value: unknown }).value)
843 if (isDynamic(key)) return key
844 if (hasDomain(key, "object")) return this.coercion(property.key, ctx)
845 if (
846 key === "__proto__" &&
847 !property.computed &&
848 !property.shorthand &&

Callers 1

evaluateNodeMethod · 0.95

Calls 13

evaluateMethod · 0.95
rejectMethod · 0.95
admitMethod · 0.95
overwriteProblemMethod · 0.95
coercionMethod · 0.95
isPlainContainerFunction · 0.90
hasArkKindFunction · 0.90
hasDomainFunction · 0.90
isDynamicFunction · 0.85
defineDataFunction · 0.85
StringInterface · 0.85
getMethod · 0.65

Tested by

no test coverage detected