Skip to content

Commit d5cfceb

Browse files
committed
Merge pull request #966 from DickvdBrink/warnaserror
implemented treat warning as errors commandline option.
2 parents 9a5df85 + c90fb4a commit d5cfceb

11 files changed

+62
-18
lines changed

Diff for: src/compiler/checker.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module ts {
109109
getAliasedSymbol: resolveImport,
110110
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
111111
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
112-
hasEarlyErrors: hasEarlyErrors
112+
isEmitBlocked: isEmitBlocked
113113
};
114114

115115
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -8984,6 +8984,12 @@ module ts {
89848984
return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0;
89858985
}
89868986

8987+
function isEmitBlocked(sourceFile?: SourceFile): boolean {
8988+
return program.getDiagnostics(sourceFile).length !== 0 ||
8989+
hasEarlyErrors(sourceFile) ||
8990+
(compilerOptions.noEmitOnError && getDiagnostics(sourceFile).length !== 0);
8991+
}
8992+
89878993
function hasEarlyErrors(sourceFile?: SourceFile): boolean {
89888994
return forEach(getDiagnostics(sourceFile), d => d.isEarly);
89898995
}
@@ -9080,7 +9086,7 @@ module ts {
90809086
getEnumMemberValue: getEnumMemberValue,
90819087
isTopLevelValueImportWithEntityName: isTopLevelValueImportWithEntityName,
90829088
hasSemanticErrors: hasSemanticErrors,
9083-
hasEarlyErrors: hasEarlyErrors,
9089+
isEmitBlocked: isEmitBlocked,
90849090
isDeclarationVisible: isDeclarationVisible,
90859091
isImplementationOfOverload: isImplementationOfOverload,
90869092
writeTypeAtLocation: writeTypeAtLocation,

Diff for: src/compiler/commandLineParser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ module ts {
5454
paramType: Diagnostics.KIND,
5555
error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd
5656
},
57+
{
58+
name: "noEmitOnError",
59+
type: "boolean",
60+
description: Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported,
61+
},
5762
{
5863
name: "noImplicitAny",
5964
type: "boolean",

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ module ts {
373373
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
374374
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
375375
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." },
376+
Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." },
376377
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
377378
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)" },
378379
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,10 @@
14901490
"category": "Message",
14911491
"code": 6007
14921492
},
1493+
"Do not emit outputs if any type checking errors were reported.": {
1494+
"category": "Message",
1495+
"code": 6008
1496+
},
14931497
"Do not emit comments to output.": {
14941498
"category": "Message",
14951499
"code": 6009

Diff for: src/compiler/emitter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3463,10 +3463,10 @@ module ts {
34633463
}
34643464

34653465
var hasSemanticErrors = resolver.hasSemanticErrors();
3466-
var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile);
3466+
var isEmitBlocked = resolver.isEmitBlocked(targetSourceFile);
34673467

34683468
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
3469-
if (!hasEarlyErrors) {
3469+
if (!isEmitBlocked) {
34703470
emitJavaScript(jsFilePath, sourceFile);
34713471
if (!hasSemanticErrors && compilerOptions.declaration) {
34723472
emitDeclarations(jsFilePath, sourceFile);
@@ -3510,7 +3510,7 @@ module ts {
35103510

35113511
// Check and update returnCode for syntactic and semantic
35123512
var returnCode: EmitReturnStatus;
3513-
if (hasEarlyErrors) {
3513+
if (isEmitBlocked) {
35143514
returnCode = EmitReturnStatus.AllOutputGenerationSkipped;
35153515
} else if (hasEmitterError) {
35163516
returnCode = EmitReturnStatus.EmitErrorsEncountered;

Diff for: src/compiler/tsc.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,17 @@ module ts {
362362
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
363363
var checkStart = new Date().getTime();
364364
errors = checker.getDiagnostics();
365-
if (!checker.hasEarlyErrors()) {
365+
if (checker.isEmitBlocked()) {
366+
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
367+
}
368+
else {
366369
var emitStart = new Date().getTime();
367370
var emitOutput = checker.emitFiles();
368371
var emitErrors = emitOutput.errors;
369372
exitStatus = emitOutput.emitResultStatus;
370373
var reportStart = new Date().getTime();
371374
errors = concatenate(errors, emitErrors);
372375
}
373-
else {
374-
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
375-
}
376376
}
377377

378378
reportDiagnostics(errors);

Diff for: src/compiler/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ module ts {
731731
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
732732
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
733733
isUndefinedSymbol(symbol: Symbol): boolean;
734-
isArgumentsSymbol(symbol: Symbol): boolean;
735-
hasEarlyErrors(sourceFile?: SourceFile): boolean;
734+
isArgumentsSymbol(symbol: Symbol): boolean;
735+
isEmitBlocked(sourceFile?: SourceFile): boolean;
736736
// Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value.
737737
getEnumMemberValue(node: EnumMember): number;
738738
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
@@ -823,7 +823,7 @@ module ts {
823823
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
824824
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
825825
getConstantValue(node: PropertyAccess | IndexedAccess): number;
826-
hasEarlyErrors(sourceFile?: SourceFile): boolean;
826+
isEmitBlocked(sourceFile?: SourceFile): boolean;
827827
}
828828

829829
export const enum SymbolFlags {
@@ -1156,6 +1156,7 @@ module ts {
11561156
locale?: string;
11571157
mapRoot?: string;
11581158
module?: ModuleKind;
1159+
noEmitOnError?: boolean;
11591160
noErrorTruncation?: boolean;
11601161
noImplicitAny?: boolean;
11611162
noLib?: boolean;

Diff for: src/harness/compilerRunner.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ class CompilerBaselineRunner extends RunnerBase {
175175
it('Correct sourcemap content for ' + fileName, () => {
176176
if (options.sourceMap) {
177177
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => {
178-
return result.getSourceMapRecord();
178+
var record = result.getSourceMapRecord();
179+
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
180+
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
181+
return null;
182+
}
183+
return record;
179184
});
180185
}
181186
});
@@ -246,6 +251,12 @@ class CompilerBaselineRunner extends RunnerBase {
246251
}
247252

248253
Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => {
254+
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
255+
// We need to return null here or the runBaseLine will actually create a empty file.
256+
// Baselining isn't required here because there is no output.
257+
return null;
258+
}
259+
249260
var sourceMapCode = '';
250261
for (var i = 0; i < result.sourceMaps.length; i++) {
251262
sourceMapCode += '//// [' + Harness.Path.getFileName(result.sourceMaps[i].fileName) + ']\r\n';

Diff for: src/harness/harness.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ module Harness {
700700
}
701701
break;
702702

703+
case 'noemitonerror':
704+
options.noEmitOnError = !!setting.value;
705+
break;
706+
703707
case 'noresolve':
704708
options.noResolve = !!setting.value;
705709
break;
@@ -794,16 +798,14 @@ module Harness {
794798
options.target,
795799
useCaseSensitiveFileNames));
796800

797-
var hadParseErrors = program.getDiagnostics().length > 0;
798-
799801
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
800802
checker.checkProgram();
801803

802-
var hasEarlyErrors = checker.hasEarlyErrors();
804+
var isEmitBlocked = checker.isEmitBlocked();
803805

804806
// only emit if there weren't parse errors
805807
var emitResult: ts.EmitResult;
806-
if (!hadParseErrors && !hasEarlyErrors) {
808+
if (!isEmitBlocked) {
807809
emitResult = checker.emitFiles();
808810
}
809811

@@ -1148,7 +1150,7 @@ module Harness {
11481150
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
11491151

11501152
// List of allowed metadata names
1151-
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums"];
1153+
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror","noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums"];
11521154

11531155
function extractCompilerSettings(content: string): CompilerSetting[] {
11541156

Diff for: tests/baselines/reference/noEmitOnError.errors.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/noEmitOnError.ts(2,5): error TS2322: Type 'string' is not assignable to type 'number'.
2+
3+
4+
==== tests/cases/compiler/noEmitOnError.ts (1 errors) ====
5+
6+
var x: number = "";
7+
~
8+
!!! error TS2322: Type 'string' is not assignable to type 'number'.
9+

Diff for: tests/cases/compiler/noEmitOnError.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @noemitonerror: true
2+
// @sourcemap: true
3+
// @declaration: true
4+
5+
var x: number = "";

0 commit comments

Comments
 (0)