import ts from 'typescript' ; import * as node_ from './node' ; import * as statement from './statement' ; import * as utils from './utils' ; export function getSourceFiles ( program ) { return program . getSourceFiles ( ) ; } export function getSourceFile ( program , fileName ) { return utils . getValueOrUndefined ( program . getSourceFile ( fileName ) ) ; } export function getSourceFileOrThrow ( program , fileName ) { return utils . throwIfNullOrUndefined ( getSourceFile ( program , fileName ) , `source file: ${ fileName }` ) ; } export function isDeclarationFile ( node ) { return node . isDeclarationFile ; } export function getFilePath ( node ) { return node . fileName ; } export function getText ( node ) { return node_ . getSourceFile ( node ) . getFullText ( ) ; } export function getImportDeclarations ( node ) { return statement . getStatements ( node ) . filter ( ts . isImportDeclaration ) ; } export function getExportDeclarations ( node ) { return statement . getStatements ( node ) . filter ( ts . isExportDeclaration ) ; } export function getExportAssignments ( node ) { return statement . getStatements ( node ) . filter ( ts . isExportAssignment ) ; } export function createSourceMapRange ( node ) { const file = node_ . getSourceFile ( node ) as ts . SourceFile | undefined ; return { pos : node . pos , end : node . end , source : file === undefined ? undefined : ts . createSourceMapSource ( getFilePath ( file ) , getText ( node ) ) } ; } export function getExportedSymbols ( typeChecker , node ) { const symbol = node_ . getSymbol ( typeChecker , node ) ; return symbol === undefined ? [ ] : typeChecker . getExportsOfModule ( symbol ) ; }