( file: ts.SourceFile, assertionsByFile: Record<string, any[]>, instantiationMethodCalls: string[] )
| 43 | * Preserves any JSDoc comments that are associated with the original expression |
| 44 | */ |
| 45 | export const gatherInlineInstantiationData = ( |
| 46 | file: ts.SourceFile, |
| 47 | assertionsByFile: Record<string, any[]>, |
| 48 | instantiationMethodCalls: string[] |
| 49 | ): void => { |
| 50 | const expressions = getCallExpressionsByName(file, instantiationMethodCalls) |
| 51 | if (!expressions.length) return |
| 52 | |
| 53 | const enclosingFunctions = expressions.map(expression => { |
| 54 | const attestInstantiationsExpression = getFirstAncestorByKindOrThrow( |
| 55 | expression, |
| 56 | ts.SyntaxKind.ExpressionStatement |
| 57 | ) |
| 58 | return { |
| 59 | ancestor: getFirstAncestorByKindOrThrow( |
| 60 | attestInstantiationsExpression, |
| 61 | ts.SyntaxKind.ExpressionStatement |
| 62 | ), |
| 63 | position: getCallLocationFromCallExpression(expression) |
| 64 | } |
| 65 | }) |
| 66 | const instantiationInfo = enclosingFunctions.map(enclosingFunction => { |
| 67 | const body = getDescendants(enclosingFunction.ancestor).find( |
| 68 | node => ts.isArrowFunction(node) || ts.isFunctionExpression(node) |
| 69 | ) as ts.ArrowFunction | ts.FunctionExpression | undefined |
| 70 | if (!body) { |
| 71 | throwInternalError( |
| 72 | `Unable to resolve source associated with TS Node: |
| 73 | ${enclosingFunction.ancestor.getText()}` |
| 74 | ) |
| 75 | } |
| 76 | |
| 77 | return { |
| 78 | location: enclosingFunction.position, |
| 79 | count: getInstantiationsContributedByNode(file, body) |
| 80 | } |
| 81 | }) |
| 82 | const assertions = assertionsByFile[getFileKey(file.fileName)] ?? [] |
| 83 | assertionsByFile[getFileKey(file.fileName)] = [ |
| 84 | ...assertions, |
| 85 | ...instantiationInfo |
| 86 | ] |
| 87 | } |
| 88 | |
| 89 | export const getCallExpressionsByName = ( |
| 90 | startNode: ts.Node, |
no test coverage detected