import * as ts from 'typescript' ; const transformerProgram = ( program ) => { const typeChecker = program . getTypeChecker ( ) ; const foundSymbols = new Array < ts . Symbol > ( ) ; const transformerFactory = context => { return sourceFile => { const visitor = ( node ) : ts . Node => { if ( ts . isIdentifier ( node ) ) { const relatedSymbol = typeChecker . getSymbolAtLocation ( node ) ; if ( foundSymbols . includes ( relatedSymbol ) ) { const foundIndex = foundSymbols . indexOf ( relatedSymbol ) ; console . log ( `Found existing symbol at position = ${ foundIndex } and name = "${ relatedSymbol . name }"` ) ; } else { foundSymbols . push ( relatedSymbol ) ; console . log ( `Found new symbol with name = "${ relatedSymbol . name }". Added at positon = ${ foundSymbols . length - 1 }` ) ; } return node ; } return ts . visitEachChild ( node , visitor , context ) ; } ; return ts . visitNode ( sourceFile , visitor ) ; } ; } ; return transformerFactory ; } ; export default transformerProgram ;