( rawExpr: string, scope: BaseScope, seen = new Set<unknown>(), shadowed?: ReadonlySet<string> )
| 1274 | } |
| 1275 | |
| 1276 | const evalStringTypeInScope = ( |
| 1277 | rawExpr: string, |
| 1278 | scope: BaseScope, |
| 1279 | seen = new Set<unknown>(), |
| 1280 | shadowed?: ReadonlySet<string> |
| 1281 | ): BaseRoot | undefined => { |
| 1282 | try { |
| 1283 | const expr = stripOuterParens(rawExpr) |
| 1284 | if (!expr) return undefined |
| 1285 | const unionParts = splitTopLevelOp(expr, "|") |
| 1286 | if (unionParts) { |
| 1287 | const roots: BaseRoot[] = [] |
| 1288 | for (const part of unionParts) { |
| 1289 | const r = evalStringTypeInScope(part, scope, new Set(seen), shadowed) |
| 1290 | if (!r) return undefined |
| 1291 | roots.push(r) |
| 1292 | } |
| 1293 | return roots.reduce((a, b) => a.or(b)) |
| 1294 | } |
| 1295 | const interParts = splitTopLevelOp(expr, "&") |
| 1296 | if (interParts) { |
| 1297 | const roots: BaseRoot[] = [] |
| 1298 | for (const part of interParts) { |
| 1299 | const r = evalStringTypeInScope(part, scope, new Set(seen), shadowed) |
| 1300 | if (!r) return undefined |
| 1301 | roots.push(r) |
| 1302 | } |
| 1303 | return roots.reduce((a, b) => a.and(b)) |
| 1304 | } |
| 1305 | if (expr.endsWith("[]")) { |
| 1306 | const inner = evalStringTypeInScope( |
| 1307 | expr.slice(0, -2), |
| 1308 | scope, |
| 1309 | seen, |
| 1310 | shadowed |
| 1311 | ) |
| 1312 | return inner?.array() |
| 1313 | } |
| 1314 | const lit = unescapeStringLiteral(expr) |
| 1315 | if (lit !== undefined) return type.unit(lit).internal |
| 1316 | // single generic instantiation spanning the whole expression |
| 1317 | const genMatch = /^([#$A-Z_a-z][\w#$.]*)\s*</.exec(expr) |
| 1318 | if (genMatch) { |
| 1319 | const ltIndex = genMatch[0].length - 1 |
| 1320 | const parsed = parseAngleArgs(expr, ltIndex) |
| 1321 | if (parsed && parsed.end === expr.length) { |
| 1322 | const target = lookupInScope(genMatch[1], scope, shadowed) |
| 1323 | if (hasArkKind(target, "generic")) { |
| 1324 | const argRoots: BaseRoot[] = [] |
| 1325 | for (const arg of parsed.args) { |
| 1326 | const r = evalStringTypeInScope(arg, scope, new Set(seen), shadowed) |
| 1327 | if (!r) return undefined |
| 1328 | argRoots.push(r) |
| 1329 | } |
| 1330 | const structural = structuralGenericOf(target) |
| 1331 | if (structural) return applyStructuralOp(structural[0], argRoots) |
| 1332 | return target(...argRoots) |
| 1333 | } |
no test coverage detected