@@ -2,6 +2,7 @@ import { LoggingContext, ptypes, SourceLocation, TypeResolver } from '@algorandf
22import path from 'path'
33import ts from 'typescript'
44import type { TypeInfo } from '../encoders'
5+ import type { DeliberateAny } from '../typescript-helpers'
56import { instanceOfAny } from '../typescript-helpers'
67import type { TransformerConfig } from './index'
78import { nodeFactory } from './node-factory'
@@ -39,9 +40,11 @@ export class SourceFileVisitor {
3940 program : ts . Program ,
4041 private config : TransformerConfig ,
4142 ) {
42- const typeChecker = program . getTypeChecker ( )
43+ // ts-jest would pass a TsCompilerInstance as program parameter whereas rollup-plugin-typescript would pass a ts.Program
44+ const programInstance = ( Object . hasOwn ( program , 'program' ) ? ( program as DeliberateAny ) . program : program ) as ts . Program
45+ const typeChecker = programInstance . getTypeChecker ( )
4346 const loggingContext = LoggingContext . create ( )
44- const typeResolver = new TypeResolver ( typeChecker , program . getCurrentDirectory ( ) )
47+ const typeResolver = new TypeResolver ( typeChecker , programInstance . getCurrentDirectory ( ) )
4548 this . helper = {
4649 additionalStatements : [ ] ,
4750 resolveType ( node : ts . Node ) : ptypes . PType {
@@ -59,7 +62,7 @@ export class SourceFileVisitor {
5962 return s && s . flags & ts . SymbolFlags . Alias ? typeChecker . getAliasedSymbol ( s ) : s
6063 } ,
6164 sourceLocation ( node : ts . Node ) : SourceLocation {
62- return SourceLocation . fromNode ( node , program . getCurrentDirectory ( ) )
65+ return SourceLocation . fromNode ( node , programInstance . getCurrentDirectory ( ) )
6366 } ,
6467 }
6568 }
0 commit comments