From fad0db2a0bfce141badfbb88d9056f323f85eb96 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 10 Sep 2015 09:21:01 -0700 Subject: [PATCH] Report error if output file is among the input files --- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/emitter.ts | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index af48e67d964..59f97a9a6ef 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -513,6 +513,7 @@ namespace ts { Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." }, Option_0_cannot_be_specified_with_option_1: { code: 5053, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." }, A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, + Could_not_write_file_0_which_is_one_of_the_input_files: { code: 5054, category: DiagnosticCategory.Error, key: "Could not write file '{0}' which is one of the input files." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7abec7b7c43..b0c877799c9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2042,6 +2042,10 @@ "category": "Error", "code": 5053 }, + "Could not write file '{0}' which is one of the input files.": { + "category": "Error", + "code": 5054 + }, "Concatenate and emit output to single file.": { "category": "Message", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d84b7b70ada..a37401b9fae 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7153,6 +7153,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { + if (forEach(host.getSourceFiles(), sourceFile => jsFilePath === sourceFile.fileName)) { + // TODO(shkamat) Verify if this works if same file is referred via different paths ..\foo\a.js and a.js refering to same one + // Report error and dont emit this file + diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_which_is_one_of_the_input_files, jsFilePath)); + return; + } + emitJavaScript(jsFilePath, sourceFile); if (compilerOptions.declaration) {