(ir: SemanticIR, factPath: string)
| 37 | * `createUserGroup` is a different function. |
| 38 | */ |
| 39 | export function runtimeCitationsFor(ir: SemanticIR, factPath: string): Evidence[] { |
| 40 | const match = /^(steps|calls)\[(\d+)\]$/.exec(factPath); |
| 41 | const runtime = ir.runtime; |
| 42 | if (!match || runtime === undefined) { |
| 43 | return []; |
| 44 | } |
| 45 | const calls = match[1] === 'steps' ? ir.steps.value : ir.calls.value; |
| 46 | const call = calls[Number(match[2])]; |
| 47 | if (call === undefined) { |
| 48 | return []; |
| 49 | } |
| 50 | // Only trust the row index when the two arrays line up, exactly as the |
| 51 | // evidence lookups do: a mislabelled citation is worse than no citation. |
| 52 | if (runtime.value.length !== runtime.evidence.length) { |
| 53 | return []; |
| 54 | } |
| 55 | const out: Evidence[] = []; |
| 56 | runtime.value.forEach((observed, index) => { |
| 57 | if (sameSymbol(observed.targetName, call.targetName) |
| 58 | || sameSymbol(observed.targetQualifiedName, call.targetQualifiedName) |
| 59 | || sameSymbol(observed.targetQualifiedName, call.targetName) |
| 60 | || sameSymbol(observed.targetName, call.targetQualifiedName)) { |
| 61 | out.push(runtime.evidence[index]); |
| 62 | } |
| 63 | }); |
| 64 | return out; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Whether two written names denote the same symbol. |
no test coverage detected