From 417555c9e9a0aa185035dad70f762e71da291f03 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Sun, 26 Oct 2014 14:53:26 +0100 Subject: [PATCH 1/5] implemented treat warning as errors commandline option (warnaserror). --- src/compiler/commandLineParser.ts | 5 +++++ src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/tsc.ts | 8 ++++---- src/compiler/types.ts | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a7993484c647d..210c71541f306 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -113,6 +113,11 @@ module ts { type: "boolean", description: Diagnostics.Print_the_compiler_s_version, }, + { + name: "warnAsError", + type: "boolean", + description: Diagnostics.Report_all_warnings_as_errors, + }, { name: "watch", shortName: "w", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a5dda0b1f4b71..5ab076413cc19 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -364,6 +364,7 @@ module ts { Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, + Report_all_warnings_as_errors: { code: 6007, category: DiagnosticCategory.Message, key: "Report all warnings as errors." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1336af21aaf80..2442d21d206ca 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1456,6 +1456,10 @@ "category": "Message", "code": 6006 }, + "Report all warnings as errors.": { + "category": "Message", + "code": 6007 + }, "Do not emit comments to output.": { "category": "Message", "code": 6009 diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 15f231bc74ea9..dff2ac8d0b167 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -362,7 +362,10 @@ module ts { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); errors = checker.getDiagnostics(); - if (!checker.hasEarlyErrors()) { + if (checker.hasEarlyErrors() || (compilerOptions.warnAsError && errors.length > 0)) { + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; + } + else { var emitStart = new Date().getTime(); var emitOutput = checker.emitFiles(); var emitErrors = emitOutput.errors; @@ -370,9 +373,6 @@ module ts { var reportStart = new Date().getTime(); errors = concatenate(errors, emitErrors); } - else { - exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; - } } reportDiagnostics(errors); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index aa2ca3b4ba83a..d96a50b8e84d6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1092,6 +1092,7 @@ module ts { sourceRoot?: string; target?: ScriptTarget; version?: boolean; + warnAsError?: boolean; watch?: boolean; [option: string]: any; } From bd2c5965f524aad1db66612cb7120a56045fc6d2 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Mon, 27 Oct 2014 20:48:46 +0100 Subject: [PATCH 2/5] Changed name to noEmitOnError --- src/compiler/commandLineParser.ts | 10 +++++----- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/tsc.ts | 2 +- src/compiler/types.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 210c71541f306..ad6452d163979 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -54,6 +54,11 @@ module ts { paramType: Diagnostics.KIND, error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd }, + { + name: "noEmitOnError", + type: "boolean", + description: Diagnostics.Do_not_emit_JavaScript_on_error, + }, { name: "noImplicitAny", type: "boolean", @@ -113,11 +118,6 @@ module ts { type: "boolean", description: Diagnostics.Print_the_compiler_s_version, }, - { - name: "warnAsError", - type: "boolean", - description: Diagnostics.Report_all_warnings_as_errors, - }, { name: "watch", shortName: "w", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5ab076413cc19..3e464e62c3364 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -364,7 +364,7 @@ module ts { Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, - Report_all_warnings_as_errors: { code: 6007, category: DiagnosticCategory.Message, key: "Report all warnings as errors." }, + Do_not_emit_JavaScript_on_error: { code: 6007, category: DiagnosticCategory.Message, key: "Do not emit JavaScript on error." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2442d21d206ca..94bbe966f3035 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1456,7 +1456,7 @@ "category": "Message", "code": 6006 }, - "Report all warnings as errors.": { + "Do not emit JavaScript on error.": { "category": "Message", "code": 6007 }, diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index dff2ac8d0b167..e578448457e6f 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -362,7 +362,7 @@ module ts { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); errors = checker.getDiagnostics(); - if (checker.hasEarlyErrors() || (compilerOptions.warnAsError && errors.length > 0)) { + if (checker.hasEarlyErrors() || (compilerOptions.noEmitOnError && errors.length > 0)) { exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d96a50b8e84d6..07b230976ed18 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1080,6 +1080,7 @@ module ts { locale?: string; mapRoot?: string; module?: ModuleKind; + noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; @@ -1092,7 +1093,6 @@ module ts { sourceRoot?: string; target?: ScriptTarget; version?: boolean; - warnAsError?: boolean; watch?: boolean; [option: string]: any; } From e4f57569b721662841d6599474adcc6cc375e396 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Tue, 28 Oct 2014 19:45:18 +0100 Subject: [PATCH 3/5] addressed feedback --- src/compiler/checker.ts | 10 ++++++++-- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 6 +++--- src/compiler/tsc.ts | 2 +- src/compiler/types.ts | 4 ++-- src/harness/harness.ts | 6 ++---- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7a959c0dbfc4a..91b27812d046d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -109,7 +109,7 @@ module ts { getAliasedSymbol: resolveImport, isUndefinedSymbol: symbol => symbol === undefinedSymbol, isArgumentsSymbol: symbol => symbol === argumentsSymbol, - hasEarlyErrors: hasEarlyErrors + isEmitBlocked: isEmitBlocked }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -8316,6 +8316,12 @@ module ts { return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0; } + function isEmitBlocked(sourceFile?: SourceFile): boolean { + return program.getDiagnostics(sourceFile).length !== 0 || + hasEarlyErrors(sourceFile) || + (compilerOptions.noEmitOnError && getDiagnostics(sourceFile).length !== 0); + } + function hasEarlyErrors(sourceFile?: SourceFile): boolean { return forEach(getDiagnostics(sourceFile), d => d.isEarly); } @@ -8403,7 +8409,7 @@ module ts { getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName, hasSemanticErrors: hasSemanticErrors, - hasEarlyErrors: hasEarlyErrors, + isEmitBlocked: isEmitBlocked, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ad6452d163979..71d68c546d2e8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -57,7 +57,7 @@ module ts { { name: "noEmitOnError", type: "boolean", - description: Diagnostics.Do_not_emit_JavaScript_on_error, + description: Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported, }, { name: "noImplicitAny", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 3e464e62c3364..6184248645037 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -364,7 +364,7 @@ module ts { Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, - Do_not_emit_JavaScript_on_error: { code: 6007, category: DiagnosticCategory.Message, key: "Do not emit JavaScript on error." }, + Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6007, category: DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 94bbe966f3035..cfb30775251ad 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1456,7 +1456,7 @@ "category": "Message", "code": 6006 }, - "Do not emit JavaScript on error.": { + "Do not emit outputs if any type checking errors were reported.": { "category": "Message", "code": 6007 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1517584e4c85f..3ce39b951276f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3271,10 +3271,10 @@ module ts { } var hasSemanticErrors = resolver.hasSemanticErrors(); - var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile); + var isEmitBlocked = resolver.isEmitBlocked(targetSourceFile); function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - if (!hasEarlyErrors) { + if (!isEmitBlocked) { emitJavaScript(jsFilePath, sourceFile); if (!hasSemanticErrors && compilerOptions.declaration) { emitDeclarations(jsFilePath, sourceFile); @@ -3318,7 +3318,7 @@ module ts { // Check and update returnCode for syntactic and semantic var returnCode: EmitReturnStatus; - if (hasEarlyErrors) { + if (isEmitBlocked) { returnCode = EmitReturnStatus.AllOutputGenerationSkipped; } else if (hasEmitterError) { returnCode = EmitReturnStatus.EmitErrorsEncountered; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e578448457e6f..e5291c9d7f1b8 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -362,7 +362,7 @@ module ts { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); errors = checker.getDiagnostics(); - if (checker.hasEarlyErrors() || (compilerOptions.noEmitOnError && errors.length > 0)) { + if (checker.isEmitBlocked()) { exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 07b230976ed18..694294d2d122f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -666,7 +666,7 @@ module ts { isImplementationOfOverload(node: FunctionDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; - hasEarlyErrors(sourceFile?: SourceFile): boolean; + isEmitBlocked(sourceFile?: SourceFile): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. @@ -762,7 +762,7 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' if it does // resolve to a constant. getConstantValue(node: PropertyAccess): number; - hasEarlyErrors(sourceFile?: SourceFile): boolean; + isEmitBlocked(sourceFile?: SourceFile): boolean; } export enum SymbolFlags { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 60c5da5a1a68a..e1735a6ad6dac 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -796,16 +796,14 @@ module Harness { options.target, useCaseSensitiveFileNames)); - var hadParseErrors = program.getDiagnostics().length > 0; - var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); checker.checkProgram(); - var hasEarlyErrors = checker.hasEarlyErrors(); + var isEmitBlocked = checker.isEmitBlocked(); // only emit if there weren't parse errors var emitResult: ts.EmitResult; - if (!hadParseErrors && !hasEarlyErrors) { + if (!isEmitBlocked) { emitResult = checker.emitFiles(); } From 4c1397b9a61c03fbc17b7e8764d226236bab577f Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Thu, 30 Oct 2014 00:10:58 +0100 Subject: [PATCH 4/5] Added test for noEmitOnError --- src/harness/compilerRunner.ts | 13 ++++++++++++- src/harness/harness.ts | 6 +++++- tests/baselines/reference/noEmitOnError.errors.txt | 9 +++++++++ tests/cases/compiler/noEmitOnError.ts | 5 +++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/noEmitOnError.errors.txt create mode 100644 tests/cases/compiler/noEmitOnError.ts diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 6e2118924375f..01dc1208010df 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -175,7 +175,12 @@ class CompilerBaselineRunner extends RunnerBase { it('Correct sourcemap content for ' + fileName, () => { if (options.sourceMap) { Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => { - return result.getSourceMapRecord(); + var record = result.getSourceMapRecord(); + if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) { + // Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required. + return null; + } + return record; }); } }); @@ -246,6 +251,12 @@ class CompilerBaselineRunner extends RunnerBase { } Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => { + if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) { + // We need to return null here or the runBaseLine will actually create a empty file. + // Baselining isn't required here because there is no output. + return null; + } + var sourceMapCode = ''; for (var i = 0; i < result.sourceMaps.length; i++) { sourceMapCode += '//// [' + Harness.Path.getFileName(result.sourceMaps[i].fileName) + ']\r\n'; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index e1735a6ad6dac..b39682913b11a 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -703,6 +703,10 @@ module Harness { } break; + case 'noemitonerror': + options.noEmitOnError = !!setting.value; + break; + case 'noresolve': options.noResolve = !!setting.value; break; @@ -1145,7 +1149,7 @@ module Harness { var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines // List of allowed metadata names - var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames"]; + var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/tests/baselines/reference/noEmitOnError.errors.txt b/tests/baselines/reference/noEmitOnError.errors.txt new file mode 100644 index 0000000000000..e969a3fbbbc1f --- /dev/null +++ b/tests/baselines/reference/noEmitOnError.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/noEmitOnError.ts(2,5): error TS2323: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/noEmitOnError.ts (1 errors) ==== + + var x: number = ""; + ~ +!!! error TS2323: Type 'string' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tests/cases/compiler/noEmitOnError.ts b/tests/cases/compiler/noEmitOnError.ts new file mode 100644 index 0000000000000..b171a23c5b95b --- /dev/null +++ b/tests/cases/compiler/noEmitOnError.ts @@ -0,0 +1,5 @@ +// @noemitonerror: true +// @sourcemap: true +// @declaration: true + +var x: number = ""; From c90fb4a7d3b7fbbb813fdad1afa88d40e0ed08e4 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Sun, 16 Nov 2014 22:05:07 +0100 Subject: [PATCH 5/5] Update baseline --- tests/baselines/reference/noEmitOnError.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/noEmitOnError.errors.txt b/tests/baselines/reference/noEmitOnError.errors.txt index e969a3fbbbc1f..92a7151d74e2a 100644 --- a/tests/baselines/reference/noEmitOnError.errors.txt +++ b/tests/baselines/reference/noEmitOnError.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/noEmitOnError.ts(2,5): error TS2323: Type 'string' is not assignable to type 'number'. +tests/cases/compiler/noEmitOnError.ts(2,5): error TS2322: Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/noEmitOnError.ts (1 errors) ==== var x: number = ""; ~ -!!! error TS2323: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file