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

Function checkStringGenericDrops

ark/aot/droppedNarrow.ts:1351–1383  ·  view source on GitHub ↗
(
	expr: string,
	scope: BaseScope,
	shadowed?: ReadonlySet<string>
)

Source from the content-addressed store, hash-verified

1349}
1350
1351const checkStringGenericDrops = (
1352 expr: string,
1353 scope: BaseScope,
1354 shadowed?: ReadonlySet<string>
1355): { op: DroppedNarrowOp; operand: string }[] => {
1356 const drops: { op: DroppedNarrowOp; operand: string }[] = []
1357 for (const call of scanStringGenerics(expr)) {
1358 const target = lookupInScope(call.name, scope, shadowed)
1359 if (!hasArkKind(target, "generic")) continue
1360 const info = structuralGenericOf(target)
1361 if (!info) continue
1362 const [op, argIndices] = info
1363 if (call.args.length !== target.params.length) continue
1364 const argRoots: BaseRoot[] = []
1365 let allResolved = true
1366 for (const arg of call.args) {
1367 const r = evalStringTypeInScope(arg, scope, new Set(), shadowed)
1368 if (!r) {
1369 allResolved = false
1370 break
1371 }
1372 argRoots.push(r)
1373 }
1374 if (!allResolved) continue
1375 const after = applyStructuralOp(op, argRoots)
1376 if (!after) continue
1377 for (const idx of argIndices) {
1378 if (dropsUserPredicate(argRoots[idx], after))
1379 drops.push({ op, operand: call.args[idx] })
1380 }
1381 }
1382 return drops
1383}
1384
1385export const isDropNarrowSuppressed = (
1386 module: SourceModule,

Callers 2

recordStringGenericDropFunction · 0.85

Calls 8

hasArkKindFunction · 0.90
scanStringGenericsFunction · 0.85
lookupInScopeFunction · 0.85
structuralGenericOfFunction · 0.85
evalStringTypeInScopeFunction · 0.85
applyStructuralOpFunction · 0.85
dropsUserPredicateFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected