Merge pull request #3558 from Microsoft/diagnosticCleanup2

Make it so all our diagnostics APIs return an independent set of diagnostics.
This commit is contained in:
CyrusNajmabadi 2015-06-18 11:12:12 -07:00
commit 3a9bc99d9b
4 changed files with 23 additions and 21 deletions

View File

@ -159,6 +159,14 @@ namespace ts {
}
};
let subtypeRelation: Map<RelationComparisonResult> = {};
let assignableRelation: Map<RelationComparisonResult> = {};
let identityRelation: Map<RelationComparisonResult> = {};
initializeTypeChecker();
return checker;
function getEmitResolver(sourceFile?: SourceFile) {
// Ensure we have all the type information in place for this file so that all the
// emitter questions of this resolver will return the right information.
@ -4221,10 +4229,6 @@ namespace ts {
// TYPE CHECKING
let subtypeRelation: Map<RelationComparisonResult> = {};
let assignableRelation: Map<RelationComparisonResult> = {};
let identityRelation: Map<RelationComparisonResult> = {};
function isTypeIdenticalTo(source: Type, target: Type): boolean {
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
}
@ -13614,9 +13618,5 @@ namespace ts {
return true;
}
}
initializeTypeChecker();
return checker;
}
}

View File

@ -105,7 +105,10 @@ namespace ts {
}
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] {
let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
let diagnostics = program.getOptionsDiagnostics().concat(
program.getSyntacticDiagnostics(sourceFile),
program.getGlobalDiagnostics(),
program.getSemanticDiagnostics(sourceFile));
if (program.getCompilerOptions().declaration) {
diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
@ -177,10 +180,10 @@ namespace ts {
getSourceFiles: () => files,
getCompilerOptions: () => options,
getSyntacticDiagnostics,
getOptionsDiagnostics,
getGlobalDiagnostics,
getSemanticDiagnostics,
getDeclarationDiagnostics,
getCompilerOptionsDiagnostics,
getTypeChecker,
getClassifiableNames,
getDiagnosticsProducingTypeChecker,
@ -311,19 +314,15 @@ namespace ts {
}
}
function getCompilerOptionsDiagnostics(): Diagnostic[] {
function getOptionsDiagnostics(): Diagnostic[] {
let allDiagnostics: Diagnostic[] = [];
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
return sortAndDeduplicateDiagnostics(allDiagnostics);
}
function getGlobalDiagnostics(): Diagnostic[] {
let typeChecker = getDiagnosticsProducingTypeChecker();
let allDiagnostics: Diagnostic[] = [];
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
return sortAndDeduplicateDiagnostics(allDiagnostics);
}

View File

@ -1212,11 +1212,11 @@ namespace ts {
*/
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getOptionsDiagnostics(): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
/* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[];
/**
* Gets a type checker that can be used to semantically analyze source fils in the program.

View File

@ -973,6 +973,9 @@ namespace ts {
getSyntacticDiagnostics(fileName: string): Diagnostic[];
getSemanticDiagnostics(fileName: string): Diagnostic[];
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
// diagnostics present for the program level, and not just 'options' diagnostics.
getCompilerOptionsDiagnostics(): Diagnostic[];
/**
@ -1810,8 +1813,8 @@ namespace ts {
var program = createProgram([inputFileName], options, compilerHost);
addRange(/*to*/ diagnostics, /*from*/ sourceFile.parseDiagnostics);
addRange(/*to*/ diagnostics, /*from*/ program.getCompilerOptionsDiagnostics());
addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
// Emit
program.emit();
@ -2790,7 +2793,7 @@ namespace ts {
function getCompilerOptionsDiagnostics() {
synchronizeHostData();
return program.getGlobalDiagnostics();
return program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
}
/// Completion