Skip to content

Commit 0d2a5bb

Browse files
Merge pull request #2431 from Microsoft/noEmitOnErrorCompileOnSave
No emit should happen if there are declaration errors and noEmitOnErrors is specified.
2 parents 79272d7 + 791a0e4 commit 0d2a5bb

12 files changed

+67
-53
lines changed

src/compiler/core.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ module ts {
122122
}
123123

124124
export function addRange<T>(to: T[], from: T[]): void {
125-
for (let v of from) {
126-
to.push(v);
125+
if (to && from) {
126+
for (let v of from) {
127+
to.push(v);
128+
}
127129
}
128130
}
129131

src/compiler/program.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ module ts {
8787

8888
export function getPreEmitDiagnostics(program: Program): Diagnostic[] {
8989
let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics());
90+
91+
if (program.getCompilerOptions().declaration) {
92+
diagnostics.concat(program.getDeclarationDiagnostics());
93+
}
94+
9095
return sortAndDeduplicateDiagnostics(diagnostics);
9196
}
9297

@@ -178,11 +183,6 @@ module ts {
178183
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
179184
}
180185

181-
function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
182-
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile);
183-
return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile);
184-
}
185-
186186
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult {
187187
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
188188
// immediately bail out.
@@ -232,6 +232,10 @@ module ts {
232232
return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile);
233233
}
234234

235+
function getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
236+
return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile);
237+
}
238+
235239
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
236240
return sourceFile.parseDiagnostics;
237241
}
@@ -247,6 +251,15 @@ module ts {
247251
return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics);
248252
}
249253

254+
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
255+
if (!isDeclarationFile(sourceFile)) {
256+
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
257+
// Don't actually write any files since we're just getting diagnostics.
258+
var writeFile: WriteFileCallback = () => { };
259+
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
260+
}
261+
}
262+
250263
function getGlobalDiagnostics(): Diagnostic[] {
251264
let typeChecker = getDiagnosticsProducingTypeChecker();
252265

src/compiler/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,14 @@ module ts {
10051005
getSourceFiles(): SourceFile[];
10061006

10071007
/**
1008-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
1009-
* the javascript and declaration files will be produced for all the files in this program.
1010-
* If targetSourceFile is specified, then only the javascript and declaration for that
1008+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
1009+
* the JavaScript and declaration files will be produced for all the files in this program.
1010+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
10111011
* specific file will be generated.
10121012
*
10131013
* If writeFile is not specified then the writeFile callback from the compiler host will be
1014-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
1015-
* will be invoked when writing the javascript and declaration files.
1014+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
1015+
* will be invoked when writing the JavaScript and declaration files.
10161016
*/
10171017
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
10181018

src/services/services.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4914,7 +4914,6 @@ module ts {
49144914
synchronizeHostData();
49154915

49164916
let sourceFile = getValidSourceFile(fileName);
4917-
49184917
let outputFiles: OutputFile[] = [];
49194918

49204919
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) {

tests/baselines/reference/APISample_compile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,14 @@ declare module "typescript" {
801801
interface Program extends ScriptReferenceHost {
802802
getSourceFiles(): SourceFile[];
803803
/**
804-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
805-
* the javascript and declaration files will be produced for all the files in this program.
806-
* If targetSourceFile is specified, then only the javascript and declaration for that
804+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
805+
* the JavaScript and declaration files will be produced for all the files in this program.
806+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
807807
* specific file will be generated.
808808
*
809809
* If writeFile is not specified then the writeFile callback from the compiler host will be
810-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
811-
* will be invoked when writing the javascript and declaration files.
810+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
811+
* will be invoked when writing the JavaScript and declaration files.
812812
*/
813813
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
814814
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];

tests/baselines/reference/APISample_compile.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,14 +2440,14 @@ declare module "typescript" {
24402440
>SourceFile : SourceFile
24412441

24422442
/**
2443-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
2444-
* the javascript and declaration files will be produced for all the files in this program.
2445-
* If targetSourceFile is specified, then only the javascript and declaration for that
2443+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
2444+
* the JavaScript and declaration files will be produced for all the files in this program.
2445+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
24462446
* specific file will be generated.
24472447
*
24482448
* If writeFile is not specified then the writeFile callback from the compiler host will be
2449-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
2450-
* will be invoked when writing the javascript and declaration files.
2449+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
2450+
* will be invoked when writing the JavaScript and declaration files.
24512451
*/
24522452
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
24532453
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult

tests/baselines/reference/APISample_linter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -832,14 +832,14 @@ declare module "typescript" {
832832
interface Program extends ScriptReferenceHost {
833833
getSourceFiles(): SourceFile[];
834834
/**
835-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
836-
* the javascript and declaration files will be produced for all the files in this program.
837-
* If targetSourceFile is specified, then only the javascript and declaration for that
835+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
836+
* the JavaScript and declaration files will be produced for all the files in this program.
837+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
838838
* specific file will be generated.
839839
*
840840
* If writeFile is not specified then the writeFile callback from the compiler host will be
841-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
842-
* will be invoked when writing the javascript and declaration files.
841+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
842+
* will be invoked when writing the JavaScript and declaration files.
843843
*/
844844
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
845845
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];

tests/baselines/reference/APISample_linter.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,14 +2586,14 @@ declare module "typescript" {
25862586
>SourceFile : SourceFile
25872587

25882588
/**
2589-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
2590-
* the javascript and declaration files will be produced for all the files in this program.
2591-
* If targetSourceFile is specified, then only the javascript and declaration for that
2589+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
2590+
* the JavaScript and declaration files will be produced for all the files in this program.
2591+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
25922592
* specific file will be generated.
25932593
*
25942594
* If writeFile is not specified then the writeFile callback from the compiler host will be
2595-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
2596-
* will be invoked when writing the javascript and declaration files.
2595+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
2596+
* will be invoked when writing the JavaScript and declaration files.
25972597
*/
25982598
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
25992599
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult

tests/baselines/reference/APISample_transform.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,14 @@ declare module "typescript" {
833833
interface Program extends ScriptReferenceHost {
834834
getSourceFiles(): SourceFile[];
835835
/**
836-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
837-
* the javascript and declaration files will be produced for all the files in this program.
838-
* If targetSourceFile is specified, then only the javascript and declaration for that
836+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
837+
* the JavaScript and declaration files will be produced for all the files in this program.
838+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
839839
* specific file will be generated.
840840
*
841841
* If writeFile is not specified then the writeFile callback from the compiler host will be
842-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
843-
* will be invoked when writing the javascript and declaration files.
842+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
843+
* will be invoked when writing the JavaScript and declaration files.
844844
*/
845845
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
846846
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];

tests/baselines/reference/APISample_transform.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,14 +2536,14 @@ declare module "typescript" {
25362536
>SourceFile : SourceFile
25372537

25382538
/**
2539-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
2540-
* the javascript and declaration files will be produced for all the files in this program.
2541-
* If targetSourceFile is specified, then only the javascript and declaration for that
2539+
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
2540+
* the JavaScript and declaration files will be produced for all the files in this program.
2541+
* If targetSourceFile is specified, then only the JavaScript and declaration for that
25422542
* specific file will be generated.
25432543
*
25442544
* If writeFile is not specified then the writeFile callback from the compiler host will be
2545-
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
2546-
* will be invoked when writing the javascript and declaration files.
2545+
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
2546+
* will be invoked when writing the JavaScript and declaration files.
25472547
*/
25482548
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
25492549
>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult

0 commit comments

Comments
 (0)