MCPcopy Create free account
hub / github.com/Effect-TS/effect / referenceResolution

Function referenceResolution

packages/tools/api-diff/src/Snapshot.ts:76–103  ·  view source on GitHub ↗
(name: ts.EntityName, context: SerializationContext)

Source from the content-addressed store, hash-verified

74 [...values].sort((left, right) => stableJson(left).localeCompare(stableJson(right)))
75
76const referenceResolution = (name: ts.EntityName, context: SerializationContext): unknown => {
77 let symbol = context.checker.getSymbolAtLocation(name)
78 if (symbol === undefined) {
79 return { unresolved: true }
80 }
81 if ((symbol.flags & ts.SymbolFlags.Alias) !== 0) {
82 symbol = context.checker.getAliasedSymbol(symbol)
83 }
84 const declaration = symbol?.declarations?.[0]
85 if (declaration === undefined) {
86 return { unresolved: true }
87 }
88 const publicApiId = context.publicSymbols.get(symbolIdentity(symbol, "type")) ??
89 context.publicSymbols.get(symbolIdentity(symbol, "value"))
90 if (publicApiId !== undefined) {
91 return { apiId: publicApiId }
92 }
93 const file = declaration.getSourceFile().fileName
94 const separator = context.path.sep
95 const nodeModules = file.lastIndexOf(`${separator}node_modules${separator}`)
96 if (nodeModules !== -1) {
97 const remainder = file.slice(nodeModules + `${separator}node_modules${separator}`.length).split(separator)
98 return {
99 externalPackage: remainder[0]?.startsWith("@") ? remainder.slice(0, 2).join("/") : remainder[0]
100 }
101 }
102 return { declaration: normalizedPath(context.path, context.repoRoot, file) }
103}
104
105const primitiveKinds = new Map<ts.SyntaxKind, string>([
106 [ts.SyntaxKind.AnyKeyword, "any"],

Callers 1

serializeTypeFunction · 0.85

Calls 5

symbolIdentityFunction · 0.85
normalizedPathFunction · 0.85
joinMethod · 0.80
getMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected