(str: string)
| 1062 | |
| 1063 | // find every generic instantiation in a string expression (innermost args scanned too) |
| 1064 | const 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>"` |
| 1101 | const genericParamNamesOfKey = (key: PropertyKey): Set<string> | undefined => { |
no test coverage detected