Skip to content

Commit 80bab05

Browse files
author
Yui
committed
Merge pull request #699 from Microsoft/reportDeclarationEmitErrors
Report declaration emit errors
2 parents 7aac8d5 + 3721382 commit 80bab05

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/services/services.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,9 @@ module ts {
15981598
}
15991599

16001600
// Only perform incremental parsing on open files that are being edited. If a file was
1601-
// open, but is now closed, we want to reparse entirely so we don't have any tokens that
1601+
// open, but is now closed, we want to re-parse entirely so we don't have any tokens that
16021602
// are holding onto expensive script snapshot instances on the host. Similarly, if a
1603-
// file was closed, then we always want to reparse. This is so our tree doesn't keep
1603+
// file was closed, then we always want to re-parse. This is so our tree doesn't keep
16041604
// the old buffer alive that represented the file on disk (as the host has moved to a
16051605
// new text buffer).
16061606
var textChangeRange: TypeScript.TextChangeRange = null;
@@ -1650,12 +1650,29 @@ module ts {
16501650
return program.getDiagnostics(getSourceFile(filename).getSourceFile());
16511651
}
16521652

1653+
// getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors
1654+
// If '-d' enabled, report both semantic and emitter errors
16531655
function getSemanticDiagnostics(filename: string) {
16541656
synchronizeHostData();
16551657

16561658
filename = TypeScript.switchToForwardSlashes(filename)
1657-
1658-
return getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename));
1659+
var compilerOptions = program.getCompilerOptions();
1660+
var checker = getFullTypeCheckChecker();
1661+
var targetSourceFile = getSourceFile(filename);
1662+
1663+
// Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file.
1664+
// Therefore only get diagnostics for given file.
1665+
1666+
var allDiagnostics = checker.getDiagnostics(targetSourceFile);
1667+
if (compilerOptions.declaration) {
1668+
// If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface
1669+
// Get emitter-diagnostics requires calling TypeChecker.emitFiles so we have to define CompilerHost.writer which does nothing because emitFiles function has side effects defined by CompilerHost.writer
1670+
var savedWriter = writer;
1671+
writer = (filename: string, data: string, writeByteOrderMark: boolean) => { };
1672+
allDiagnostics = allDiagnostics.concat(checker.emitFiles(targetSourceFile).errors);
1673+
writer = savedWriter;
1674+
}
1675+
return allDiagnostics
16591676
}
16601677

16611678
function getCompilerOptionsDiagnostics() {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @declaration: true
4+
//// interface privateInterface {}
5+
//// export class Bar implements /*1*/privateInterface/*2*/{ }
6+
7+
verify.errorExistsBetweenMarkers("1", "2");
8+
verify.numberOfErrorsInCurrentFile(1);
9+
10+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// interface privateInterface {}
4+
//// export class Bar implements /*1*/privateInterface/*2*/{ }
5+
6+
verify.numberOfErrorsInCurrentFile(0);
7+
8+

0 commit comments

Comments
 (0)