From 5fbc6d7f7284bb6feb05500ab2157fc7d379edca Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 1 Nov 2016 13:54:16 -0700 Subject: [PATCH 1/5] WIP --- src/compiler/program.ts | 14 +++++++++++--- src/compiler/types.ts | 1 + src/server/project.ts | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d7e4a4c2701d1..c289cff2c23d4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1537,7 +1537,13 @@ namespace ts { const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { - createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); + const sourceFile = filesByName.get(emitFilePath); + if (isSourceFileJavaScript(sourceFile) && options.noEmitForJsFiles) { + createEmitBlockingDiagnostics(emitFileName); + } + else { + createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); + } } // Report error if multiple files write into same file @@ -1552,9 +1558,11 @@ namespace ts { } } - function createEmitBlockingDiagnostics(emitFileName: string, message: DiagnosticMessage) { + function createEmitBlockingDiagnostics(emitFileName: string, message?: DiagnosticMessage) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); - programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); + if (message) { + programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); + } } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e6c13235c9b8a..8b93cc132e820 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2984,6 +2984,7 @@ namespace ts { moduleResolution?: ModuleResolutionKind; newLine?: NewLineKind; noEmit?: boolean; + /*@internal*/noEmitForJsFiles?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; diff --git a/src/server/project.ts b/src/server/project.ts index 5f4f8d4049027..640c3a6369bfc 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -161,6 +161,10 @@ namespace ts.server { this.compilerOptions.allowNonTsExtensions = true; } + if (this.projectKind === ProjectKind.Inferred) { + this.compilerOptions.noEmitForJsFiles = true; + } + if (languageServiceEnabled) { this.enableLanguageService(); } From 5268b75a17a5f45fb64fa80ff9cf704cd8f3a949 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 1 Nov 2016 14:12:37 -0700 Subject: [PATCH 2/5] Properly naming things --- src/compiler/program.ts | 10 +++++----- src/compiler/types.ts | 2 +- src/server/project.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c289cff2c23d4..8bd4d9e8f5043 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1538,18 +1538,18 @@ namespace ts { // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { const sourceFile = filesByName.get(emitFilePath); - if (isSourceFileJavaScript(sourceFile) && options.noEmitForJsFiles) { - createEmitBlockingDiagnostics(emitFileName); + if (isSourceFileJavaScript(sourceFile) && options.noEmitOverwriteForJsFiles) { + blockEmitingOfFile(emitFileName); } else { - createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); + blockEmitingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); } } // Report error if multiple files write into same file if (emitFilesSeen.contains(emitFilePath)) { // Already seen the same emit file - report error - createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); + blockEmitingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); } else { emitFilesSeen.set(emitFilePath, true); @@ -1558,7 +1558,7 @@ namespace ts { } } - function createEmitBlockingDiagnostics(emitFileName: string, message?: DiagnosticMessage) { + function blockEmitingOfFile(emitFileName: string, message?: DiagnosticMessage) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); if (message) { programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8b93cc132e820..1457b2e65f622 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2984,7 +2984,7 @@ namespace ts { moduleResolution?: ModuleResolutionKind; newLine?: NewLineKind; noEmit?: boolean; - /*@internal*/noEmitForJsFiles?: boolean; + /*@internal*/noEmitOverwriteForJsFiles?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; diff --git a/src/server/project.ts b/src/server/project.ts index 640c3a6369bfc..c303fad5e99a7 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -162,7 +162,7 @@ namespace ts.server { } if (this.projectKind === ProjectKind.Inferred) { - this.compilerOptions.noEmitForJsFiles = true; + this.compilerOptions.noEmitOverwriteForJsFiles = true; } if (languageServiceEnabled) { From 0c723094919258712f3205e82b8b8b3fdc2e8852 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 1 Nov 2016 15:38:41 -0700 Subject: [PATCH 3/5] refactor --- src/compiler/program.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8bd4d9e8f5043..90edae31f5910 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1538,18 +1538,13 @@ namespace ts { // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { const sourceFile = filesByName.get(emitFilePath); - if (isSourceFileJavaScript(sourceFile) && options.noEmitOverwriteForJsFiles) { - blockEmitingOfFile(emitFileName); - } - else { - blockEmitingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); - } + blockEmittingOfFile(emitFileName, !(options.noEmitOverwriteForJsFiles && isSourceFileJavaScript(sourceFile)) && Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); } // Report error if multiple files write into same file if (emitFilesSeen.contains(emitFilePath)) { // Already seen the same emit file - report error - blockEmitingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); + blockEmittingOfFile(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); } else { emitFilesSeen.set(emitFilePath, true); @@ -1558,7 +1553,7 @@ namespace ts { } } - function blockEmitingOfFile(emitFileName: string, message?: DiagnosticMessage) { + function blockEmittingOfFile(emitFileName: string, message?: DiagnosticMessage) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); if (message) { programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); From a874a6d43b94a4fa60373e434d3bf0e4033c71ab Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Wed, 2 Nov 2016 11:05:37 -0700 Subject: [PATCH 4/5] apply the option to all files and check out options --- src/compiler/program.ts | 3 +-- src/compiler/types.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 22613d2942478..3b6ae08984a7f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1537,8 +1537,7 @@ namespace ts { const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { - const sourceFile = filesByName.get(emitFilePath); - if (options.noEmitOverwriteForJsFiles && isSourceFileJavaScript(sourceFile)) { + if (options.noEmitOverwritenFiles && !options.out && !options.outDir && !options.outFile) { blockEmittingOfFile(emitFileName); } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1457b2e65f622..458173d88f1a6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2984,7 +2984,7 @@ namespace ts { moduleResolution?: ModuleResolutionKind; newLine?: NewLineKind; noEmit?: boolean; - /*@internal*/noEmitOverwriteForJsFiles?: boolean; + /*@internal*/noEmitOverwritenFiles?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; From c266897aaeacc2ee88cbfc500848b642bb55b3fe Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 2 Nov 2016 11:34:58 -0700 Subject: [PATCH 5/5] Fix typo --- src/server/project.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/project.ts b/src/server/project.ts index c303fad5e99a7..8b134d3fe1cc3 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -162,7 +162,7 @@ namespace ts.server { } if (this.projectKind === ProjectKind.Inferred) { - this.compilerOptions.noEmitOverwriteForJsFiles = true; + this.compilerOptions.noEmitOverwritenFiles = true; } if (languageServiceEnabled) {