namespace ts . pxtc { let reportDiagnostic = reportDiagnosticSimply ; function reportDiagnostics ( diagnostics ) { for ( const diagnostic of diagnostics ) { reportDiagnostic ( diagnostic ) ; } } function reportDiagnosticSimply ( diagnostic ) { let output = getDiagnosticString ( diagnostic ) ; sys . write ( output ) ; } export function getDiagnosticString ( diagnostic ) { let ksDiagnostic ; if ( isTsDiagnostic ( diagnostic ) ) { let tsDiag = diagnostic as ts . Diagnostic ; const { line , character } = getLineAndCharacterOfPosition ( tsDiag . file , tsDiag . start ) ; const relativeFileName = tsDiag . file . fileName ; ksDiagnostic = Object . assign ( { fileName : relativeFileName , line : line , column : character } , tsDiag ) ; } else { ksDiagnostic = Object . assign ( { fileName : undefined , line : undefined , column : undefined } , diagnostic ) ; } return getDiagnosticStringHelper ( ksDiagnostic ) ; } function getDiagnosticStringHelper ( diagnostic ) { let output = "" ; if ( diagnostic . fileName ) { output += `${ diagnostic . fileName }(${ diagnostic . line + 1 },${ diagnostic . column + 1 }): ` ; } let nl = sys ? sys . newLine : "\n" ; const category = DiagnosticCategory [ diagnostic . category ] . toLowerCase ( ) ; output += `${ category } TS${ diagnostic . code }: ${ flattenDiagnosticMessageText ( diagnostic . messageText , nl ) }${ nl }` ; return output ; } function isTsDiagnostic ( a ) { return ( a as any ) . file !== undefined ; } export function plainTscCompileDir ( dir ) { const commandLine = parseCommandLine ( [ ] ) ; let configFileName = findConfigFile ( dir , sys . fileExists ) ; const configParseResult = parseConfigFile ( ) ; let program = plainTscCompileFiles ( configParseResult . fileNames , configParseResult . options ) ; let diagnostics = getProgramDiagnostics ( program ) ; diagnostics . forEach ( reportDiagnostic ) ; return program ; function parseConfigFile ( ) { let cachedConfigFileText = sys . readFile ( configFileName ) ; const result = parseConfigFileTextToJson ( configFileName , cachedConfigFileText ) ; const configObject = result . config ; if ( ! configObject ) { reportDiagnostics ( [ result . error ] ) ; sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ; return undefined ; } const configParseResult = parseJsonConfigFileContent ( configObject , sys , dir , commandLine . options , configFileName ) ; if ( configParseResult . errors . length > 0 ) { reportDiagnostics ( configParseResult . errors ) ; sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ; return undefined ; } return configParseResult ; } } export function plainTscCompileFiles ( fileNames , compilerOpts ) { const compilerHost = createCompilerHost ( compilerOpts ) ; compilerHost . getDefaultLibFileName = ( ) => "node_modules/pxt-core/pxtcompiler/ext-typescript/lib/lib.d.ts" ; let prog = createProgram ( fileNames , compilerOpts , compilerHost ) ; return prog ; } export function getProgramDiagnostics ( program ) { let diagnostics = program . getSyntacticDiagnostics ( ) ; if ( diagnostics . length === 0 ) { diagnostics = program . getOptionsDiagnostics ( ) . concat ( Util . toArray ( program . getGlobalDiagnostics ( ) ) ) ; if ( diagnostics . length === 0 ) { diagnostics = program . getSemanticDiagnostics ( ) ; } } return diagnostics . slice ( 0 ) ; } }