import ts from 'typescript' ; export function isAbsolute ( filename ) { return ( filename [ 0 ] === '/' ) ; } export function isRelative ( filename ) { return ( filename [ 0 ] === '.' ) ; } export function isAmbientImport ( filename ) { return ( isAmbient ( filename ) && ! isTypescriptDeclaration ( filename ) ) ; } export function isAmbientReference ( filename ) { return ( isAmbient ( filename ) && isTypescriptDeclaration ( filename ) ) ; } export function isAmbient ( filename ) { return ( ! isRelative ( filename ) && ! isAbsolute ( filename ) ) ; } const typescriptRegex = /\.tsx?$/i ; export function isTypescript ( filename ) { return typescriptRegex . test ( filename ) ; } const javascriptRegex = /\.js$/i ; export function isJavaScript ( filename ) { return javascriptRegex . test ( filename ) ; } const jsxRegex = /\.jsx$/i ; export function isJSX ( filename ) { return jsxRegex . test ( filename ) ; } const mapRegex = /\.map$/i ; export function isSourceMap ( filename ) { return mapRegex . test ( filename ) ; } const declarationRegex = /\.d\.tsx?$/i ; export function isTypescriptDeclaration ( filename ) { return declarationRegex . test ( filename ) ; } const jsonRegex = /\.json$/i ; export function isJson ( filename ) { return jsonRegex . test ( filename ) ; } export function tsToJs ( tsFile ) { return tsFile . replace ( typescriptRegex , '.js' ) ; } export function tsToJsMap ( tsFile ) { return tsFile . replace ( typescriptRegex , '.js.map' ) ; } const convertRegex = /\.[^\.]+$/ ; export function convertToDts ( anyFile ) { return anyFile . replace ( convertRegex , '.d.ts' ) ; } export function getExtension ( normalized ) { const baseName = ( ts as any ) . getBaseFileName ( normalized ) ; const parts = baseName . split ( '.' ) ; return parts . length > 1 ? parts . pop ( ) : undefined ; } export function stripDoubleExtension ( normalized ) { const parts = normalized . split ( '.' ) ; if ( parts . length > 1 ) { const extensions = [ "js" , "jsx" , "ts" , "tsx" , "json" ] ; if ( extensions . indexOf ( parts [ parts . length - 2 ] ) >= 0 ) { return parts . slice ( 0 , - 1 ) . join ( '.' ) ; } } return normalized ; } export function hasError ( diags ) { return diags . some ( diag => ( diag . category === ts . DiagnosticCategory . Error ) ) ; }