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

Function scanStringGenerics

ark/aot/droppedNarrow.ts:1064–1098  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

1062
1063// find every generic instantiation in a string expression (innermost args scanned too)
1064const scanStringGenerics = (str: string): StringGenericCall[] => {
1065 const found: StringGenericCall[] = []
1066 const scan = (s: string) => {
1067 let i = 0
1068 while (i < s.length) {
1069 const ch = s[i]
1070 if (ch === "'" || ch === '"' || ch === "/") {
1071 i = skipQuotedOrRegex(s, i)
1072 continue
1073 }
1074 if (isIdentStart(ch)) {
1075 const start = i
1076 i++
1077 while (i < s.length && isIdentPart(s[i])) i++
1078 const name = s.slice(start, i)
1079 let j = i
1080 while (j < s.length && /\s/.test(s[j])) j++
1081 if (s[j] === "<" && s[j + 1] !== "=") {
1082 const parsed = parseAngleArgs(s, j)
1083 if (parsed) {
1084 for (const arg of parsed.args) if (arg.includes("<")) scan(arg)
1085
1086 found.push({ name, args: parsed.args })
1087 i = parsed.end
1088 continue
1089 }
1090 }
1091 continue
1092 }
1093 i++
1094 }
1095 }
1096 scan(str)
1097 return found
1098}
1099
1100// extract parameter names from a scope generic key like `"MyPartial<t, k extends string>"`
1101const genericParamNamesOfKey = (key: PropertyKey): Set<string> | undefined => {

Callers 1

checkStringGenericDropsFunction · 0.85

Calls 1

scanFunction · 0.85

Tested by

no test coverage detected