@@ -1537,21 +1537,24 @@ namespace ts {
15371537 const emitFilePath = toPath ( emitFileName , currentDirectory , getCanonicalFileName ) ;
15381538 // Report error if the output overwrites input file
15391539 if ( filesByName . contains ( emitFilePath ) ) {
1540- let chain : DiagnosticMessageChain ;
1541- if ( ! options . configFilePath ) {
1542- // The program is from either an inferred project or an external project
1543- chain = chainDiagnosticMessages ( /*details*/ undefined , Diagnostics . Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig ) ;
1540+ if ( options . noEmitOverwritenFiles && ! options . out && ! options . outDir && ! options . outFile ) {
1541+ blockEmittingOfFile ( emitFileName ) ;
1542+ }
1543+ else {
1544+ let chain : DiagnosticMessageChain ;
1545+ if ( ! options . configFilePath ) {
1546+ // The program is from either an inferred project or an external project
1547+ chain = chainDiagnosticMessages ( /*details*/ undefined , Diagnostics . Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig ) ;
1548+ }
1549+ chain = chainDiagnosticMessages ( chain , Diagnostics . Cannot_write_file_0_because_it_would_overwrite_input_file , emitFileName ) ;
1550+ blockEmittingOfFile ( emitFileName , createCompilerDiagnosticFromMessageChain ( chain ) ) ;
15441551 }
1545- chain = chainDiagnosticMessages ( chain , Diagnostics . Cannot_write_file_0_because_it_would_overwrite_input_file , emitFileName ) ;
1546- const diagnostic = createCompilerDiagnosticFromMessageChain ( chain ) ;
1547- createEmitBlockingDiagnostics ( emitFileName , diagnostic ) ;
15481552 }
15491553
15501554 // Report error if multiple files write into same file
15511555 if ( emitFilesSeen . contains ( emitFilePath ) ) {
15521556 // Already seen the same emit file - report error
1553- const diagnostic = createCompilerDiagnostic ( Diagnostics . Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files , emitFileName ) ;
1554- createEmitBlockingDiagnostics ( emitFileName , diagnostic ) ;
1557+ blockEmittingOfFile ( emitFileName , createCompilerDiagnostic ( Diagnostics . Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files , emitFileName ) ) ;
15551558 }
15561559 else {
15571560 emitFilesSeen . set ( emitFilePath , true ) ;
@@ -1560,9 +1563,11 @@ namespace ts {
15601563 }
15611564 }
15621565
1563- function createEmitBlockingDiagnostics ( emitFileName : string , diag : Diagnostic ) {
1566+ function blockEmittingOfFile ( emitFileName : string , diag ? : Diagnostic ) {
15641567 hasEmitBlockingDiagnostics . set ( toPath ( emitFileName , currentDirectory , getCanonicalFileName ) , true ) ;
1565- programDiagnostics . add ( diag ) ;
1568+ if ( diag ) {
1569+ programDiagnostics . add ( diag ) ;
1570+ }
15661571 }
15671572 }
15681573}
0 commit comments