( file: ts.SourceFile, benchBlock: ts.FunctionExpression | ts.ArrowFunction )
| 109 | const instantiationsByPath: { [path: string]: number } = {} |
| 110 | |
| 111 | export const getInstantiationsContributedByNode = ( |
| 112 | file: ts.SourceFile, |
| 113 | benchBlock: ts.FunctionExpression | ts.ArrowFunction |
| 114 | ): number => { |
| 115 | const originalPath = filePath(file.fileName) |
| 116 | const fakePath = originalPath + ".nonexistent.ts" |
| 117 | |
| 118 | const baselineFile = getBaselineSourceFile(file) |
| 119 | |
| 120 | const baselineFileWithBenchBlock = |
| 121 | baselineFile + `\nconst $attestIsolatedBench = ${benchBlock.getFullText()}` |
| 122 | |
| 123 | if (!instantiationsByPath[fakePath]) { |
| 124 | const instantiationsWithoutNode = getInstantiationsWithFile( |
| 125 | baselineFile, |
| 126 | fakePath |
| 127 | ) |
| 128 | |
| 129 | instantiationsByPath[fakePath] = instantiationsWithoutNode |
| 130 | } |
| 131 | |
| 132 | const instantiationsWithNode = getInstantiationsWithFile( |
| 133 | baselineFileWithBenchBlock, |
| 134 | fakePath, |
| 135 | // a generic block's result would be inferred from constraints it's |
| 136 | // never called with |
| 137 | !benchBlock.typeParameters?.length |
| 138 | ) |
| 139 | |
| 140 | return instantiationsWithNode - instantiationsByPath[fakePath] |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * TS only evaluates the members of many types, e.g. mapped types, once |
no test coverage detected