@@ -1537,21 +1537,24 @@ namespace ts {
1537
1537
const emitFilePath = toPath ( emitFileName , currentDirectory , getCanonicalFileName ) ;
1538
1538
// Report error if the output overwrites input file
1539
1539
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 ) ) ;
1544
1551
}
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 ) ;
1548
1552
}
1549
1553
1550
1554
// Report error if multiple files write into same file
1551
1555
if ( emitFilesSeen . contains ( emitFilePath ) ) {
1552
1556
// 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 ) ) ;
1555
1558
}
1556
1559
else {
1557
1560
emitFilesSeen . set ( emitFilePath , true ) ;
@@ -1560,9 +1563,11 @@ namespace ts {
1560
1563
}
1561
1564
}
1562
1565
1563
- function createEmitBlockingDiagnostics ( emitFileName : string , diag : Diagnostic ) {
1566
+ function blockEmittingOfFile ( emitFileName : string , diag ? : Diagnostic ) {
1564
1567
hasEmitBlockingDiagnostics . set ( toPath ( emitFileName , currentDirectory , getCanonicalFileName ) , true ) ;
1565
- programDiagnostics . add ( diag ) ;
1568
+ if ( diag ) {
1569
+ programDiagnostics . add ( diag ) ;
1570
+ }
1566
1571
}
1567
1572
}
1568
1573
}
0 commit comments