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

Function evalDefInScope

ark/aot/droppedNarrow.ts:1238–1274  ·  view source on GitHub ↗
(
	def: unknown,
	scope: BaseScope,
	seen: Set<unknown>
)

Source from the content-addressed store, hash-verified

1236}
1237
1238const evalDefInScope = (
1239 def: unknown,
1240 scope: BaseScope,
1241 seen: Set<unknown>
1242): BaseRoot | undefined => {
1243 try {
1244 if (hasArkKind(def, "root")) return def
1245 if (typeof def === "string") return evalStringTypeInScope(def, scope, seen)
1246 if (seen.has(def)) return undefined
1247 if (Array.isArray(def)) {
1248 seen.add(def)
1249 if (def.length === 3 && def[1] === ":") {
1250 const base = evalDefInScope(def[0], scope, seen)
1251 if (base && typeof def[2] === "function")
1252 return base.narrow(def[2] as never)
1253 return base
1254 }
1255 if (def.length === 3 && def[1] === "@")
1256 return evalDefInScope(def[0], scope, seen)
1257 if (def.length === 3 && def[1] === "&") {
1258 const l = evalDefInScope(def[0], scope, new Set(seen))
1259 const r = evalDefInScope(def[2], scope, new Set(seen))
1260 return l && r ? l.and(r) : undefined
1261 }
1262 if (def.length === 3 && def[1] === "|") {
1263 const l = evalDefInScope(def[0], scope, new Set(seen))
1264 const r = evalDefInScope(def[2], scope, new Set(seen))
1265 return l && r ? l.or(r) : undefined
1266 }
1267 return undefined
1268 }
1269 if (isPlainContainer(def)) return type.raw(def).internal
1270 } catch {
1271 return undefined
1272 }
1273 return undefined
1274}
1275
1276const evalStringTypeInScope = (
1277 rawExpr: string,

Callers 1

evalStringTypeInScopeFunction · 0.85

Calls 9

hasArkKindFunction · 0.90
isPlainContainerFunction · 0.90
evalStringTypeInScopeFunction · 0.85
narrowMethod · 0.80
orMethod · 0.80
rawMethod · 0.80
andMethod · 0.65
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected