diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c550c703336..3fd917bc00e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -159,6 +159,14 @@ namespace ts { } }; + let subtypeRelation: Map = {}; + let assignableRelation: Map = {}; + let identityRelation: Map = {}; + + initializeTypeChecker(); + + return checker; + function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationTokenObject) { // 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 = {}; - let assignableRelation: Map = {}; - let identityRelation: Map = {}; - function isTypeIdenticalTo(source: Type, target: Type): boolean { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); } @@ -13641,9 +13645,5 @@ namespace ts { return true; } } - - initializeTypeChecker(); - - return checker; } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index df976f17ae9..443f5f92b49 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -105,8 +105,9 @@ namespace ts { } export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[] { - let diagnostics = program.getSyntacticDiagnostics(sourceFile, cancellationToken).concat( - program.getGlobalDiagnostics(cancellationToken)).concat( + let diagnostics = program.getOptionsDiagnostics(cancellationToken).concat( + program.getSyntacticDiagnostics(sourceFile, cancellationToken), + program.getGlobalDiagnostics(cancellationToken), program.getSemanticDiagnostics(sourceFile, cancellationToken)); if (program.getCompilerOptions().declaration) { @@ -179,10 +180,10 @@ namespace ts { getSourceFiles: () => files, getCompilerOptions: () => options, getSyntacticDiagnostics, + getOptionsDiagnostics, getGlobalDiagnostics, getSemanticDiagnostics, getDeclarationDiagnostics, - getCompilerOptionsDiagnostics, getTypeChecker, getClassifiableNames, getDiagnosticsProducingTypeChecker, @@ -344,19 +345,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); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b230b2c5feb..799c291f46a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1212,11 +1212,11 @@ namespace ts { */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationTokenObject): EmitResult; - getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[]; + getOptionsDiagnostics(cancellationToken?: CancellationTokenObject): Diagnostic[]; getGlobalDiagnostics(cancellationToken?: CancellationTokenObject): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[]; getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[]; getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationTokenObject): Diagnostic[]; - /* @internal */ getCompilerOptionsDiagnostics(cancellationToken?: CancellationTokenObject): Diagnostic[]; /** * Gets a type checker that can be used to semantically analyze source fils in the program. diff --git a/src/services/services.ts b/src/services/services.ts index 86540ccd3e5..f4348d52b6f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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[]; /** @@ -1790,8 +1793,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(); @@ -2770,7 +2773,8 @@ namespace ts { function getCompilerOptionsDiagnostics() { synchronizeHostData(); - return program.getGlobalDiagnostics(cancellationToken); + return program.getOptionsDiagnostics(cancellationToken).concat( + program.getGlobalDiagnostics(cancellationToken)); } /// Completion diff --git a/tests/perftsc.ts b/tests/perftsc.ts index e0189896a15..89bff1cc006 100644 --- a/tests/perftsc.ts +++ b/tests/perftsc.ts @@ -10,7 +10,7 @@ if (perftest.hasLogIOFlag()) { var content = perftest.readFile(s); return content !== undefined ? ts.createSourceFile(s, content, v) : undefined; }, - getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"), + getDefaultLibFileName: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"), writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); }, getCurrentDirectory: () => perftest.getCurrentDirectory(), getCanonicalFileName: (f: string) => ts.sys.useCaseSensitiveFileNames ? f : f.toLowerCase(), @@ -19,8 +19,8 @@ if (perftest.hasLogIOFlag()) { }; var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag()); - var program = ts.createProgram(commandLine.filenames, commandLine.options, compilerHost); - var fileNames = program.getSourceFiles().map(f => f.filename); + var program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost); + var fileNames = program.getSourceFiles().map(f => f.fileName); perftest.writeIOLog(fileNames); } else {