diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50dcbd21fdc..7eb13e52a29 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10111,11 +10111,6 @@ module ts { return isImportResolvedToValue(getSymbolOfNode(node)); } - function hasSemanticDiagnostics(sourceFile?: SourceFile) { - // Return true if there is any semantic error in a file or globally - return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0; - } - function isImportResolvedToValue(symbol: Symbol): boolean { var target = resolveImport(symbol); // const enums and modules that contain only const enums are not considered values from the emit perespective @@ -10210,7 +10205,6 @@ module ts { getNodeCheckFlags, getEnumMemberValue, isTopLevelValueImportWithEntityName, - hasSemanticDiagnostics, isDeclarationVisible, isImplementationOfOverload, writeTypeOfDeclaration, @@ -10226,14 +10220,15 @@ module ts { // Bind all source files and propagate errors forEach(host.getSourceFiles(), file => { bindSourceFile(file); - forEach(file.bindDiagnostics, d => diagnostics.add(d)); }); + // Initialize global symbol table forEach(host.getSourceFiles(), file => { if (!isExternalModule(file)) { extendSymbolTable(globals, file.locals); } }); + // Initialize special symbols getSymbolLinks(undefinedSymbol).type = undefinedType; getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9b852a37ff6..b82ca2f07af 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -118,6 +118,12 @@ module ts { return result; } + export function addRange(to: T[], from: T[]): void { + for (var i = 0, n = from.length; i < n; i++) { + to.push(from[i]); + } + } + /** * Returns the last element of an array if non-empty, undefined otherwise. */ @@ -369,6 +375,10 @@ module ts { return text1 ? 1 : -1; } + export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { + return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)); + } + export function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { if (diagnostics.length < 2) { return diagnostics; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9b080fa4c39..467bef144fe 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4395,13 +4395,13 @@ module ts { } } - var hasSemanticDiagnostics = false; var isEmitBlocked = false; + var isDeclarationEmitBlocked = false; if (targetSourceFile === undefined) { // No targetSourceFile is specified (e.g. calling emitter from batch compiler) - hasSemanticDiagnostics = resolver.hasSemanticDiagnostics(); isEmitBlocked = host.isEmitBlocked(); + isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(); forEach(host.getSourceFiles(), sourceFile => { if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { @@ -4418,8 +4418,8 @@ module ts { // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { // If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file - hasSemanticDiagnostics = resolver.hasSemanticDiagnostics(targetSourceFile); isEmitBlocked = host.isEmitBlocked(targetSourceFile); + isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(targetSourceFile); var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); emitFile(jsFilePath, targetSourceFile); @@ -4429,8 +4429,8 @@ module ts { // Emit all, non-external-module file, into one single output file forEach(host.getSourceFiles(), sourceFile => { if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { - hasSemanticDiagnostics = hasSemanticDiagnostics || resolver.hasSemanticDiagnostics(sourceFile); isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile); + isDeclarationEmitBlocked = isDeclarationEmitBlocked || host.isDeclarationEmitBlocked(sourceFile); } }); @@ -4441,15 +4441,14 @@ module ts { function emitFile(jsFilePath: string, sourceFile?: SourceFile) { if (!isEmitBlocked) { emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticDiagnostics && compilerOptions.declaration) { + if (!isDeclarationEmitBlocked && compilerOptions.declaration) { writeDeclarationFile(jsFilePath, sourceFile); } } } // Sort and make the unique list of diagnostics - diagnostics.sort(compareDiagnostics); - diagnostics = deduplicateSortedDiagnostics(diagnostics); + diagnostics = sortAndDeduplicateDiagnostics(diagnostics); // Update returnCode if there is any EmitterError var hasEmitterError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); @@ -4457,13 +4456,13 @@ module ts { // Check and update returnCode for syntactic and semantic var emitResultStatus: EmitReturnStatus; if (isEmitBlocked) { - emitResultStatus = EmitReturnStatus.AllOutputGenerationSkipped; + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_AllOutputsSkipped; } else if (hasEmitterError) { emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; - } else if (hasSemanticDiagnostics && compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.DeclarationGenerationSkipped; - } else if (hasSemanticDiagnostics && !compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.JSGeneratedWithSemanticErrors; + } else if (isDeclarationEmitBlocked && compilerOptions.declaration) { + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated; + } else if (isDeclarationEmitBlocked && !compilerOptions.declaration) { + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated; } else { emitResultStatus = EmitReturnStatus.Succeeded; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4f23e2f30a7..05b5ea55505 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -357,7 +357,7 @@ module ts { forEachChild(sourceFile, walk); } - export function getSyntacticDiagnostics(sourceFile: SourceFile) { + export function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[] { if (!sourceFile.syntacticDiagnostics) { sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 85181b2aa55..e60a9e9f188 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -75,6 +75,37 @@ module ts { }; } + export function getPreEmitDiagnostics(program: Program): Diagnostic[] { + var diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + return sortAndDeduplicateDiagnostics(diagnostics); + } + + export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { + if (typeof messageText === "string") { + return messageText; + } + else { + var diagnosticChain = messageText; + var result = ""; + + var indent = 0; + while (diagnosticChain) { + if (indent) { + result += newLine; + + for (var i = 0; i < indent; i++) { + result += " "; + } + } + result += diagnosticChain.messageText; + indent++; + diagnosticChain = diagnosticChain.next; + } + + return result; + } + } + export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; @@ -97,10 +128,9 @@ module ts { getSourceFile: getSourceFile, getSourceFiles: () => files, getCompilerOptions: () => options, - getDiagnostics, + getSyntacticDiagnostics, getGlobalDiagnostics, - getTypeCheckerDiagnostics, - getTypeCheckerGlobalDiagnostics, + getSemanticDiagnostics, getDeclarationDiagnostics, getTypeChecker, getDiagnosticsProducingTypeChecker, @@ -116,7 +146,7 @@ module ts { }; return program; - function getEmitHost(writeFileCallback?: WriteFileCallback) { + function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost { return { getCanonicalFileName: host.getCanonicalFileName, getCommonSourceDirectory: program.getCommonSourceDirectory, @@ -126,17 +156,28 @@ module ts { getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, isEmitBlocked, + isDeclarationEmitBlocked, writeFile: writeFileCallback || host.writeFile, }; } + function hasPreEmitDiagnostics(sourceFile?: SourceFile): boolean { + var hasSyntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile).length > 0; + var hasSemanticDiagnostics = program.getSemanticDiagnostics(sourceFile).length > 0; - function isEmitBlocked(sourceFile?: SourceFile): boolean { - if (options.noEmitOnError) { - return getDiagnostics(sourceFile).length !== 0 || getTypeCheckerDiagnostics(sourceFile).length !== 0; + if (hasSyntacticDiagnostics || hasSemanticDiagnostics) { + return true; } - return false; + return !sourceFile && program.getGlobalDiagnostics().length > 0; + } + + function isEmitBlocked(sourceFile?: SourceFile): boolean { + return options.noEmitOnError && hasPreEmitDiagnostics(sourceFile); + } + + function isDeclarationEmitBlocked(sourceFile?: SourceFile) { + return hasPreEmitDiagnostics(sourceFile); } function getDiagnosticsProducingTypeChecker() { @@ -170,20 +211,51 @@ module ts { return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; } - function getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[] { - return getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile); + function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + if (sourceFile) { + return ts.getSyntacticDiagnostics(sourceFile); + } + + var allDiagnostics: Diagnostic[] = []; + forEach(program.getSourceFiles(), sourceFile => { + addRange(allDiagnostics, ts.getSyntacticDiagnostics(sourceFile)); + }); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } - function getTypeCheckerGlobalDiagnostics(): Diagnostic[] { - return getDiagnosticsProducingTypeChecker().getGlobalDiagnostics(); + function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + var typeChecker = getDiagnosticsProducingTypeChecker(); + + Debug.assert(!!sourceFile.bindDiagnostics); + var bindDiagnostics = sourceFile.bindDiagnostics; + var checkDiagnostics = typeChecker.getDiagnostics(sourceFile); + var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + + return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } - function getDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ - return sourceFile ? diagnostics.getDiagnostics(sourceFile.fileName) : diagnostics.getDiagnostics(); + function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + if (sourceFile) { + return sortAndDeduplicateDiagnostics(getSemanticDiagnosticsForFile(sourceFile)); + } + + var allDiagnostics: Diagnostic[] = []; + forEach(program.getSourceFiles(), sourceFile => { + addRange(allDiagnostics, getSemanticDiagnosticsForFile(sourceFile)); + }); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics(): Diagnostic[]{ - return diagnostics.getGlobalDiagnostics(); + var typeChecker = getDiagnosticsProducingTypeChecker(); + + var allDiagnostics: Diagnostic[] = []; + addRange(allDiagnostics, typeChecker.getGlobalDiagnostics()); + addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } function hasExtension(fileName: string): boolean { @@ -272,9 +344,6 @@ module ts { else { files.push(file); } - forEach(getSyntacticDiagnostics(file), e => { - diagnostics.add(e); - }); } } return file; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 15f97e028fc..541a64b6473 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -364,13 +364,19 @@ module ts { function compileProgram(): EmitReturnStatus { // First get any syntactic errors. - var errors = program.getDiagnostics(); + var errors = program.getSyntacticDiagnostics(); reportDiagnostics(errors); - // If we didn't have any syntactic errors, then also try getting the semantic errors. + // If we didn't have any syntactic errors, then also try getting the global and + // semantic errors. if (errors.length === 0) { - var errors = program.getTypeCheckerDiagnostics(); + var errors = program.getGlobalDiagnostics(); reportDiagnostics(errors); + + if (errors.length === 0) { + var errors = program.getSemanticDiagnostics(); + reportDiagnostics(errors); + } } // If the user doesn't want us to emit, then we're done at this point. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 467d9b6cc90..75cee5e7314 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -946,13 +946,10 @@ module ts { */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - // These will merge with the below diagnostics function in a followup checkin. - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; // Gets a type checker that can be used to semantically analyze source fils in the program. getTypeChecker(): TypeChecker; @@ -992,12 +989,26 @@ module ts { // Return code used by getEmitOutput function to indicate status of the function export enum EmitReturnStatus { - Succeeded = 0, // All outputs generated if requested (.js, .map, .d.ts), no errors reported - AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated - JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors - DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors - EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process - CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options, nothing generated + // All outputs generated if requested (.js, .map, .d.ts), no errors reported + Succeeded = 0, + + // No .js, .map or d.ts generated because of diagnostics and the presence of the + // -noEmitOnError optoin. + DiagnosticsPresent_AllOutputsSkipped = 1, + + // .js and .map generated. However, diagnostics were generated as well. + // No .d.ts was requested or generated. + DiagnosticsPresent_JavaScriptGenerated = 2, + + // .js, .map generated. .d.ts was requested but was not generated due to the + // presence of diagnostics. + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, + + // Emitter errors occurred during emitting process. + EmitErrorsEncountered = 4, + + // Errors occurred in parsing compiler options, nothing generated + CompilerOptionsErrors = 5, } export interface EmitResult { @@ -1137,7 +1148,6 @@ module ts { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4204acc4716..8291520da82 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -25,7 +25,9 @@ module ts { export interface EmitHost extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + isDeclarationEmitBlocked(sourceFile?: SourceFile): boolean; getCommonSourceDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -210,36 +212,10 @@ module ts { length, code: messageChain.code, category: messageChain.category, - messageText: messageChain + messageText: messageChain.next ? messageChain : messageChain.messageText }; } - export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { - if (typeof messageText === "string") { - return messageText; - } - else { - var diagnosticChain = messageText; - var result = ""; - - var indent = 0; - while (diagnosticChain) { - if (indent) { - result += newLine; - - for (var i = 0; i < indent; i++) { - result += " "; - } - } - result += diagnosticChain.messageText; - indent++; - diagnosticChain = diagnosticChain.next; - } - - return result; - } - } - export function getErrorSpanForNode(node: Node): Node { var errorSpan: Node; switch (node.kind) { @@ -1144,7 +1120,7 @@ module ts { } } - return sortAndDeplicateList(allDiagnostics); + return sortAndDeduplicateDiagnostics(allDiagnostics); } function sortAndDeduplicate() { @@ -1153,17 +1129,13 @@ module ts { } diagnosticsModified = false; - nonFileDiagnostics = sortAndDeplicateList(nonFileDiagnostics); + nonFileDiagnostics = sortAndDeduplicateDiagnostics(nonFileDiagnostics); for (var key in fileDiagnostics) { if (hasProperty(fileDiagnostics, key)) { - fileDiagnostics[key] = sortAndDeplicateList(fileDiagnostics[key]); + fileDiagnostics[key] = sortAndDeduplicateDiagnostics(fileDiagnostics[key]); } } } - - function sortAndDeplicateList(diagnostics: Diagnostic[]): Diagnostic[] { - return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)) - } } } \ No newline at end of file diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5e046c070ab..5ce3d3f37b9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1142,14 +1142,23 @@ module FourSlash { var emitOutput = this.languageService.getEmitOutput(emitFile.fileName); var emitOutputStatus = emitOutput.emitOutputStatus; // Print emitOutputStatus in readable format - resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus]; - resultString += "\n"; + resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus] + ts.sys.newLine; + + if (emitOutputStatus !== ts.EmitReturnStatus.Succeeded) { + resultString += "Diagnostics:" + ts.sys.newLine; + var diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram()); + for (var i = 0, n = diagnostics.length; i < n; i++) { + resultString += " " + diagnostics[0].messageText + ts.sys.newLine; + } + } + emitOutput.outputFiles.forEach((outputFile, idx, array) => { - var fileName = "FileName : " + outputFile.name + "\n"; + var fileName = "FileName : " + outputFile.name + ts.sys.newLine; resultString = resultString + fileName + outputFile.text; }); - resultString += "\n"; + resultString += ts.sys.newLine; }); + return resultString; }, true /* run immediately */); @@ -2215,11 +2224,11 @@ module FourSlash { ts.sys.useCaseSensitiveFileNames); // TODO (drosen): We need to enforce checking on these tests. var program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); - var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true); - var errors = program.getDiagnostics().concat(checker.getDiagnostics()); - if (errors.length > 0) { - throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); + var diagnostics = ts.getPreEmitDiagnostics(program); + if (diagnostics.length > 0) { + throw new Error('Error compiling ' + fileName + ': ' + + diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); } program.emit(); result = result || ''; // Might have an empty fourslash file diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 84aaf66be3d..866652e2e26 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1083,10 +1083,11 @@ module Harness { (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), options.target, useCaseSensitiveFileNames, currentDirectory)); + debugger; var emitResult = program.emit(); var errors: HarnessDiagnostic[] = []; - program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(emitResult.diagnostics).forEach(err => { + ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => { // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now errors.push(getMinimalDiagnostic(err)); }); diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 53ce8e507a0..0fde9a9d77c 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -127,23 +127,20 @@ class ProjectRunner extends RunnerBase { writeFile: (fileName: string, data: string, writeByteOrderMark: boolean) => void): CompileProjectFilesResult { var program = ts.createProgram(getInputFiles(), createCompilerOptions(), createCompilerHost()); - var errors = program.getDiagnostics(); - var sourceMapData: ts.SourceMapData[] = null; - if (!errors.length) { - errors = program.getTypeCheckerDiagnostics(); - var emitResult = program.emit(); - errors = ts.concatenate(errors, emitResult.diagnostics); - sourceMapData = emitResult.sourceMaps; + var errors = ts.getPreEmitDiagnostics(program); - // Clean up source map data that will be used in baselining - if (sourceMapData) { - for (var i = 0; i < sourceMapData.length; i++) { - for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) { - sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]); - } - sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL); - sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot); + var emitResult = program.emit(); + errors = ts.concatenate(errors, emitResult.diagnostics); + var sourceMapData = emitResult.sourceMaps; + + // Clean up source map data that will be used in baselining + if (sourceMapData) { + for (var i = 0; i < sourceMapData.length; i++) { + for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) { + sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]); } + sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL); + sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot); } } diff --git a/src/services/services.ts b/src/services/services.ts index 7311e5f7596..da695920cd7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2168,7 +2168,7 @@ module ts { fileName = normalizeSlashes(fileName); - return program.getDiagnostics(getValidSourceFile(fileName)); + return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } /** @@ -2179,18 +2179,19 @@ module ts { synchronizeHostData(); fileName = normalizeSlashes(fileName) - var compilerOptions = program.getCompilerOptions(); var targetSourceFile = getValidSourceFile(fileName); // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. // Therefore only get diagnostics for given file. - var allDiagnostics = program.getTypeCheckerDiagnostics(targetSourceFile); - if (compilerOptions.declaration) { - // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface - allDiagnostics = allDiagnostics.concat(program.getDeclarationDiagnostics(targetSourceFile)); + var semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile); + if (!program.getCompilerOptions().declaration) { + return semanticDiagnostics; } - return allDiagnostics + + // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface + var declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile); + return semanticDiagnostics.concat(declarationDiagnostics); } function getCompilerOptionsDiagnostics() { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index db4f29683d2..c64da05d512 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -10,24 +10,23 @@ declare var process: any; declare var console: any; +declare var os: any; import ts = require("typescript"); export function compile(fileNames: string[], options: ts.CompilerOptions): void { var program = ts.createProgram(fileNames, options); - var result = program.emit(); + var emitResult = program.emit(); - var allDiagnostics = program.getDiagnostics() - .concat(program.getTypeCheckerDiagnostics()) - .concat(result.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); - process.exit(result.emitResultStatus); + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); + process.exit(emitResult.emitResultStatus); } compile(process.argv.slice(2), { @@ -752,11 +751,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -781,9 +779,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -888,7 +886,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1422,6 +1419,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { @@ -1923,14 +1922,14 @@ declare module "typescript" { var ts = require("typescript"); function compile(fileNames, options) { var program = ts.createProgram(fileNames, options); - var result = program.emit(); - var allDiagnostics = program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(result.diagnostics); + var emitResult = program.emit(); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(function (diagnostic) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText); + console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)); }); - console.log("Process exiting with code '" + result.emitResultStatus + "'."); - process.exit(result.emitResultStatus); + console.log("Process exiting with code '" + emitResult.emitResultStatus + "'."); + process.exit(emitResult.emitResultStatus); } exports.compile = compile; compile(process.argv.slice(2), { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 5124312b6d3..e5ac6de7c10 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -12,6 +12,9 @@ declare var process: any; declare var console: any; >console : any +declare var os: any; +>os : any + import ts = require("typescript"); >ts : typeof ts @@ -31,43 +34,33 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >fileNames : string[] >options : ts.CompilerOptions - var result = program.emit(); ->result : ts.EmitResult + var emitResult = program.emit(); +>emitResult : ts.EmitResult >program.emit() : ts.EmitResult >program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program >emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult - var allDiagnostics = program.getDiagnostics() + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); >allDiagnostics : ts.Diagnostic[] ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) .concat(result.diagnostics) : ts.Diagnostic[] ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) : ts.Diagnostic[] ->program.getDiagnostics() .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getDiagnostics() : ts.Diagnostic[] ->program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program).concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>ts.getPreEmitDiagnostics(program) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] +>ts : typeof ts +>getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] >program : ts.Program ->getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - .concat(program.getTypeCheckerDiagnostics()) >concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] ->program : ts.Program ->getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - .concat(result.diagnostics); ->concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->result.diagnostics : ts.Diagnostic[] ->result : ts.EmitResult +>emitResult.diagnostics : ts.Diagnostic[] +>emitResult : ts.EmitResult >diagnostics : ts.Diagnostic[] allDiagnostics.forEach(diagnostic => { ->allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); }) : void +>allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }) : void >allDiagnostics.forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void >allDiagnostics : ts.Diagnostic[] >forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void ->diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); } : (diagnostic: ts.Diagnostic) => void +>diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); } : (diagnostic: ts.Diagnostic) => void >diagnostic : ts.Diagnostic var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); @@ -82,8 +75,8 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >diagnostic : ts.Diagnostic >start : number - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); ->console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`) : any + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); +>console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`) : any >console.log : any >console : any >log : any @@ -98,28 +91,35 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >lineChar.character : number >lineChar : ts.LineAndCharacter >character : number +>ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL) : string +>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string +>ts : typeof ts +>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string >diagnostic.messageText : string | ts.DiagnosticMessageChain >diagnostic : ts.Diagnostic >messageText : string | ts.DiagnosticMessageChain +>os.EOL : any +>os : any +>EOL : any }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); ->console.log(`Process exiting with code '${result.emitResultStatus}'.`) : any + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); +>console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`) : any >console.log : any >console : any >log : any ->result.emitResultStatus : ts.EmitReturnStatus ->result : ts.EmitResult +>emitResult.emitResultStatus : ts.EmitReturnStatus +>emitResult : ts.EmitResult >emitResultStatus : ts.EmitReturnStatus - process.exit(result.emitResultStatus); ->process.exit(result.emitResultStatus) : any + process.exit(emitResult.emitResultStatus); +>process.exit(emitResult.emitResultStatus) : any >process.exit : any >process : any >exit : any ->result.emitResultStatus : ts.EmitReturnStatus ->result : ts.EmitResult +>emitResult.emitResultStatus : ts.EmitReturnStatus +>emitResult : ts.EmitResult >emitResultStatus : ts.EmitReturnStatus } @@ -2268,18 +2268,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2288,8 +2278,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2359,14 +2355,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2852,11 +2848,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4556,6 +4547,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 646d0e47a4e..b84bcdb33fd 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -783,11 +783,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -812,9 +811,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -919,7 +918,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1453,6 +1451,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 1e917893832..798d41e70ee 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2415,18 +2415,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2435,8 +2425,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2506,14 +2502,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2999,11 +2995,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4703,6 +4694,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 280c5202db3..4b235f25df3 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -12,6 +12,7 @@ declare var process: any; declare var console: any; declare var fs: any; declare var path: any; +declare var os: any; import ts = require("typescript"); @@ -45,17 +46,17 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + + errors = errors.concat(emitResult.diagnostics); + return { outputs: outputs, - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); + }) }; } @@ -783,11 +784,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -812,9 +812,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -919,7 +919,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1453,6 +1452,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { @@ -1978,18 +1979,13 @@ function transform(contents, compilerOptions) { // Create a program from inputs var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + errors = errors.concat(emitResult.diagnostics); return { outputs: outputs, errors: errors.map(function (e) { - return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) }; } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index c8b7e10fa89..6a149ddbae3 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -18,6 +18,9 @@ declare var fs: any; declare var path: any; >path : any +declare var os: any; +>os : any + import ts = require("typescript"); >ts : typeof ts @@ -147,52 +150,50 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >compilerHost : { getSourceFile: (fileName: any, target: any) => ts.SourceFile; writeFile: (name: any, text: any, writeByteOrderMark: any) => void; getDefaultLibFileName: () => string; useCaseSensitiveFileNames: () => boolean; getCanonicalFileName: (fileName: any) => any; getCurrentDirectory: () => string; getNewLine: () => string; } // Query for early errors - var errors = program.getDiagnostics(); + var errors = ts.getPreEmitDiagnostics(program); >errors : ts.Diagnostic[] ->program.getDiagnostics() : ts.Diagnostic[] ->program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] +>ts : typeof ts +>getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] >program : ts.Program ->getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - // Do not generate code in the presence of early errors - if (!errors.length) { ->!errors.length : boolean ->errors.length : number ->errors : ts.Diagnostic[] ->length : number - - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); ->errors = program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->errors : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] ->program : ts.Program ->getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - // Generate output - program.emit(); + var emitResult = program.emit(); +>emitResult : ts.EmitResult >program.emit() : ts.EmitResult >program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program >emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult - } + + errors = errors.concat(emitResult.diagnostics); +>errors = errors.concat(emitResult.diagnostics) : ts.Diagnostic[] +>errors : ts.Diagnostic[] +>errors.concat(emitResult.diagnostics) : ts.Diagnostic[] +>errors.concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>errors : ts.Diagnostic[] +>concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>emitResult.diagnostics : ts.Diagnostic[] +>emitResult : ts.EmitResult +>diagnostics : ts.Diagnostic[] + return { ->{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) } : { outputs: any[]; errors: string[]; } +>{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) } : { outputs: any[]; errors: string[]; } outputs: outputs, >outputs : any[] >outputs : any[] - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { >errors : string[] ->errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) : string[] +>errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) : string[] >errors.map : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[] >errors : ts.Diagnostic[] >map : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[] ->function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; } : (e: ts.Diagnostic) => string +>function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); } : (e: ts.Diagnostic) => string >e : ts.Diagnostic ->e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText : string + + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " +>e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string >e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " : string >e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line : string >e.file.fileName + "(" : string @@ -212,10 +213,20 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >e : ts.Diagnostic >start : number >line : number + + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); +>ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string +>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string +>ts : typeof ts +>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string >e.messageText : string | ts.DiagnosticMessageChain >e : ts.Diagnostic >messageText : string | ts.DiagnosticMessageChain +>os.EOL : any +>os : any +>EOL : any + }) }; } @@ -2356,18 +2367,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2376,8 +2377,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2447,14 +2454,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2940,11 +2947,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4644,6 +4646,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 89f3bc43d37..8c53f252843 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -821,11 +821,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -850,9 +849,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -957,7 +956,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1491,6 +1489,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index f286fe18eb2..8a1f4aa259d 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2541,18 +2541,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2561,8 +2551,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2632,14 +2628,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -3125,11 +3121,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4829,6 +4820,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/declarationEmit_invalidReference2.js b/tests/baselines/reference/declarationEmit_invalidReference2.js index 78fb232cca7..0f8d5d4c07d 100644 --- a/tests/baselines/reference/declarationEmit_invalidReference2.js +++ b/tests/baselines/reference/declarationEmit_invalidReference2.js @@ -5,7 +5,3 @@ var x = 0; //// [declarationEmit_invalidReference2.js] /// var x = 0; - - -//// [declarationEmit_invalidReference2.d.ts] -declare var x: number; diff --git a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline index 111448faa61..a8b6f8a9cd4 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline @@ -1,30 +1,30 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js var x = 5; var Bar = (function () { function Bar() { } return Bar; })(); -FileName : tests/cases/fourslash/inputFile1.d.ts +FileName : tests/cases/fourslash/inputFile1.d.ts declare var x: number; declare class Bar { x: string; y: number; } - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; })(); -FileName : tests/cases/fourslash/inputFile2.d.ts +FileName : tests/cases/fourslash/inputFile2.d.ts declare var x1: string; declare class Foo { x: string; y: number; } - + diff --git a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline index a54108eb379..131b6cd98ed 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { @@ -12,7 +12,7 @@ var Foo = (function () { } return Foo; })(); -FileName : declSingleFile.d.ts +FileName : declSingleFile.d.ts declare var x: number; declare class Bar { x: string; @@ -23,4 +23,4 @@ declare class Foo { x: string; y: number; } - + diff --git a/tests/baselines/reference/getEmitOutputExternalModule.baseline b/tests/baselines/reference/getEmitOutputExternalModule.baseline index 6c1b0552a49..dcfd9bd89cc 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { } return Bar; })(); - + diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 5613592b414..5ec634d37a5 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,5 +1,8 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : declSingleFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. + Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { @@ -12,4 +15,4 @@ var Bar2 = (function () { } return Bar2; })(); - + diff --git a/tests/baselines/reference/getEmitOutputMapRoots.baseline b/tests/baselines/reference/getEmitOutputMapRoots.baseline index 733897879df..91cb853bdf0 100644 --- a/tests/baselines/reference/getEmitOutputMapRoots.baseline +++ b/tests/baselines/reference/getEmitOutputMapRoots.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js.map -{"version":3,"file":"declSingleFile.js","sourceRoot":"","sources":["../tests/cases/fourslash/inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js.map +{"version":3,"file":"declSingleFile.js","sourceRoot":"","sources":["../tests/cases/fourslash/inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : declSingleFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=mapRootDir/declSingleFile.js.map +//# sourceMappingURL=mapRootDir/declSingleFile.js.map diff --git a/tests/baselines/reference/getEmitOutputNoErrors.baseline b/tests/baselines/reference/getEmitOutputNoErrors.baseline index b8eddab6a9c..7fb0ca2eee5 100644 --- a/tests/baselines/reference/getEmitOutputNoErrors.baseline +++ b/tests/baselines/reference/getEmitOutputNoErrors.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js var x; var M = (function () { function M() { } return M; })(); - + diff --git a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline index 6be2d3e1d04..775cbf195c6 100644 --- a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline +++ b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x; var Foo = (function () { function Foo() { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputSingleFile.baseline b/tests/baselines/reference/getEmitOutputSingleFile.baseline index b5fc4214d7c..81ceb3f4357 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : outputDir/singleFile.js +EmitOutputStatus : Succeeded +FileName : outputDir/singleFile.js var x; var Bar = (function () { function Bar() { @@ -12,4 +12,4 @@ var Foo = (function () { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputSingleFile2.baseline b/tests/baselines/reference/getEmitOutputSingleFile2.baseline index fcbd145361d..0f5fad8505d 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile2.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile2.baseline @@ -1,8 +1,8 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile3.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile3.js exports.foo = 10; exports.bar = "hello world"; -FileName : tests/cases/fourslash/inputFile3.d.ts +FileName : tests/cases/fourslash/inputFile3.d.ts export declare var foo: number; export declare var bar: string; - + diff --git a/tests/baselines/reference/getEmitOutputSourceMap.baseline b/tests/baselines/reference/getEmitOutputSourceMap.baseline index c095c2f7542..553936bd91b 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile.js.map +//# sourceMappingURL=inputFile.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceMap2.baseline b/tests/baselines/reference/getEmitOutputSourceMap2.baseline index 021b3918712..838a9a985eb 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap2.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap2.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : sample/outDir/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : sample/outDir/inputFile1.js +EmitOutputStatus : Succeeded +FileName : sample/outDir/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : sample/outDir/inputFile1.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,12 +8,12 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded -FileName : sample/outDir/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,KAAK,GAAG,aAAa,CAAC;AAC1B,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,CAAC;AACd,CAAC"}FileName : sample/outDir/inputFile2.js +//# sourceMappingURL=inputFile1.js.map +EmitOutputStatus : Succeeded +FileName : sample/outDir/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,KAAK,GAAG,aAAa,CAAC;AAC1B,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,CAAC;AACd,CAAC"}FileName : sample/outDir/inputFile2.js var intro = "hello world"; if (intro !== undefined) { var k = 10; } -//# sourceMappingURL=inputFile2.js.map +//# sourceMappingURL=inputFile2.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceRoot.baseline b/tests/baselines/reference/getEmitOutputSourceRoot.baseline index 38621490fe7..880ad48ded3 100644 --- a/tests/baselines/reference/getEmitOutputSourceRoot.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRoot.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile.js.map +//# sourceMappingURL=inputFile.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline index 46e8a782a97..20ed671e8cf 100644 --- a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,14 +8,14 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":["C","C.constructor"],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile2.js +//# sourceMappingURL=inputFile1.js.map +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":["C","C.constructor"],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile2.js var bar = "hello world Typescript"; var C = (function () { function C() { } return C; })(); -//# sourceMappingURL=inputFile2.js.map +//# sourceMappingURL=inputFile2.js.map diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline index 51ea0ffba1a..0d9c3c16f55 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline @@ -1,11 +1,11 @@ -EmitOutputStatus : Succeeded - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline index c42cf8974cb..03b466d4dde 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline @@ -1,15 +1,15 @@ -EmitOutputStatus : Succeeded - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var Foo = (function () { function Foo() { } return Foo; })(); exports.Foo = Foo; - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile3.js + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile3.js var x = "hello"; - + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline index 83837faece8..972d164af42 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : declSingle.js +EmitOutputStatus : Succeeded +FileName : declSingle.js var x = "hello"; var x1 = 1000; - + diff --git a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline index e38f6a2021c..e9622faf16b 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,5 +1,8 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + 'const' declarations are only available when targeting ECMAScript 6 and higher. + 'const' declarations are only available when targeting ECMAScript 6 and higher. +FileName : tests/cases/fourslash/inputFile1.js // File contains early errors. All outputs should be skipped. const uninitialized_const_error; - + diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline index 359faef5fc1..d5bf626085e 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline @@ -1,5 +1,6 @@ -EmitOutputStatus : EmitErrorsEncountered -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : EmitErrorsEncountered +Diagnostics: +FileName : tests/cases/fourslash/inputFile.js var M; (function (M) { var C = (function () { @@ -9,4 +10,4 @@ var M; })(); M.foo = new C(); })(M || (M = {})); - + diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index 2465f832b37..98df927aa4b 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -1,5 +1,6 @@ -EmitOutputStatus : EmitErrorsEncountered -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : EmitErrorsEncountered +Diagnostics: +FileName : tests/cases/fourslash/inputFile.js define(["require", "exports"], function (require, exports) { var C = (function () { function C() { @@ -11,4 +12,4 @@ define(["require", "exports"], function (require, exports) { M.foo = new C(); })(M = exports.M || (exports.M = {})); }); - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline index a1a721704a3..9143fe51318 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Type 'string' is not assignable to type 'number'. +FileName : tests/cases/fourslash/inputFile.js var x = "hello world"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline index d9cf2b1eedd..7a251e5aca4 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : DeclarationGenerationSkipped -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated +Diagnostics: + Type 'string' is not assignable to type 'number'. +FileName : tests/cases/fourslash/inputFile.js var x = "hello world"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline index 91865045420..2a0b26f47c8 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline @@ -1,8 +1,8 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js // File to emit, does not contain semantic errors // expected to be emitted correctelly regardless of the semantic errors in the other file var noErrors = true; -FileName : tests/cases/fourslash/inputFile1.d.ts +FileName : tests/cases/fourslash/inputFile1.d.ts declare var noErrors: boolean; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline index 8b3a8ce8526..fde530fd483 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline @@ -1,8 +1,10 @@ -EmitOutputStatus : DeclarationGenerationSkipped -FileName : out.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated +Diagnostics: + Type 'string' is not assignable to type 'boolean'. +FileName : out.js // File to emit, does not contain semantic errors, but --out is passed // expected to not generate declarations because of the semantic errors in the other file var noErrors = true; // File not emitted, and contains semantic errors var semanticError = "string"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline index 0edb4e3bb61..224742eea3c 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js // File to emit, does not contain syntactic errors // expected to be emitted correctelly regardless of the syntactic errors in the other file var noErrors = true; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline index 21f60cf9eeb..8b68a9d8ad9 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline @@ -1,8 +1,10 @@ -EmitOutputStatus : Succeeded -FileName : out.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + '=' expected. +FileName : out.js // File to emit, does not contain syntactic errors, but --out is passed // expected to not generate outputs because of the syntactic errors in the other file. var noErrors = true; // File not emitted, and contains syntactic errors var syntactic = Error; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline index 53c09d5fe28..6e6c38f4531 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Type expected. +FileName : tests/cases/fourslash/inputFile.js var x; - + diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json index 9aefd24fb37..03bc2e44e0c 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json @@ -11,5 +11,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json index 9aefd24fb37..03bc2e44e0c 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json @@ -11,5 +11,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json index f9d00318f8c..b4ff3c201d8 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json index f9d00318f8c..b4ff3c201d8 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json index 7cf066f15c4..be0075d1500 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json index 7cf066f15c4..be0075d1500 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json index 5fb6100024f..6ba257bd4ac 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json @@ -8,5 +8,7 @@ "lib.d.ts", "main.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "main.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json index 5fb6100024f..6ba257bd4ac 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json @@ -8,5 +8,7 @@ "lib.d.ts", "main.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "main.js" + ] } \ No newline at end of file diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 4731f856e2a..25f9fe6e145 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -10,24 +10,23 @@ declare var process: any; declare var console: any; +declare var os: any; import ts = require("typescript"); export function compile(fileNames: string[], options: ts.CompilerOptions): void { var program = ts.createProgram(fileNames, options); - var result = program.emit(); + var emitResult = program.emit(); - var allDiagnostics = program.getDiagnostics() - .concat(program.getTypeCheckerDiagnostics()) - .concat(result.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); - process.exit(result.emitResultStatus); + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); + process.exit(emitResult.emitResultStatus); } compile(process.argv.slice(2), { diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index eccdb1ccecc..e9d9a46d286 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -12,6 +12,7 @@ declare var process: any; declare var console: any; declare var fs: any; declare var path: any; +declare var os: any; import ts = require("typescript"); @@ -45,17 +46,17 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + + errors = errors.concat(emitResult.diagnostics); + return { outputs: outputs, - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); + }) }; } diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts index e363d6b53fd..266edaf23e1 100644 --- a/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts @@ -18,5 +18,5 @@ // @Filename: inputFile5.js //// var x2 = 1000; - +debugger; verify.baselineGetEmitOutput(); \ No newline at end of file diff --git a/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts b/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts index 5cfacc36715..69f8b8a8b41 100644 --- a/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts +++ b/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts @@ -12,5 +12,5 @@ // @Filename: inputFile2.ts //// // File not emitted, and contains semantic errors //// var semanticError: boolean = "string"; - +debugger; verify.baselineGetEmitOutput(); \ No newline at end of file