( tokenScores: Record<string, Record<string, number>>, fileCallsMap: Map<string, string[]>, )
| 278 | } |
| 279 | |
| 280 | function buildTokenCallers( |
| 281 | tokenScores: Record<string, Record<string, number>>, |
| 282 | fileCallsMap: Map<string, string[]>, |
| 283 | ): TokenCallerMap { |
| 284 | const tokenDefinitionMap = new Map<string, string>() |
| 285 | const highestScores = new Map<string, number>() |
| 286 | |
| 287 | for (const [filePath, scores] of Object.entries(tokenScores)) { |
| 288 | for (const [token, score] of Object.entries(scores)) { |
| 289 | const currentHighestScore = highestScores.get(token) ?? -Infinity |
| 290 | if (score > currentHighestScore) { |
| 291 | highestScores.set(token, score) |
| 292 | tokenDefinitionMap.set(token, filePath) |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | const tokenCallers: TokenCallerMap = {} |
| 298 | for (const [callingFile, calls] of fileCallsMap.entries()) { |
| 299 | for (const call of calls) { |
| 300 | const definingFile = tokenDefinitionMap.get(call) |
| 301 | if (!definingFile || callingFile === definingFile || call in {}) { |
| 302 | continue |
| 303 | } |
| 304 | |
| 305 | const callersByToken = (tokenCallers[definingFile] ??= {}) |
| 306 | const callerFiles = (callersByToken[call] ??= []) |
| 307 | if ( |
| 308 | callerFiles.length < MAX_CALLERS && |
| 309 | !callerFiles.includes(callingFile) |
| 310 | ) { |
| 311 | callerFiles.push(callingFile) |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | return tokenCallers |
| 317 | } |
| 318 | |
| 319 | function boostScoresByExternalCalls( |
| 320 | tokenScores: Record<string, Record<string, number>>, |
no test coverage detected