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

Method inline

ark/aot/link.ts:1383–1478  ·  view source on GitHub ↗
(owner: Unit, binding: Binding, read: Read)

Source from the content-addressed store, hash-verified

1381 }
1382
1383 private inline(owner: Unit, binding: Binding, read: Read): boolean {
1384 const declarator = binding.declaration
1385 if (
1386 !binding.name.endsWith("Allows") ||
1387 binding.kind !== "const" ||
1388 declarator.type !== "VariableDeclarator" ||
1389 declarator.init?.type !== "CallExpression" ||
1390 !isAtTopLevel(read.reference.id) ||
1391 !isAtTopLevel(declarator)
1392 )
1393 return false
1394 const init = declarator.init
1395 const text = new MagicString(owner.module.source)
1396 const imports = new Map<string, string>()
1397 const exports: string[] = []
1398 for (const reference of owner.module.scopes.references) {
1399 const { id } = reference
1400 if (id.start < init.start || init.end < id.end) continue
1401 const outer = reference.binding
1402 // a global, which a binding of the reader's may shadow
1403 if (!outer) {
1404 if (namesBinding(read.unit, id.name)) return false
1405 continue
1406 }
1407 // e.g. a callback's parameter, or what the reader's own module declares
1408 if (outer.scope !== owner.module.scopes.root || read.unit === owner)
1409 continue
1410 const source = importSourceOf(outer)
1411 let local: string | undefined
1412 if (source === "arktype/runtime" && isNamespaceImport(outer))
1413 local = this.localOf(read.unit, outer.name, `* as`, source, imports)
1414 else if (source?.startsWith("~arktype/") && !isNamespaceImport(outer)) {
1415 local = this.localOf(
1416 read.unit,
1417 outer.name,
1418 importedNameOf(outer),
1419 source,
1420 imports,
1421 this.declarationOf(owner, outer)?.[1]
1422 )
1423 } else if (outer.kind === "const") {
1424 local = this.localOf(
1425 read.unit,
1426 outer.name,
1427 outer.name,
1428 owner.key,
1429 imports,
1430 outer
1431 )
1432 const exported = owner.module.scopes.exportsByName[outer.name]
1433 if (!exported) exports.push(outer.name)
1434 // e.g. `export { other as name }`, which an import of it would read
1435 else if (exported.kind !== "binding" || exported.binding !== outer)
1436 return false
1437 } else if (
1438 source !== undefined &&
1439 outer.kind === "import" &&
1440 !isNamespaceImport(outer)

Callers 1

linkMethod · 0.95

Calls 13

localOfMethod · 0.95
declarationOfMethod · 0.95
allowsReadOfMethod · 0.95
isAtTopLevelFunction · 0.85
namesBindingFunction · 0.85
importSourceOfFunction · 0.85
isNamespaceImportFunction · 0.85
addImportsFunction · 0.85
testMethod · 0.80
importedNameOfFunction · 0.70
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected