Skip to content

Commit 3a9bc99

Browse files
Merge pull request microsoft#3558 from Microsoft/diagnosticCleanup2
Make it so all our diagnostics APIs return an independent set of diagnostics.
2 parents b743d05 + c4f65f8 commit 3a9bc99

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ namespace ts {
159159
}
160160
};
161161

162+
let subtypeRelation: Map<RelationComparisonResult> = {};
163+
let assignableRelation: Map<RelationComparisonResult> = {};
164+
let identityRelation: Map<RelationComparisonResult> = {};
165+
166+
initializeTypeChecker();
167+
168+
return checker;
169+
162170
function getEmitResolver(sourceFile?: SourceFile) {
163171
// Ensure we have all the type information in place for this file so that all the
164172
// emitter questions of this resolver will return the right information.
@@ -4221,10 +4229,6 @@ namespace ts {
42214229

42224230
// TYPE CHECKING
42234231

4224-
let subtypeRelation: Map<RelationComparisonResult> = {};
4225-
let assignableRelation: Map<RelationComparisonResult> = {};
4226-
let identityRelation: Map<RelationComparisonResult> = {};
4227-
42284232
function isTypeIdenticalTo(source: Type, target: Type): boolean {
42294233
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
42304234
}
@@ -13614,9 +13618,5 @@ namespace ts {
1361413618
return true;
1361513619
}
1361613620
}
13617-
13618-
initializeTypeChecker();
13619-
13620-
return checker;
1362113621
}
1362213622
}

src/compiler/program.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ namespace ts {
105105
}
106106

107107
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] {
108-
let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
108+
let diagnostics = program.getOptionsDiagnostics().concat(
109+
program.getSyntacticDiagnostics(sourceFile),
110+
program.getGlobalDiagnostics(),
111+
program.getSemanticDiagnostics(sourceFile));
109112

110113
if (program.getCompilerOptions().declaration) {
111114
diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
@@ -177,10 +180,10 @@ namespace ts {
177180
getSourceFiles: () => files,
178181
getCompilerOptions: () => options,
179182
getSyntacticDiagnostics,
183+
getOptionsDiagnostics,
180184
getGlobalDiagnostics,
181185
getSemanticDiagnostics,
182186
getDeclarationDiagnostics,
183-
getCompilerOptionsDiagnostics,
184187
getTypeChecker,
185188
getClassifiableNames,
186189
getDiagnosticsProducingTypeChecker,
@@ -311,19 +314,15 @@ namespace ts {
311314
}
312315
}
313316

314-
function getCompilerOptionsDiagnostics(): Diagnostic[] {
317+
function getOptionsDiagnostics(): Diagnostic[] {
315318
let allDiagnostics: Diagnostic[] = [];
316319
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
317320
return sortAndDeduplicateDiagnostics(allDiagnostics);
318321
}
319322

320323
function getGlobalDiagnostics(): Diagnostic[] {
321-
let typeChecker = getDiagnosticsProducingTypeChecker();
322-
323324
let allDiagnostics: Diagnostic[] = [];
324-
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
325-
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
326-
325+
addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
327326
return sortAndDeduplicateDiagnostics(allDiagnostics);
328327
}
329328

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,11 @@ namespace ts {
12121212
*/
12131213
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
12141214

1215-
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
1215+
getOptionsDiagnostics(): Diagnostic[];
12161216
getGlobalDiagnostics(): Diagnostic[];
1217+
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
12171218
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
12181219
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
1219-
/* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[];
12201220

12211221
/**
12221222
* Gets a type checker that can be used to semantically analyze source fils in the program.

src/services/services.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ namespace ts {
973973

974974
getSyntacticDiagnostics(fileName: string): Diagnostic[];
975975
getSemanticDiagnostics(fileName: string): Diagnostic[];
976+
977+
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
978+
// diagnostics present for the program level, and not just 'options' diagnostics.
976979
getCompilerOptionsDiagnostics(): Diagnostic[];
977980

978981
/**
@@ -1810,8 +1813,8 @@ namespace ts {
18101813

18111814
var program = createProgram([inputFileName], options, compilerHost);
18121815

1813-
addRange(/*to*/ diagnostics, /*from*/ sourceFile.parseDiagnostics);
1814-
addRange(/*to*/ diagnostics, /*from*/ program.getCompilerOptionsDiagnostics());
1816+
addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
1817+
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
18151818

18161819
// Emit
18171820
program.emit();
@@ -2790,7 +2793,7 @@ namespace ts {
27902793

27912794
function getCompilerOptionsDiagnostics() {
27922795
synchronizeHostData();
2793-
return program.getGlobalDiagnostics();
2796+
return program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
27942797
}
27952798

27962799
/// Completion

0 commit comments

Comments
 (0)