import type ts from 'typescript' ; import { Logger } from '../../logger/logger' ; import { ILogger } from '../../logger/logger.interface' ; import { GetCurrentCreateMock } from '../mock/currentCreateMockNode' ; let logger ; export interface TransformerLogger { circularGenericNotSupported ( nodeName ) : void ; unexpectedCreateMock ( mockFileName , expectedFileName ) : void ; typeNotSupported ( type , currentNode ? ) : void ; typeOfFunctionCallNotFound ( node ) : void ; typeOfPropertyNotFound ( node ) : void ; missingTypeDefinition ( node ) : void ; missingReturnFromFunctionLike ( node ) : void ; typeCannotBeChecked ( node ) : void ; indexedAccessTypeFailed ( propertyName , nodeText , currentNode ) : void ; } const notSupportedTypeMessage = ( type , createMockFileUrl , currentNodeFileUrl ) => `Not supported type: ${ type } - it will convert to null
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ; const warningPositionLog = ( createMockFileUrl , currentNodeFileUrl ) => `created ${ createMockFileUrl }
used by ${ currentNodeFileUrl }` ; export const getNodeFileUrl = ( node ) => { const sourceFile = node . getSourceFile ( ) ; const { line , character } = sourceFile . getLineAndCharacterOfPosition ( node . getStart ( ) ) ; return `file://${ sourceFile . fileName }:${ line + 1 }:${ character + 1 }` ; } ; export function TransformerLogger ( ) { logger = logger || Logger ( 'Transformer' ) ; return { circularGenericNotSupported ( nodeName ) { logger . warning ( `Found a circular generic of \`${ nodeName }' and such generics are currently not supported. 
        The generated mock will be incomplete.` ) ; } , unexpectedCreateMock ( mockFileName , expectedFileName ) { logger . warning ( `I\'ve found a mock creator but it comes from a different folder
            found: ${ mockFileName }
            expected: ${ expectedFileName }` ) ; } , typeNotSupported ( type , currentNode ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( currentNode ) ; logger . warning ( notSupportedTypeMessage ( type , createMockFileUrl , currentNodeFileUrl ) ) ; } , typeOfFunctionCallNotFound ( node ) { logger . warning ( `Cannot find type of function call: ${ node } - it will convert to null` ) ; } , typeOfPropertyNotFound ( node ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( node ) ; logger . warning ( `The transformer could not determine a property value for ${ node . getText ( ) } without a specified type nor an initializer value - it will convert to null
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ) ; } , indexedAccessTypeFailed ( propertyName , nodeText , currentNode ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( currentNode ) ; logger . warning ( `IndexedAccessType transformation failed: cannot find property ${ propertyName } of - ${ nodeText }
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ) ; } , missingTypeDefinition ( node ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( node ) ; logger . warning ( `Type definition for type reference ${ node . getText ( ) } not found - it will convert to null
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ) ; } , missingReturnFromFunctionLike ( node ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( node ) ; logger . warning ( `Node body or return type for type reference ${ node . getText ( ) } not found - it will convert to null
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ) ; } , typeCannotBeChecked ( node ) { const createMockNode = GetCurrentCreateMock ( ) ; const createMockFileUrl = getNodeFileUrl ( createMockNode ) ; const currentNodeFileUrl = getNodeFileUrl ( node ) ; logger . warning ( `the type to type node conversion returned a type that will fail to convert because it cannot be analyzed ${ node . getText ( ) } not found - it will convert to null
${ warningPositionLog ( createMockFileUrl , currentNodeFileUrl ) }` ) ; } , } ; }