import * as ts from "typescript" ; export namespace TsCore { export function fileExtensionIs ( path , extension ) { let pathLen = path . length ; let extLen = extension . length ; return pathLen > extLen && path . substr ( pathLen - extLen , extLen ) === extension ; } export const supportedExtensions = [ ".ts" , ".tsx" , ".d.ts" ] ; export const moduleFileExtensions = supportedExtensions ; export function isSupportedSourceFileName ( fileName ) { if ( ! fileName ) { return false ; } for ( let extension of supportedExtensions ) { if ( fileExtensionIs ( fileName , extension ) ) { return true ; } } return false ; } export function getSourceFileFromSymbol ( symbol ) { const declarations = symbol . getDeclarations ( ) ; if ( declarations && declarations . length > 0 ) { if ( declarations [ 0 ] . kind === ts . SyntaxKind . SourceFile ) { return declarations [ 0 ] . getSourceFile ( ) ; } } return undefined ; } export function getExternalModuleName ( node ) { if ( node . kind === ts . SyntaxKind . ImportDeclaration ) { return ( < ts . ImportDeclaration > node ) . moduleSpecifier ; } if ( node . kind === ts . SyntaxKind . ImportEqualsDeclaration ) { let reference = ( < ts . ImportEqualsDeclaration > node ) . moduleReference ; if ( reference . kind === ts . SyntaxKind . ExternalModuleReference ) { return ( < ts . ExternalModuleReference > reference ) . expression ; } } if ( node . kind === ts . SyntaxKind . ExportDeclaration ) { return ( < ts . ExportDeclaration > node ) . moduleSpecifier ; } return undefined ; } export function createDiagnostic ( message , ... args ) { let textUnique123 = message . message ; if ( arguments . length > 1 ) { textUnique123 = formatStringFromArgs ( textUnique123 , arguments , 1 ) ; } return { file : undefined , start : undefined , length : undefined , messageText : textUnique123 , category : message . category , code : message . code } ; } function formatStringFromArgs ( text , args , baseIndex ) { baseIndex = baseIndex || 0 ; return text . replace ( /{(\d+)}/g , function ( match , index ) { return args [ + index + baseIndex ] ; } ) ; } export function isAliasSymbolDeclaration ( node ) { return node . kind === ts . SyntaxKind . ImportEqualsDeclaration || node . kind === ts . SyntaxKind . ImportClause && ! ! ( < ts . ImportClause > node ) . name || node . kind === ts . SyntaxKind . NamespaceImport || node . kind === ts . SyntaxKind . ImportSpecifier || node . kind === ts . SyntaxKind . ExportSpecifier || node . kind === ts . SyntaxKind . ExportAssignment && ( < ts . ExportAssignment > node ) . expression . kind === ts . SyntaxKind . Identifier ; } export function normalizeSlashes ( path ) { return path . replace ( /\\/g , "/" ) ; } export function outputExtension ( path ) { return path . replace ( /\.ts/ , ".js" ) ; } }