Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented treat warning as errors commandline option. #966

Merged
merged 6 commits into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -8984,6 +8984,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);
}
Expand Down Expand Up @@ -9080,7 +9086,7 @@ module ts {
getEnumMemberValue: getEnumMemberValue,
isTopLevelValueImportWithEntityName: isTopLevelValueImportWithEntityName,
hasSemanticErrors: hasSemanticErrors,
hasEarlyErrors: hasEarlyErrors,
isEmitBlocked: isEmitBlocked,
isDeclarationVisible: isDeclarationVisible,
isImplementationOfOverload: isImplementationOfOverload,
writeTypeAtLocation: writeTypeAtLocation,
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_outputs_if_any_type_checking_errors_were_reported,
},
{
name: "noImplicitAny",
type: "boolean",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ module ts {
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_erase_const_enum_declarations_in_generated_code: { code: 6007, category: DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." },
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." },
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'" },
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,10 @@
"category": "Message",
"code": 6007
},
"Do not emit outputs if any type checking errors were reported.": {
"category": "Message",
"code": 6008
},
"Do not emit comments to output.": {
"category": "Message",
"code": 6009
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3463,10 +3463,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);
Expand Down Expand Up @@ -3510,7 +3510,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;
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,17 @@ module ts {
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
var checkStart = new Date().getTime();
errors = checker.getDiagnostics();
if (!checker.hasEarlyErrors()) {
if (checker.isEmitBlocked()) {
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
}
else {
var emitStart = new Date().getTime();
var emitOutput = checker.emitFiles();
var emitErrors = emitOutput.errors;
exitStatus = emitOutput.emitResultStatus;
var reportStart = new Date().getTime();
errors = concatenate(errors, emitErrors);
}
else {
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
}
}

reportDiagnostics(errors);
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ module ts {
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
hasEarlyErrors(sourceFile?: SourceFile): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
isEmitBlocked(sourceFile?: SourceFile): boolean;
// Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value.
getEnumMemberValue(node: EnumMember): number;
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
Expand Down Expand Up @@ -823,7 +823,7 @@ module ts {
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
getConstantValue(node: PropertyAccess | IndexedAccess): number;
hasEarlyErrors(sourceFile?: SourceFile): boolean;
isEmitBlocked(sourceFile?: SourceFile): boolean;
}

export const enum SymbolFlags {
Expand Down Expand Up @@ -1156,6 +1156,7 @@ module ts {
locale?: string;
mapRoot?: string;
module?: ModuleKind;
noEmitOnError?: boolean;
noErrorTruncation?: boolean;
noImplicitAny?: boolean;
noLib?: boolean;
Expand Down
13 changes: 12 additions & 1 deletion src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a situation in which record can be undefined but the condition options.noEmitOnError && result.errors.length !== 0 evaluates to false? Perhaps a || is more appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if || is more appropriate here, when for example noEmitOnError is true and there are errors and record is not undefined (because getSourceMapRecord returned a sourcemap).. then it should actually try to compare them right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, do you actually get an empty sourcemap file if you don't perform this check?

Sorry, I'm personally not familiar enough with the harness code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it did, runBaseline calls generateActual: https://github.com/Microsoft/TypeScript/blob/5ce3baf339e0424263069c70f0ea239bc3cea96a/src/harness/harness.ts#L1307 which creates the file when it is something different than null. It throws an error when it is undefined.

// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
return null;
}
return record;
});
}
});
Expand Down Expand Up @@ -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';
Expand Down
12 changes: 7 additions & 5 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ module Harness {
}
break;

case 'noemitonerror':
options.noEmitOnError = !!setting.value;
break;

case 'noresolve':
options.noResolve = !!setting.value;
break;
Expand Down Expand Up @@ -794,16 +798,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();
}

Expand Down Expand Up @@ -1148,7 +1150,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", "preserveconstenums"];
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror","noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums"];

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

Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/noEmitOnError.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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 TS2322: Type 'string' is not assignable to type 'number'.

5 changes: 5 additions & 0 deletions tests/cases/compiler/noEmitOnError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @noemitonerror: true
// @sourcemap: true
// @declaration: true

var x: number = "";