diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts
index c97e1f34772..c1b9d76f1b5 100644
--- a/src/compiler/binder.ts
+++ b/src/compiler/binder.ts
@@ -1,6 +1,8 @@
///
module ts {
+ /* @internal */ export var bindTime = 0;
+
export const enum ModuleInstanceState {
NonInstantiated = 0,
Instantiated = 1,
@@ -60,8 +62,13 @@ module ts {
return declaration.name && declaration.name.kind === SyntaxKind.ComputedPropertyName;
}
- export function bindSourceFile(file: SourceFile) {
+ export function bindSourceFile(file: SourceFile): void {
+ var start = new Date().getTime();
+ bindSourceFileWorker(file);
+ bindTime += new Date().getTime() - start;
+ }
+ function bindSourceFileWorker(file: SourceFile): void {
var parent: Node;
var container: Node;
var blockScopeContainer: Node;
@@ -136,9 +143,9 @@ module ts {
: Diagnostics.Duplicate_identifier_0;
forEach(symbol.declarations, declaration => {
- file.semanticDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
+ file.bindDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
});
- file.semanticDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
+ file.bindDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
symbol = createSymbol(0, name);
}
@@ -159,7 +166,7 @@ module ts {
if (node.name) {
node.name.parent = node;
}
- file.semanticDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
+ file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 6aa4862abc5..7c43b8bb233 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -5,6 +5,8 @@ module ts {
var nextNodeId = 1;
var nextMergeId = 1;
+ /* @internal */ export var checkTime = 0;
+
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
var Symbol = objectAllocator.getSymbolConstructor();
var Type = objectAllocator.getTypeConstructor();
@@ -48,12 +50,12 @@ module ts {
getContextualType,
getFullyQualifiedName,
getResolvedSignature,
- getEnumMemberValue,
+ getConstantValue,
isValidPropertyAccess,
getSignatureFromDeclaration,
isImplementationOfOverload,
getAliasedSymbol: resolveImport,
- getEmitResolver: () => emitResolver,
+ getEmitResolver,
};
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -104,8 +106,7 @@ module ts {
var nodeLinks: NodeLinks[] = [];
var potentialThisCollisions: Node[] = [];
- var diagnostics: Diagnostic[] = [];
- var diagnosticsModified: boolean = false;
+ var diagnostics = createDiagnosticCollection();
var primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
"string": {
@@ -122,16 +123,18 @@ module ts {
}
};
- function addDiagnostic(diagnostic: Diagnostic) {
- diagnostics.push(diagnostic);
- diagnosticsModified = true;
+ function getEmitResolver(sourceFile?: SourceFile) {
+ // Ensure we have all the type information in place for this file so that all the
+ // emitter questions of this resolver will return the right information.
+ getDiagnostics(sourceFile);
+ return emitResolver;
}
function error(location: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var diagnostic = location
? createDiagnosticForNode(location, message, arg0, arg1, arg2)
: createCompilerDiagnostic(message, arg0, arg1, arg2);
- addDiagnostic(diagnostic);
+ diagnostics.add(diagnostic);
}
function createSymbol(flags: SymbolFlags, name: string): Symbol {
@@ -3479,7 +3482,8 @@ module ts {
if (containingMessageChain) {
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
}
- addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine()));
+
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
}
return result !== Ternary.False;
@@ -5705,9 +5709,9 @@ module ts {
return false;
}
else {
- var diagnosticsCount = diagnostics.length;
+ var modificationCount = diagnostics.getModificationCount();
checkClassPropertyAccess(node, left, type, prop);
- return diagnostics.length === diagnosticsCount
+ return diagnostics.getModificationCount() === modificationCount;
}
}
}
@@ -8927,7 +8931,7 @@ module ts {
var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
- addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine()));
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
}
}
}
@@ -9542,8 +9546,14 @@ module ts {
}
}
- // Fully type check a source file and collect the relevant diagnostics.
function checkSourceFile(node: SourceFile) {
+ var start = new Date().getTime();
+ checkSourceFileWorker(node);
+ checkTime += new Date().getTime() - start;
+ }
+
+ // Fully type check a source file and collect the relevant diagnostics.
+ function checkSourceFileWorker(node: SourceFile) {
var links = getNodeLinks(node);
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
// Grammar checking
@@ -9578,30 +9588,19 @@ module ts {
}
}
- function getSortedDiagnostics(): Diagnostic[]{
- Debug.assert(produceDiagnostics, "diagnostics are available only in the full typecheck mode");
-
- if (diagnosticsModified) {
- diagnostics.sort(compareDiagnostics);
- diagnostics = deduplicateSortedDiagnostics(diagnostics);
- diagnosticsModified = false;
- }
- return diagnostics;
- }
-
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
throwIfNonDiagnosticsProducing();
if (sourceFile) {
checkSourceFile(sourceFile);
- return filter(getSortedDiagnostics(), d => d.file === sourceFile);
+ return diagnostics.getDiagnostics(sourceFile.fileName);
}
forEach(host.getSourceFiles(), checkSourceFile);
- return getSortedDiagnostics();
+ return diagnostics.getDiagnostics();
}
- function getGlobalDiagnostics(): Diagnostic[]{
+ function getGlobalDiagnostics(): Diagnostic[] {
throwIfNonDiagnosticsProducing();
- return filter(getSortedDiagnostics(), d => !d.file);
+ return diagnostics.getGlobalDiagnostics();
}
function throwIfNonDiagnosticsProducing() {
@@ -9625,7 +9624,7 @@ module ts {
return false;
}
- function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]{
+ function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] {
var symbols: SymbolTable = {};
var memberFlags: NodeFlags = 0;
function copySymbol(symbol: Symbol, meaning: SymbolFlags) {
@@ -10011,7 +10010,7 @@ module ts {
return getNamedMembers(propsByName);
}
- function getRootSymbols(symbol: Symbol): Symbol[]{
+ function getRootSymbols(symbol: Symbol): Symbol[] {
if (symbol.flags & SymbolFlags.UnionProperty) {
var symbols: Symbol[] = [];
var name = symbol.name;
@@ -10119,11 +10118,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
@@ -10177,7 +10171,11 @@ module ts {
return getNodeLinks(node).enumMemberValue;
}
- function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number {
+ function getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number {
+ if (node.kind === SyntaxKind.EnumMember) {
+ return getEnumMemberValue(node);
+ }
+
var symbol = getNodeLinks(node).resolvedSymbol;
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
var declaration = symbol.valueDeclaration;
@@ -10216,9 +10214,7 @@ module ts {
getExportAssignmentName,
isReferencedImportDeclaration,
getNodeCheckFlags,
- getEnumMemberValue,
isTopLevelValueImportWithEntityName,
- hasSemanticDiagnostics,
isDeclarationVisible,
isImplementationOfOverload,
writeTypeOfDeclaration,
@@ -10234,14 +10230,15 @@ module ts {
// Bind all source files and propagate errors
forEach(host.getSourceFiles(), file => {
bindSourceFile(file);
- forEach(file.semanticDiagnostics, addDiagnostic);
});
+
// 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");
@@ -11035,14 +11032,14 @@ module ts {
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
var start = scanToken(scanner, node.pos);
- diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
+ diagnostics.add(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
return true;
}
}
function grammarErrorAtPos(sourceFile: SourceFile, start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
if (!hasParseDiagnostics(sourceFile)) {
- diagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
+ diagnostics.add(createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
return true;
}
}
@@ -11052,7 +11049,7 @@ module ts {
if (!hasParseDiagnostics(sourceFile)) {
var span = getErrorSpanForNode(node);
var start = span.end > span.pos ? skipTrivia(sourceFile.text, span.pos) : span.pos;
- diagnostics.push(createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
+ diagnostics.add(createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2));
return true;
}
}
@@ -11186,7 +11183,7 @@ module ts {
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
scanToken(scanner, node.pos);
- diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
+ diagnostics.add(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
return true;
}
}
diff --git a/src/compiler/core.ts b/src/compiler/core.ts
index 87094150baf..d527b62005e 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.
*/
@@ -325,38 +331,6 @@ module ts {
return headChain;
}
- export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic {
- Debug.assert(start >= 0, "start must be non-negative, is " + start);
- Debug.assert(length >= 0, "length must be non-negative, is " + length);
-
- var code = diagnosticChain.code;
- var category = diagnosticChain.category;
- var messageText = "";
-
- var indent = 0;
- while (diagnosticChain) {
- if (indent) {
- messageText += newLine;
-
- for (var i = 0; i < indent; i++) {
- messageText += " ";
- }
- }
- messageText += diagnosticChain.messageText;
- indent++;
- diagnosticChain = diagnosticChain.next;
- }
-
- return {
- file,
- start,
- length,
- code,
- category,
- messageText
- };
- }
-
export function compareValues(a: T, b: T): Comparison {
if (a === b) return Comparison.EqualTo;
if (a === undefined) return Comparison.LessThan;
@@ -368,13 +342,41 @@ module ts {
return diagnostic.file ? diagnostic.file.fileName : undefined;
}
- export function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number {
+ export function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): Comparison {
return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
compareValues(d1.start, d2.start) ||
compareValues(d1.length, d2.length) ||
compareValues(d1.code, d2.code) ||
- compareValues(d1.messageText, d2.messageText) ||
- 0;
+ compareMessageText(d1.messageText, d2.messageText) ||
+ Comparison.EqualTo;
+ }
+
+ function compareMessageText(text1: string | DiagnosticMessageChain, text2: string | DiagnosticMessageChain): Comparison {
+ while (text1 && text2) {
+ // We still have both chains.
+ var string1 = typeof text1 === "string" ? text1 : text1.messageText;
+ var string2 = typeof text2 === "string" ? text2 : text2.messageText;
+
+ var res = compareValues(string1, string2);
+ if (res) {
+ return res;
+ }
+
+ text1 = typeof text1 === "string" ? undefined : text1.next;
+ text2 = typeof text2 === "string" ? undefined : text2.next;
+ }
+
+ if (!text1 && !text2) {
+ // if the chains are done, then these messages are the same.
+ return Comparison.EqualTo;
+ }
+
+ // We still have one chain remaining. The shorter chain should come first.
+ return text1 ? Comparison.GreaterThan : Comparison.LessThan;
+ }
+
+ export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[]{
+ return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
}
export function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] {
diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts
index a4521977802..95e46112d57 100644
--- a/src/compiler/emitter.ts
+++ b/src/compiler/emitter.ts
@@ -825,7 +825,7 @@ module ts {
function emitEnumMemberDeclaration(node: EnumMember) {
emitJsDocComments(node);
writeTextOfNode(currentSourceFile, node.name);
- var enumMemberValue = resolver.getEnumMemberValue(node);
+ var enumMemberValue = resolver.getConstantValue(node);
if (enumMemberValue !== undefined) {
write(" = ");
write(enumMemberValue.toString());
@@ -1144,7 +1144,9 @@ module ts {
if (accessor) {
return accessor.kind === SyntaxKind.GetAccessor
? accessor.type // Getter - return type
- : accessor.parameters[0].type; // Setter parameter type
+ : accessor.parameters.length > 0
+ ? accessor.parameters[0].type // Setter parameter type
+ : undefined;
}
}
@@ -1504,14 +1506,47 @@ module ts {
return diagnostics;
}
- // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
- export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult {
+ // @internal
+ // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
+ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile): EmitResult {
var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
var diagnostics: Diagnostic[] = [];
var newLine = host.getNewLine();
+ if (targetSourceFile === undefined) {
+ forEach(host.getSourceFiles(), sourceFile => {
+ if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
+ var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js");
+ emitFile(jsFilePath, sourceFile);
+ }
+ });
+
+ if (compilerOptions.out) {
+ emitFile(compilerOptions.out);
+ }
+ }
+ else {
+ // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
+ if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
+ emitFile(jsFilePath, targetSourceFile);
+ }
+ else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
+ emitFile(compilerOptions.out);
+ }
+ }
+
+ // Sort and make the unique list of diagnostics
+ diagnostics = sortAndDeduplicateDiagnostics(diagnostics);
+
+ return {
+ emitSkipped: false,
+ diagnostics,
+ sourceMaps: sourceMapDataList
+ };
+
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(newLine);
var write = writer.write;
@@ -1575,6 +1610,25 @@ module ts {
/** Sourcemap data that will get encoded */
var sourceMapData: SourceMapData;
+ if (compilerOptions.sourceMap) {
+ initializeEmitterWithSourceMaps();
+ }
+
+ if (root) {
+ emit(root);
+ }
+ else {
+ forEach(host.getSourceFiles(), sourceFile => {
+ if (!isExternalModuleOrDeclarationFile(sourceFile)) {
+ emit(sourceFile);
+ }
+ });
+ }
+
+ writeLine();
+ writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
+ return;
+
function initializeEmitterWithSourceMaps() {
var sourceMapDir: string; // The directory in which sourcemap will be
@@ -2637,7 +2691,6 @@ module ts {
write(tokenToString(node.operator));
}
-
function emitBinaryExpression(node: BinaryExpression) {
if (languageVersion < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken &&
(node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
@@ -3756,7 +3809,7 @@ module ts {
function writeEnumMemberDeclarationValue(member: EnumMember) {
if (!member.initializer || isConst(member.parent)) {
- var value = resolver.getEnumMemberValue(member);
+ var value = resolver.getConstantValue(member);
if (value !== undefined) {
write(value.toString());
return;
@@ -4236,7 +4289,6 @@ module ts {
return leadingComments;
}
-
function getLeadingCommentsToEmit(node: Node) {
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
if (node.parent) {
@@ -4354,24 +4406,6 @@ module ts {
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
emitComments(currentSourceFile, writer, pinnedComments, /*trailingSeparator*/ true, newLine, writeComment);
}
-
- if (compilerOptions.sourceMap) {
- initializeEmitterWithSourceMaps();
- }
-
- if (root) {
- emit(root);
- }
- else {
- forEach(host.getSourceFiles(), sourceFile => {
- if (!isExternalModuleOrDeclarationFile(sourceFile)) {
- emit(sourceFile);
- }
- });
- }
-
- writeLine();
- writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
}
function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile) {
@@ -4393,84 +4427,13 @@ module ts {
writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
}
}
-
- var hasSemanticDiagnostics = false;
- var isEmitBlocked = false;
-
- if (targetSourceFile === undefined) {
- // No targetSourceFile is specified (e.g. calling emitter from batch compiler)
- hasSemanticDiagnostics = resolver.hasSemanticDiagnostics();
- isEmitBlocked = host.isEmitBlocked();
-
- forEach(host.getSourceFiles(), sourceFile => {
- if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
- var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js");
- emitFile(jsFilePath, sourceFile);
- }
- });
-
- if (compilerOptions.out) {
- emitFile(compilerOptions.out);
- }
- }
- else {
- // 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);
-
- var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
- emitFile(jsFilePath, targetSourceFile);
- }
- else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
- // Otherwise, if --out is specified and targetSourceFile is not a declaration file,
- // 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);
- }
- });
-
- emitFile(compilerOptions.out);
- }
- }
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
- if (!isEmitBlocked) {
- emitJavaScript(jsFilePath, sourceFile);
- if (!hasSemanticDiagnostics && compilerOptions.declaration) {
- writeDeclarationFile(jsFilePath, sourceFile);
- }
+ emitJavaScript(jsFilePath, sourceFile);
+
+ if (compilerOptions.declaration) {
+ writeDeclarationFile(jsFilePath, sourceFile);
}
}
-
- // Sort and make the unique list of diagnostics
- diagnostics.sort(compareDiagnostics);
- diagnostics = deduplicateSortedDiagnostics(diagnostics);
-
- // Update returnCode if there is any EmitterError
- var hasEmitterError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
-
- // Check and update returnCode for syntactic and semantic
- var emitResultStatus: EmitReturnStatus;
- if (isEmitBlocked) {
- emitResultStatus = EmitReturnStatus.AllOutputGenerationSkipped;
- } else if (hasEmitterError) {
- emitResultStatus = EmitReturnStatus.EmitErrorsEncountered;
- } else if (hasSemanticDiagnostics && compilerOptions.declaration) {
- emitResultStatus = EmitReturnStatus.DeclarationGenerationSkipped;
- } else if (hasSemanticDiagnostics && !compilerOptions.declaration) {
- emitResultStatus = EmitReturnStatus.JSGeneratedWithSemanticErrors;
- } else {
- emitResultStatus = EmitReturnStatus.Succeeded;
- }
-
- return {
- emitResultStatus,
- diagnostics,
- sourceMaps: sourceMapDataList
- };
}
}
diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts
index 866d66d5151..cd08e592be8 100644
--- a/src/compiler/parser.ts
+++ b/src/compiler/parser.ts
@@ -3,6 +3,7 @@
module ts {
var nodeConstructors = new Array Node>(SyntaxKind.Count);
+ /* @internal */ export var parseTime = 0;
export function getNodeConstructor(kind: SyntaxKind): new () => Node {
return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind));
@@ -356,15 +357,6 @@ module ts {
forEachChild(sourceFile, walk);
}
- export function getSyntacticDiagnostics(sourceFile: SourceFile) {
- if (!sourceFile.syntacticDiagnostics) {
- // Don't bother doing any grammar checks if there are already parser errors.
- // Otherwise we may end up with too many cascading errors.
- sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics);
- }
- return sourceFile.syntacticDiagnostics;
- }
-
function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) {
if (element.length) {
visitArray(element);
@@ -857,8 +849,13 @@ module ts {
}
}
}
+
export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false): SourceFile {
- return parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
+ var start = new Date().getTime();
+ var result = parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
+
+ parseTime += new Date().getTime() - start;
+ return result;
}
function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile {
@@ -871,10 +868,12 @@ module ts {
var sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0);
- sourceFile.pos = sourceFile.end = 0;
- sourceFile.referenceDiagnostics = [];
+ sourceFile.pos = 0;
+ sourceFile.end = sourceText.length;
+ sourceFile.text = sourceText;
+
sourceFile.parseDiagnostics = [];
- sourceFile.semanticDiagnostics = [];
+ sourceFile.bindDiagnostics = [];
sourceFile.languageVersion = languageVersion;
sourceFile.fileName = normalizePath(fileName);
sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0;
@@ -956,13 +955,6 @@ module ts {
// attached to the EOF token.
var parseErrorBeforeNextFinishedNode: boolean = false;
- sourceFile.syntacticDiagnostics = undefined;
- sourceFile.referenceDiagnostics = [];
- sourceFile.parseDiagnostics = [];
- sourceFile.semanticDiagnostics = [];
- sourceFile.end = sourceText.length;
- sourceFile.text = sourceText;
-
// Create and prime the scanner before parsing the source elements.
scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError);
token = nextToken();
@@ -4697,7 +4689,7 @@ module ts {
referencedFiles.push(fileReference);
}
if (diagnosticMessage) {
- sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
+ sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
}
}
else {
@@ -4705,7 +4697,7 @@ module ts {
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
if (amdModuleNameMatchResult) {
if (amdModuleName) {
- sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
+ sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
}
amdModuleName = amdModuleNameMatchResult[2];
}
diff --git a/src/compiler/program.ts b/src/compiler/program.ts
index e764e20f29f..954c443a77c 100644
--- a/src/compiler/program.ts
+++ b/src/compiler/program.ts
@@ -2,6 +2,8 @@
///
module ts {
+ /* @internal */ export var emitTime = 0;
+
export function createCompilerHost(options: CompilerOptions): CompilerHost {
var currentDirectory: string;
var existingDirectories: Map = {};
@@ -21,9 +23,9 @@ module ts {
}
catch (e) {
if (onError) {
- onError(e.number === unsupportedFileEncodingErrorCode ?
- createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText :
- e.message);
+ onError(e.number === unsupportedFileEncodingErrorCode
+ ? createCompilerDiagnostic(Diagnostics.Unsupported_file_encoding).messageText
+ : e.message);
}
text = "";
}
@@ -73,90 +75,168 @@ module ts {
};
}
- export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program {
+ 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[] = [];
var filesByName: Map = {};
- var errors: Diagnostic[] = [];
+ var diagnostics = createDiagnosticCollection();
var seenNoDefaultLib = options.noLib;
var commonSourceDirectory: string;
+ host = host || createCompilerHost(options);
forEach(rootNames, name => processRootFile(name, false));
if (!seenNoDefaultLib) {
processRootFile(host.getDefaultLibFileName(options), true);
}
verifyCompilerOptions();
- errors.sort(compareDiagnostics);
-
var diagnosticsProducingTypeChecker: TypeChecker;
var noDiagnosticsTypeChecker: TypeChecker;
- var emitHost: EmitHost;
program = {
getSourceFile: getSourceFile,
getSourceFiles: () => files,
getCompilerOptions: () => options,
- getCompilerHost: () => host,
- getDiagnostics: getDiagnostics,
- getGlobalDiagnostics: getGlobalDiagnostics,
- getDeclarationDiagnostics: getDeclarationDiagnostics,
+ getSyntacticDiagnostics,
+ getGlobalDiagnostics,
+ getSemanticDiagnostics,
+ getDeclarationDiagnostics,
getTypeChecker,
+ getDiagnosticsProducingTypeChecker,
getCommonSourceDirectory: () => commonSourceDirectory,
- emitFiles: invokeEmitter,
- isEmitBlocked,
+ emit,
getCurrentDirectory: host.getCurrentDirectory,
+ getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(),
+ getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
+ getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
+ getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
};
return program;
- function getEmitHost() {
- return emitHost || (emitHost = createEmitHostFromProgram(program));
- }
-
- function isEmitBlocked(sourceFile?: SourceFile): boolean {
- if (options.noEmitOnError) {
- return getDiagnostics(sourceFile).length !== 0 || getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile).length !== 0;
- }
-
- return false;
+ function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
+ return {
+ getCanonicalFileName: host.getCanonicalFileName,
+ getCommonSourceDirectory: program.getCommonSourceDirectory,
+ getCompilerOptions: program.getCompilerOptions,
+ getCurrentDirectory: host.getCurrentDirectory,
+ getNewLine: host.getNewLine,
+ getSourceFile: program.getSourceFile,
+ getSourceFiles: program.getSourceFiles,
+ writeFile: writeFileCallback || host.writeFile,
+ };
}
function getDiagnosticsProducingTypeChecker() {
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true));
}
- function getTypeChecker(produceDiagnostics: boolean) {
- if (produceDiagnostics) {
- return getDiagnosticsProducingTypeChecker();
- }
- else {
- return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, produceDiagnostics));
- }
+ function getTypeChecker() {
+ return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
}
- function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[]{
- var typeChecker = getDiagnosticsProducingTypeChecker();
- typeChecker.getDiagnostics(targetSourceFile);
- var resolver = typeChecker.getEmitResolver();
+ function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
+ var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile);
return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile);
}
- function invokeEmitter(targetSourceFile?: SourceFile) {
- var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver();
- return emitFiles(resolver, getEmitHost(), targetSourceFile);
+ function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult {
+ // If the noEmitOnError flag is set, then check if we have any errors so far. If so,
+ // immediately bail out.
+ if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) {
+ return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
+ }
+
+ var start = new Date().getTime();
+
+ var emitResult = emitFiles(
+ getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile),
+ getEmitHost(writeFileCallback),
+ sourceFile);
+
+ emitTime += new Date().getTime() - start;
+ return emitResult;
}
-
+
function getSourceFile(fileName: string) {
fileName = host.getCanonicalFileName(fileName);
return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined;
}
- function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
- return sourceFile ? filter(errors, e => e.file === sourceFile) : errors;
+ function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] {
+ if (sourceFile) {
+ return getDiagnostics(sourceFile);
+ }
+
+ var allDiagnostics: Diagnostic[] = [];
+ forEach(program.getSourceFiles(), sourceFile => {
+ addRange(allDiagnostics, getDiagnostics(sourceFile));
+ });
+
+ return sortAndDeduplicateDiagnostics(allDiagnostics);
+ }
+
+ function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
+ return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile);
+ }
+
+ function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] {
+ return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile);
+ }
+
+ function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
+ return sourceFile.parseDiagnostics;
+ }
+
+ 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 getGlobalDiagnostics(): Diagnostic[] {
- return filter(errors, e => !e.file);
+ var typeChecker = getDiagnosticsProducingTypeChecker();
+
+ var allDiagnostics: Diagnostic[] = [];
+ addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
+ addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
+
+ return sortAndDeduplicateDiagnostics(allDiagnostics);
}
function hasExtension(fileName: string): boolean {
@@ -196,10 +276,10 @@ module ts {
if (diagnostic) {
if (refFile) {
- errors.push(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
+ diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName));
}
else {
- errors.push(createCompilerDiagnostic(diagnostic, fileName));
+ diagnostics.add(createCompilerDiagnostic(diagnostic, fileName));
}
}
}
@@ -221,11 +301,11 @@ module ts {
// We haven't looked for this file, do so now and cache result
var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => {
if (refFile) {
- errors.push(createFileDiagnostic(refFile, refStart, refLength,
+ diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
}
else {
- errors.push(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
}
});
if (file) {
@@ -245,9 +325,6 @@ module ts {
else {
files.push(file);
}
- forEach(getSyntacticDiagnostics(file), e => {
- errors.push(e);
- });
}
}
return file;
@@ -257,7 +334,7 @@ module ts {
if (file && host.useCaseSensitiveFileNames()) {
var sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
if (canonicalName !== sourceFileName) {
- errors.push(createFileDiagnostic(refFile, refStart, refLength,
+ diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
}
}
@@ -331,10 +408,10 @@ module ts {
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
if (options.mapRoot) {
- errors.push(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option));
}
if (options.sourceRoot) {
- errors.push(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option));
}
return;
}
@@ -345,7 +422,7 @@ module ts {
var externalModuleErrorSpan = getErrorSpanForNode(firstExternalModule.externalModuleIndicator);
var errorStart = skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos);
var errorLength = externalModuleErrorSpan.end - errorStart;
- errors.push(createFileDiagnostic(firstExternalModule, errorStart, errorLength, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
+ diagnostics.add(createFileDiagnostic(firstExternalModule, errorStart, errorLength, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
}
// there has to be common source directory if user specified --outdir || --sourcRoot
@@ -366,7 +443,7 @@ module ts {
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
if (commonPathComponents[i] !== sourcePathComponents[i]) {
if (i === 0) {
- errors.push(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
return;
}
@@ -399,11 +476,11 @@ module ts {
if (options.noEmit) {
if (options.out || options.outDir) {
- errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
}
if (options.declaration) {
- errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
+ diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
}
}
}
diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts
index cf71869ab14..4bcd0856ca8 100644
--- a/src/compiler/tsc.ts
+++ b/src/compiler/tsc.ts
@@ -78,8 +78,8 @@ module ts {
}
function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string {
- var diagnostic: Diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
- return diagnostic.messageText;
+ var diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
+ return diagnostic.messageText;
}
function reportDiagnostic(diagnostic: Diagnostic) {
@@ -92,7 +92,7 @@ module ts {
}
var category = DiagnosticCategory[diagnostic.category].toLowerCase();
- output += category + " TS" + diagnostic.code + ": " + diagnostic.messageText + sys.newLine;
+ output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) + sys.newLine;
sys.write(output);
}
@@ -165,7 +165,7 @@ module ts {
if (commandLine.options.locale) {
if (!isJSONSupported()) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
}
@@ -174,29 +174,29 @@ module ts {
// setting up localization, report them and quit.
if (commandLine.errors.length > 0) {
reportDiagnostics(commandLine.errors);
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
if (commandLine.options.version) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version));
- return sys.exit(EmitReturnStatus.Succeeded);
+ return sys.exit(ExitStatus.Success);
}
if (commandLine.options.help) {
printVersion();
printHelp();
- return sys.exit(EmitReturnStatus.Succeeded);
+ return sys.exit(ExitStatus.Success);
}
if (commandLine.options.project) {
if (!isJSONSupported()) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
configFileName = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json"));
if (commandLine.fileNames.length !== 0) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
}
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
@@ -206,13 +206,13 @@ module ts {
if (commandLine.fileNames.length === 0 && !configFileName) {
printVersion();
printHelp();
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.Success);
}
if (commandLine.options.watch) {
if (!sys.watchFile) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
if (configFileName) {
configFileWatcher = sys.watchFile(configFileName, configFileChanged);
@@ -229,12 +229,12 @@ module ts {
var configObject = readConfigFile(configFileName);
if (!configObject) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName));
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFileName));
if (configParseResult.errors.length > 0) {
reportDiagnostics(configParseResult.errors);
- return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
+ return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
rootFileNames = configParseResult.fileNames;
compilerOptions = extend(commandLine.options, configParseResult.options);
@@ -322,40 +322,17 @@ module ts {
}
function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) {
- var parseStart = new Date().getTime();
+ ts.parseTime = 0;
+ ts.bindTime = 0;
+ ts.checkTime = 0;
+ ts.emitTime = 0;
+
+ var start = new Date().getTime();
+
var program = createProgram(fileNames, compilerOptions, compilerHost);
+ var exitStatus = compileProgram();
- var bindStart = new Date().getTime();
- var errors: Diagnostic[] = program.getDiagnostics();
- var exitStatus: EmitReturnStatus;
-
- if (errors.length) {
- var checkStart = bindStart;
- var emitStart = bindStart;
- var reportStart = bindStart;
- exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
- }
- else {
- var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
- var checkStart = new Date().getTime();
- errors = checker.getDiagnostics();
- if (program.isEmitBlocked()) {
- exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
- }
- else if (compilerOptions.noEmit) {
- exitStatus = EmitReturnStatus.Succeeded;
- }
- else {
- var emitStart = new Date().getTime();
- var emitOutput = program.emitFiles();
- var emitErrors = emitOutput.diagnostics;
- exitStatus = emitOutput.emitResultStatus;
- var reportStart = new Date().getTime();
- errors = concatenate(errors, emitErrors);
- }
- }
-
- reportDiagnostics(errors);
+ var end = start - new Date().getTime();
if (compilerOptions.listFiles) {
forEach(program.getSourceFiles(), file => {
@@ -367,21 +344,65 @@ module ts {
var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
reportCountStatistic("Files", program.getSourceFiles().length);
reportCountStatistic("Lines", countLines(program));
- reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0);
- reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0);
- reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0);
- reportCountStatistic("Types", checker ? checker.getTypeCount() : 0);
+ reportCountStatistic("Nodes", program.getNodeCount());
+ reportCountStatistic("Identifiers", program.getIdentifierCount());
+ reportCountStatistic("Symbols", program.getSymbolCount());
+ reportCountStatistic("Types", program.getTypeCount());
+
if (memoryUsed >= 0) {
reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
}
- reportTimeStatistic("Parse time", bindStart - parseStart);
- reportTimeStatistic("Bind time", checkStart - bindStart);
- reportTimeStatistic("Check time", emitStart - checkStart);
- reportTimeStatistic("Emit time", reportStart - emitStart);
- reportTimeStatistic("Total time", reportStart - parseStart);
+
+ reportTimeStatistic("Parse time", ts.parseTime);
+ reportTimeStatistic("Bind time", ts.bindTime);
+ reportTimeStatistic("Check time", ts.checkTime);
+ reportTimeStatistic("Emit time", ts.emitTime);
+ reportTimeStatistic("Total time", start - end);
}
return { program, exitStatus };
+
+ function compileProgram(): ExitStatus {
+ // First get any syntactic errors.
+ var diagnostics = program.getSyntacticDiagnostics();
+ reportDiagnostics(diagnostics);
+
+ // If we didn't have any syntactic errors, then also try getting the global and
+ // semantic errors.
+ if (diagnostics.length === 0) {
+ var diagnostics = program.getGlobalDiagnostics();
+ reportDiagnostics(diagnostics);
+
+ if (diagnostics.length === 0) {
+ var diagnostics = program.getSemanticDiagnostics();
+ reportDiagnostics(diagnostics);
+ }
+ }
+
+ // If the user doesn't want us to emit, then we're done at this point.
+ if (compilerOptions.noEmit) {
+ return diagnostics.length
+ ? ExitStatus.DiagnosticsPresent_OutputsSkipped
+ : ExitStatus.Success;
+ }
+
+ // Otherwise, emit and report any errors we ran into.
+ var emitOutput = program.emit();
+ reportDiagnostics(emitOutput.diagnostics);
+
+ // If the emitter didn't emit anything, then pass that value along.
+ if (emitOutput.emitSkipped) {
+ return ExitStatus.DiagnosticsPresent_OutputsSkipped;
+ }
+
+ // The emitter emitted something, inform the caller if that happened in the presence
+ // of diagnostics or not.
+ if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
+ ExitStatus.DiagnosticsPresent_OutputsGenerated;
+ }
+
+ return ExitStatus.Success;
+ }
}
function printVersion() {
diff --git a/src/compiler/types.ts b/src/compiler/types.ts
index ff8f5d2ed48..1c79ef169e9 100644
--- a/src/compiler/types.ts
+++ b/src/compiler/types.ts
@@ -892,41 +892,26 @@ module ts {
referencedFiles: FileReference[];
hasNoDefaultLib: boolean;
- externalModuleIndicator: Node; // The first node that causes this file to be an external module
+
+ // The first node that causes this file to be an external module
+ externalModuleIndicator: Node;
languageVersion: ScriptTarget;
identifiers: Map;
- // @internal
- nodeCount: number;
+ /* @internal */ nodeCount: number;
+ /* @internal */ identifierCount: number;
+ /* @internal */ symbolCount: number;
- // @internal
- identifierCount: number;
-
- // @internal
- symbolCount: number;
-
- // @internal
- // Diagnostics reported about the "/// void): void;
+ }
+
export interface Program extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- getCompilerHost(): CompilerHost;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+
+ 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.
- // The 'produceDiagnostics' flag determines if the checker will produce diagnostics while
- // analyzing the code. It can be set to 'false' to make many type checking operaitons
- // faster. With this flag set, the checker can avoid codepaths only necessary to produce
- // diagnostics, but not necessary to answer semantic questions about the code.
- //
- // If 'produceDiagnostics' is false, then any calls to get diagnostics from the TypeChecker
- // will throw an invalid operation exception.
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
+ getTypeChecker(): TypeChecker;
+
getCommonSourceDirectory(): string;
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
- isEmitBlocked(sourceFile?: SourceFile): boolean;
+ // For testing purposes only. Should not be used by any other consumers (including the
+ // language service).
+ /* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
+
+ /* @internal */ getNodeCount(): number;
+ /* @internal */ getIdentifierCount(): number;
+ /* @internal */ getSymbolCount(): number;
+ /* @internal */ getTypeCount(): number;
}
export interface SourceMapSpan {
@@ -980,37 +981,33 @@ 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
+ export enum ExitStatus {
+ // Compiler ran successfully. Either this was a simple do-nothing compilation (for example,
+ // when -version or -help was provided, or this was a normal compilation, no diagnostics
+ // were produced, and all outputs were generated successfully.
+ Success = 0,
+
+ // Diagnostics were produced and because of them no code was generated.
+ DiagnosticsPresent_OutputsSkipped = 1,
+
+ // Diagnostics were produced and outputs were generated in spite of them.
+ DiagnosticsPresent_OutputsGenerated = 2,
}
export interface EmitResult {
- emitResultStatus: EmitReturnStatus;
+ emitSkipped: boolean;
diagnostics: Diagnostic[];
sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
}
export interface TypeCheckerHost {
getCompilerOptions(): CompilerOptions;
- getCompilerHost(): CompilerHost;
getSourceFiles(): SourceFile[];
getSourceFile(fileName: string): SourceFile;
}
export interface TypeChecker {
- getEmitResolver(): EmitResolver;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
- getGlobalDiagnostics(): Diagnostic[];
- getNodeCount(): number;
- getIdentifierCount(): number;
- getSymbolCount(): number;
- getTypeCount(): number;
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
@@ -1035,10 +1032,19 @@ module ts {
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
- // Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value.
- getEnumMemberValue(node: EnumMember): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
+
+ // Should not be called directly. Should only be accessed through the Program instance.
+ /* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /* @internal */ getGlobalDiagnostics(): Diagnostic[];
+ /* @internal */ getEmitResolver(sourceFile?: SourceFile): EmitResolver;
+
+ /* @internal */ getNodeCount(): number;
+ /* @internal */ getIdentifierCount(): number;
+ /* @internal */ getSymbolCount(): number;
+ /* @internal */ getTypeCount(): number;
}
export interface SymbolDisplayBuilder {
@@ -1123,8 +1129,6 @@ module ts {
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
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;
@@ -1132,7 +1136,7 @@ module ts {
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isUnknownIdentifier(location: Node, name: string): boolean;
}
@@ -1436,7 +1440,7 @@ module ts {
file: SourceFile;
start: number;
length: number;
- messageText: string;
+ messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
code: number;
}
@@ -1662,7 +1666,7 @@ module ts {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFileName(options: CompilerOptions): string;
getCancellationToken? (): CancellationToken;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
@@ -1678,4 +1682,24 @@ module ts {
span: TextSpan;
newLength: number;
}
+
+ // @internal
+ export interface DiagnosticCollection {
+ // Adds a diagnostic to this diagnostic collection.
+ add(diagnostic: Diagnostic): void;
+
+ // Gets all the diagnostics that aren't associated with a file.
+ getGlobalDiagnostics(): Diagnostic[];
+
+ // If fileName is provided, gets all the diagnostics associated with that file name.
+ // Otherwise, returns all the diagnostics (global and file associated) in this colletion.
+ getDiagnostics(fileName?: string): Diagnostic[];
+
+ // Gets a count of how many times this collection has been modified. This value changes
+ // each time 'add' is called (regardless of whether or not an equivalent diagnostic was
+ // already in the collection). As such, it can be used as a simple way to tell if any
+ // operation caused diagnostics to be returned by storing and comparing the return value
+ // of this method before/after the operation is performed.
+ getModificationCount(): number;
+ }
}
diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts
index f95952dc5c5..5a50e2799dc 100644
--- a/src/compiler/utilities.ts
+++ b/src/compiler/utilities.ts
@@ -25,13 +25,12 @@ module ts {
export interface EmitHost extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- isEmitBlocked(sourceFile?: SourceFile): boolean;
getCommonSourceDirectory(): string;
getCanonicalFileName(fileName: string): string;
getNewLine(): string;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
}
// Pool writers to avoid needing to allocate them for every symbol we write.
@@ -199,12 +198,19 @@ module ts {
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
}
- export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic {
+ export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic {
node = getErrorSpanForNode(node);
var file = getSourceFileOfNode(node);
var start = skipTrivia(file.text, node.pos);
var length = node.end - start;
- return flattenDiagnosticChain(file, start, length, messageChain, newLine);
+ return {
+ file,
+ start,
+ length,
+ code: messageChain.code,
+ category: messageChain.category,
+ messageText: messageChain.next ? messageChain : messageChain.messageText
+ };
}
export function getErrorSpanForNode(node: Node): Node {
@@ -843,21 +849,6 @@ module ts {
return false;
}
- export function createEmitHostFromProgram(program: Program): EmitHost {
- var compilerHost = program.getCompilerHost();
- return {
- getCanonicalFileName: compilerHost.getCanonicalFileName,
- getCommonSourceDirectory: program.getCommonSourceDirectory,
- getCompilerOptions: program.getCompilerOptions,
- getCurrentDirectory: compilerHost.getCurrentDirectory,
- getNewLine: compilerHost.getNewLine,
- getSourceFile: program.getSourceFile,
- getSourceFiles: program.getSourceFiles,
- isEmitBlocked: program.isEmitBlocked,
- writeFile: compilerHost.writeFile,
- };
- }
-
export function textSpanEnd(span: TextSpan) {
return span.start + span.length
}
@@ -1068,4 +1059,84 @@ module ts {
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN);
}
+
+ // @internal
+ export function createDiagnosticCollection(): DiagnosticCollection {
+ var nonFileDiagnostics: Diagnostic[] = [];
+ var fileDiagnostics: Map = {};
+
+ var diagnosticsModified = false;
+ var modificationCount = 0;
+
+ return {
+ add,
+ getGlobalDiagnostics,
+ getDiagnostics,
+ getModificationCount
+ };
+
+ function getModificationCount() {
+ return modificationCount;
+ }
+
+ function add(diagnostic: Diagnostic): void {
+ var diagnostics: Diagnostic[];
+ if (diagnostic.file) {
+ diagnostics = fileDiagnostics[diagnostic.file.fileName];
+ if (!diagnostics) {
+ diagnostics = [];
+ fileDiagnostics[diagnostic.file.fileName] = diagnostics;
+ }
+ }
+ else {
+ diagnostics = nonFileDiagnostics;
+ }
+
+ diagnostics.push(diagnostic);
+ diagnosticsModified = true;
+ modificationCount++;
+ }
+
+ function getGlobalDiagnostics(): Diagnostic[] {
+ sortAndDeduplicate();
+ return nonFileDiagnostics;
+ }
+
+ function getDiagnostics(fileName?: string): Diagnostic[] {
+ sortAndDeduplicate();
+ if (fileName) {
+ return fileDiagnostics[fileName] || [];
+ }
+
+ var allDiagnostics: Diagnostic[] = [];
+ function pushDiagnostic(d: Diagnostic) {
+ allDiagnostics.push(d);
+ }
+
+ forEach(nonFileDiagnostics, pushDiagnostic);
+
+ for (var key in fileDiagnostics) {
+ if (hasProperty(fileDiagnostics, key)) {
+ forEach(fileDiagnostics[key], pushDiagnostic);
+ }
+ }
+
+ return sortAndDeduplicateDiagnostics(allDiagnostics);
+ }
+
+ function sortAndDeduplicate() {
+ if (!diagnosticsModified) {
+ return;
+ }
+
+ diagnosticsModified = false;
+ nonFileDiagnostics = sortAndDeduplicateDiagnostics(nonFileDiagnostics);
+
+ for (var key in fileDiagnostics) {
+ if (hasProperty(fileDiagnostics, key)) {
+ fileDiagnostics[key] = sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts
index a88620c4e6c..e4979f7a3c4 100644
--- a/src/harness/compilerRunner.ts
+++ b/src/harness/compilerRunner.ts
@@ -256,11 +256,40 @@ class CompilerBaselineRunner extends RunnerBase {
it('Correct type baselines for ' + fileName, () => {
// NEWTODO: Type baselines
if (result.errors.length === 0) {
- Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => {
+ // The full walker simulates the types that you would get from doing a full
+ // compile. The pull walker simulates the types you get when you just do
+ // a type query for a random node (like how the LS would do it). Most of the
+ // time, these will be the same. However, occasionally, they can be different.
+ // Specifically, when the compiler internally depends on symbol IDs to order
+ // things, then we may see different results because symbols can be created in a
+ // different order with 'pull' operations, and thus can produce slightly differing
+ // output.
+ //
+ // For example, with a full type check, we may see a type outputed as: number | string
+ // But with a pull type check, we may see it as: string | number
+ //
+ // These types are equivalent, but depend on what order the compiler observed
+ // certain parts of the program.
+
+ var fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
+ var pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
+
+ var fullTypes = generateTypes(fullWalker);
+ var pullTypes = generateTypes(pullWalker);
+
+ if (fullTypes !== pullTypes) {
+ Harness.Baseline.runBaseline('Correct full expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
+ Harness.Baseline.runBaseline('Correct pull expression types for ' + fileName, justName.replace(/\.ts/, '.types.pull'), () => pullTypes);
+ }
+ else {
+ Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
+ }
+
+ function generateTypes(walker: TypeWriterWalker): string {
var allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
var typeLines: string[] = [];
var typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
- var walker = new TypeWriterWalker(program);
+
allFiles.forEach(file => {
var codeLines = file.content.split('\n');
walker.getTypes(file.unitName).forEach(result => {
@@ -299,7 +328,7 @@ class CompilerBaselineRunner extends RunnerBase {
});
return typeLines.join('');
- });
+ }
}
});
});
diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts
index 46a18ff0790..d829ce0b83e 100644
--- a/src/harness/fourslash.ts
+++ b/src/harness/fourslash.ts
@@ -513,7 +513,9 @@ module FourSlash {
}
errors.forEach(function (error: ts.Diagnostic) {
- Harness.IO.log(" minChar: " + error.start + ", limChar: " + (error.start + error.length) + ", message: " + error.messageText + "\n");
+ Harness.IO.log(" minChar: " + error.start +
+ ", limChar: " + (error.start + error.length) +
+ ", message: " + ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine) + "\n");
});
}
@@ -1147,16 +1149,24 @@ module FourSlash {
// Loop through all the emittedFiles and emit them one by one
emitFiles.forEach(emitFile => {
var emitOutput = this.languageService.getEmitOutput(emitFile.fileName);
- var emitOutputStatus = emitOutput.emitOutputStatus;
// Print emitOutputStatus in readable format
- resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus];
- resultString += "\n";
+ resultString += "EmitSkipped: " + emitOutput.emitSkipped + ts.sys.newLine;
+
+ if (emitOutput.emitSkipped) {
+ 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 */);
@@ -1188,7 +1198,10 @@ module FourSlash {
if (errorList.length) {
errorList.forEach(err => {
- Harness.IO.log("start: " + err.start + ", length: " + err.length + ", message: " + err.messageText);
+ Harness.IO.log(
+ "start: " + err.start +
+ ", length: " + err.length +
+ ", message: " + ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine));
});
}
}
@@ -1402,7 +1415,7 @@ module FourSlash {
var incrementalSourceFile = this.languageService.getSourceFile(this.activeFile.fileName);
Utils.assertInvariants(incrementalSourceFile, /*parent:*/ undefined);
- var incrementalSyntaxDiagnostics = ts.getSyntacticDiagnostics(incrementalSourceFile);
+ var incrementalSyntaxDiagnostics = incrementalSourceFile.parseDiagnostics;
// Check syntactic structure
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
@@ -1410,7 +1423,7 @@ module FourSlash {
var referenceSourceFile = ts.createLanguageServiceSourceFile(
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false);
- var referenceSyntaxDiagnostics = ts.getSyntacticDiagnostics(referenceSourceFile);
+ var referenceSyntaxDiagnostics = referenceSourceFile.parseDiagnostics;
Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics);
Utils.assertStructuralEquals(incrementalSourceFile, referenceSourceFile);
@@ -2219,13 +2232,13 @@ 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 => e.messageText).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.emitFiles();
+ program.emit();
result = result || ''; // Might have an empty fourslash file
// Compile and execute the test
diff --git a/src/harness/harness.ts b/src/harness/harness.ts
index c17a8da78e8..8002b019551 100644
--- a/src/harness/harness.ts
+++ b/src/harness/harness.ts
@@ -183,7 +183,7 @@ module Utils {
return {
start: diagnostic.start,
length: diagnostic.length,
- messageText: diagnostic.messageText,
+ messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine),
category: (ts).DiagnosticCategory[diagnostic.category],
code: diagnostic.code
};
@@ -305,7 +305,9 @@ module Utils {
assert.equal(d1.start, d2.start, "d1.start !== d2.start");
assert.equal(d1.length, d2.length, "d1.length !== d2.length");
- assert.equal(d1.messageText, d2.messageText, "d1.messageText !== d2.messageText");
+ assert.equal(
+ ts.flattenDiagnosticMessageText(d1.messageText, ts.sys.newLine),
+ ts.flattenDiagnosticMessageText(d2.messageText, ts.sys.newLine), "d1.messageText !== d2.messageText");
assert.equal(d1.category, d2.category, "d1.category !== d2.category");
assert.equal(d1.code, d2.code, "d1.code !== d2.code");
}
@@ -1074,30 +1076,22 @@ module Harness {
otherFiles.forEach(register);
var fileOutputs: GeneratedFile[] = [];
-
+
var programFiles = inputFiles.map(file => file.unitName);
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(otherFiles),
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
options.target, useCaseSensitiveFileNames, currentDirectory));
- var checker = program.getTypeChecker(/*produceDiagnostics*/ true);
-
- var isEmitBlocked = program.isEmitBlocked();
-
- // only emit if there weren't parse errors
- var emitResult: ts.EmitResult;
- if (!isEmitBlocked) {
- emitResult = program.emitFiles();
- }
+ var emitResult = program.emit();
var errors: HarnessDiagnostic[] = [];
- program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? 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));
});
this.lastErrors = errors;
- var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined);
+ var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
onComplete(result, program);
// reset what newline means in case the last test changed it
@@ -1189,7 +1183,7 @@ module Harness {
end: err.start + err.length,
line: errorLineInfo.line,
character: errorLineInfo.character,
- message: err.messageText,
+ message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine),
category: ts.DiagnosticCategory[err.category].toLowerCase(),
code: err.code
};
diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts
index d7510c7879e..547f8ccce48 100644
--- a/src/harness/harnessLanguageService.ts
+++ b/src/harness/harnessLanguageService.ts
@@ -134,6 +134,10 @@ module Harness.LanguageService {
public trace(s: string) {
}
+ public getNewLine(): string {
+ return "\r\n";
+ }
+
public addDefaultLibrary() {
this.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
}
diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts
index fac5219f5c1..0fde9a9d77c 100644
--- a/src/harness/projectsRunner.ts
+++ b/src/harness/projectsRunner.ts
@@ -127,24 +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) {
- var checker = program.getTypeChecker(/*produceDiagnostics:*/ true);
- errors = checker.getDiagnostics();
- var emitResult = program.emitFiles();
- 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);
}
}
@@ -276,14 +272,14 @@ class ProjectRunner extends RunnerBase {
function compileCompileDTsFiles(compilerResult: BatchCompileProjectTestCaseResult) {
var allInputFiles: { emittedFileName: string; code: string; }[] = [];
var compilerOptions = compilerResult.program.getCompilerOptions();
- var compilerHost = compilerResult.program.getCompilerHost();
+
ts.forEach(compilerResult.program.getSourceFiles(), sourceFile => {
if (Harness.Compiler.isDTS(sourceFile.fileName)) {
allInputFiles.unshift({ emittedFileName: sourceFile.fileName, code: sourceFile.text });
}
else if (ts.shouldEmitToOwnFile(sourceFile, compilerResult.program.getCompilerOptions())) {
if (compilerOptions.outDir) {
- var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, compilerHost.getCurrentDirectory());
+ var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, compilerResult.program.getCurrentDirectory());
sourceFilePath = sourceFilePath.replace(compilerResult.program.getCommonSourceDirectory(), "");
var emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath));
}
diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts
index 332173d218f..1d8b3efef68 100644
--- a/src/harness/typeWriter.ts
+++ b/src/harness/typeWriter.ts
@@ -12,10 +12,12 @@ class TypeWriterWalker {
private checker: ts.TypeChecker;
- constructor(private program: ts.Program) {
+ constructor(private program: ts.Program, fullTypeCheck: boolean) {
// Consider getting both the diagnostics checker and the non-diagnostics checker to verify
// they are consistent.
- this.checker = program.getTypeChecker(/*produceDiagnostics:*/ true);
+ this.checker = fullTypeCheck
+ ? program.getDiagnosticsProducingTypeChecker()
+ : program.getTypeChecker();
}
public getTypes(fileName: string): TypeWriterResult[] {
diff --git a/src/services/services.ts b/src/services/services.ts
index d328af1ee35..fad7632843a 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -64,7 +64,6 @@ module ts {
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionFromLineAndCharacter(line: number, character: number): number;
- getSyntacticDiagnostics(): Diagnostic[];
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
@@ -733,7 +732,7 @@ module ts {
public syntacticDiagnostics: Diagnostic[];
public referenceDiagnostics: Diagnostic[];
public parseDiagnostics: Diagnostic[];
- public semanticDiagnostics: Diagnostic[];
+ public bindDiagnostics: Diagnostic[];
public hasNoDefaultLib: boolean;
public externalModuleIndicator: Node; // The first node that causes this file to be an external module
@@ -747,10 +746,6 @@ module ts {
private namedDeclarations: Declaration[];
- public getSyntacticDiagnostics(): Diagnostic[]{
- return getSyntacticDiagnostics(this);
- }
-
public update(newText: string, textChangeRange: TextChangeRange): SourceFile {
return updateSourceFile(this, newText, textChangeRange);
}
@@ -1128,7 +1123,7 @@ module ts {
export interface EmitOutput {
outputFiles: OutputFile[];
- emitOutputStatus: EmitReturnStatus;
+ emitSkipped: boolean;
}
export const enum OutputFileType {
@@ -2025,10 +2020,6 @@ module ts {
return sourceFile;
}
- function getDiagnosticsProducingTypeChecker() {
- return program.getTypeChecker(/*produceDiagnostics:*/ true);
- }
-
function getRuleProvider(options: FormatCodeOptions) {
// Ensure rules are initialized and up to date wrt to formatting options
if (!ruleProvider) {
@@ -2077,7 +2068,7 @@ module ts {
}
program = newProgram;
- typeInfoResolver = program.getTypeChecker(/*produceDiagnostics*/ false);
+ typeInfoResolver = program.getTypeChecker();
return;
@@ -2156,7 +2147,7 @@ module ts {
*/
function cleanupSemanticCache(): void {
if (program) {
- typeInfoResolver = program.getTypeChecker(/*produceDiagnostics*/ false);
+ typeInfoResolver = program.getTypeChecker();
}
}
@@ -2173,7 +2164,7 @@ module ts {
fileName = normalizeSlashes(fileName);
- return program.getDiagnostics(getValidSourceFile(fileName));
+ return program.getSyntacticDiagnostics(getValidSourceFile(fileName));
}
/**
@@ -2184,19 +2175,19 @@ module ts {
synchronizeHostData();
fileName = normalizeSlashes(fileName)
- var compilerOptions = program.getCompilerOptions();
- var checker = getDiagnosticsProducingTypeChecker();
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 = checker.getDiagnostics(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() {
@@ -3070,7 +3061,7 @@ module ts {
addPrefixForAnyFunctionOrVar(symbol, "enum member");
var declaration = symbol.declarations[0];
if (declaration.kind === SyntaxKind.EnumMember) {
- var constantValue = typeResolver.getEnumMemberValue(declaration);
+ var constantValue = typeResolver.getConstantValue(declaration);
if (constantValue !== undefined) {
displayParts.push(spacePart());
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
@@ -4763,16 +4754,11 @@ module ts {
});
}
- // Get an emit host from our program, but override the writeFile functionality to
- // call our local writer function.
- var emitHost = createEmitHostFromProgram(program);
- emitHost.writeFile = writeFile;
-
- var emitOutput = emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(), emitHost, sourceFile);
+ var emitOutput = program.emit(sourceFile, writeFile);
return {
outputFiles,
- emitOutputStatus: emitOutput.emitResultStatus
+ emitSkipped: emitOutput.emitSkipped
};
}
diff --git a/src/services/shims.ts b/src/services/shims.ts
index c5b2b24108d..5b5216813fe 100644
--- a/src/services/shims.ts
+++ b/src/services/shims.ts
@@ -52,6 +52,7 @@ module ts {
getCancellationToken(): CancellationToken;
getCurrentDirectory(): string;
getDefaultLibFileName(options: string): string;
+ getNewLine?(): string;
}
///
@@ -367,9 +368,14 @@ module ts {
});
}
- private static realizeDiagnostic(diagnostic: Diagnostic): { message: string; start: number; length: number; category: string; } {
+ private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[]{
+ var newLine = this.getNewLine();
+ return diagnostics.map(d => this.realizeDiagnostic(d, newLine));
+ }
+
+ private realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } {
return {
- message: diagnostic.messageText,
+ message: flattenDiagnosticMessageText(diagnostic.messageText, newLine),
start: diagnostic.start,
length: diagnostic.length,
/// TODO: no need for the tolowerCase call
@@ -396,12 +402,16 @@ module ts {
});
}
+ private getNewLine(): string {
+ return this.host.getNewLine ? this.host.getNewLine() : "\r\n";
+ }
+
public getSyntacticDiagnostics(fileName: string): string {
return this.forwardJSONCall(
"getSyntacticDiagnostics('" + fileName + "')",
() => {
- var errors = this.languageService.getSyntacticDiagnostics(fileName);
- return errors.map(LanguageServiceShimObject.realizeDiagnostic);
+ var diagnostics = this.languageService.getSyntacticDiagnostics(fileName);
+ return this.realizeDiagnostics(diagnostics);
});
}
@@ -409,8 +419,8 @@ module ts {
return this.forwardJSONCall(
"getSemanticDiagnostics('" + fileName + "')",
() => {
- var errors = this.languageService.getSemanticDiagnostics(fileName);
- return errors.map(LanguageServiceShimObject.realizeDiagnostic);
+ var diagnostics = this.languageService.getSemanticDiagnostics(fileName);
+ return this.realizeDiagnostics(diagnostics);
});
}
@@ -418,8 +428,8 @@ module ts {
return this.forwardJSONCall(
"getCompilerOptionsDiagnostics()",
() => {
- var errors = this.languageService.getCompilerOptionsDiagnostics();
- return errors.map(LanguageServiceShimObject.realizeDiagnostic)
+ var diagnostics = this.languageService.getCompilerOptionsDiagnostics();
+ return this.realizeDiagnostics(diagnostics);
});
}
diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js
index 88013c70916..6840f079972 100644
--- a/tests/baselines/reference/APISample_compile.js
+++ b/tests/baselines/reference/APISample_compile.js
@@ -10,26 +10,24 @@
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 host = ts.createCompilerHost(options);
- var program = ts.createProgram(fileNames, options, host);
- var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
- var result = program.emitFiles();
+ var program = ts.createProgram(fileNames, options);
+ var emitResult = program.emit();
- var allDiagnostics = program.getDiagnostics()
- .concat(checker.getDiagnostics())
- .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);
+ var exitCode = emitResult.emitSkipped ? 1 : 0;
+ console.log(`Process exiting with code '${exitCode}'.`);
+ process.exit(exitCode);
}
compile(process.argv.slice(2), {
@@ -738,16 +736,28 @@ declare module "typescript" {
getSourceFile(fileName: string): SourceFile;
getCurrentDirectory(): string;
}
+ interface WriteFileCallback {
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ }
interface Program extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- getCompilerHost(): CompilerHost;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
- getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
+ getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getTypeChecker(): TypeChecker;
getCommonSourceDirectory(): string;
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
- isEmitBlocked(sourceFile?: SourceFile): boolean;
}
interface SourceMapSpan {
emittedLine: number;
@@ -768,33 +778,22 @@ declare module "typescript" {
sourceMapMappings: string;
sourceMapDecodedMappings: SourceMapSpan[];
}
- enum EmitReturnStatus {
- Succeeded = 0,
- AllOutputGenerationSkipped = 1,
- JSGeneratedWithSemanticErrors = 2,
- DeclarationGenerationSkipped = 3,
- EmitErrorsEncountered = 4,
- CompilerOptionsErrors = 5,
+ enum ExitStatus {
+ Success = 0,
+ DiagnosticsPresent_OutputsSkipped = 1,
+ DiagnosticsPresent_OutputsGenerated = 2,
}
interface EmitResult {
- emitResultStatus: EmitReturnStatus;
+ emitSkipped: boolean;
diagnostics: Diagnostic[];
sourceMaps: SourceMapData[];
}
interface TypeCheckerHost {
getCompilerOptions(): CompilerOptions;
- getCompilerHost(): CompilerHost;
getSourceFiles(): SourceFile[];
getSourceFile(fileName: string): SourceFile;
}
interface TypeChecker {
- getEmitResolver(): EmitResolver;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
- getGlobalDiagnostics(): Diagnostic[];
- getNodeCount(): number;
- getIdentifierCount(): number;
- getSymbolCount(): number;
- getTypeCount(): number;
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
@@ -818,7 +817,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
- getEnumMemberValue(node: EnumMember): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
}
@@ -884,15 +883,13 @@ declare module "typescript" {
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
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;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isUnknownIdentifier(location: Node, name: string): boolean;
}
const enum SymbolFlags {
@@ -1139,7 +1136,7 @@ declare module "typescript" {
file: SourceFile;
start: number;
length: number;
- messageText: string;
+ messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
code: number;
}
@@ -1343,7 +1340,7 @@ declare module "typescript" {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFileName(options: CompilerOptions): string;
getCancellationToken?(): CancellationToken;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
@@ -1407,7 +1404,6 @@ declare module "typescript" {
function createNode(kind: SyntaxKind): Node;
function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
function modifierToFlag(token: SyntaxKind): NodeFlags;
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
function isEvalOrArgumentsIdentifier(node: Node): boolean;
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1419,7 +1415,9 @@ declare module "typescript" {
}
declare module "typescript" {
function createCompilerHost(options: CompilerOptions): CompilerHost;
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
+ 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" {
var servicesVersion: string;
@@ -1471,7 +1469,6 @@ declare module "typescript" {
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionFromLineAndCharacter(line: number, character: number): number;
- getSyntacticDiagnostics(): Diagnostic[];
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
/**
@@ -1724,7 +1721,7 @@ declare module "typescript" {
}
interface EmitOutput {
outputFiles: OutputFile[];
- emitOutputStatus: EmitReturnStatus;
+ emitSkipped: boolean;
}
const enum OutputFileType {
JavaScript = 0,
@@ -1920,17 +1917,16 @@ declare module "typescript" {
*/
var ts = require("typescript");
function compile(fileNames, options) {
- var host = ts.createCompilerHost(options);
- var program = ts.createProgram(fileNames, options, host);
- var checker = ts.createTypeChecker(program, true);
- var result = program.emitFiles();
- var allDiagnostics = program.getDiagnostics().concat(checker.getDiagnostics()).concat(result.diagnostics);
+ var program = ts.createProgram(fileNames, options);
+ 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);
+ var exitCode = emitResult.emitSkipped ? 1 : 0;
+ console.log("Process exiting with code '" + exitCode + "'.");
+ process.exit(exitCode);
}
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 024434be63b..d70172377ca 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
@@ -22,69 +25,42 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
>ts : unknown
>CompilerOptions : ts.CompilerOptions
- var host = ts.createCompilerHost(options);
->host : ts.CompilerHost
->ts.createCompilerHost(options) : ts.CompilerHost
->ts.createCompilerHost : (options: ts.CompilerOptions) => ts.CompilerHost
->ts : typeof ts
->createCompilerHost : (options: ts.CompilerOptions) => ts.CompilerHost
->options : ts.CompilerOptions
-
- var program = ts.createProgram(fileNames, options, host);
+ var program = ts.createProgram(fileNames, options);
>program : ts.Program
->ts.createProgram(fileNames, options, host) : ts.Program
->ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host: ts.CompilerHost) => ts.Program
+>ts.createProgram(fileNames, options) : ts.Program
+>ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
>ts : typeof ts
->createProgram : (rootNames: string[], options: ts.CompilerOptions, host: ts.CompilerHost) => ts.Program
+>createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
>fileNames : string[]
>options : ts.CompilerOptions
->host : ts.CompilerHost
- var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
->checker : ts.TypeChecker
->ts.createTypeChecker(program, /*produceDiagnostics*/ true) : ts.TypeChecker
->ts.createTypeChecker : (host: ts.TypeCheckerHost, produceDiagnostics: boolean) => ts.TypeChecker
->ts : typeof ts
->createTypeChecker : (host: ts.TypeCheckerHost, produceDiagnostics: boolean) => ts.TypeChecker
+ 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 result = program.emitFiles();
->result : ts.EmitResult
->program.emitFiles() : ts.EmitResult
->program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
->program : ts.Program
->emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
-
- var allDiagnostics = program.getDiagnostics()
+ var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
>allDiagnostics : ts.Diagnostic[]
->program.getDiagnostics() .concat(checker.getDiagnostics()) .concat(result.diagnostics) : ts.Diagnostic[]
->program.getDiagnostics() .concat(checker.getDiagnostics()) .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
->program.getDiagnostics() .concat(checker.getDiagnostics()) : 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(checker.getDiagnostics())
>concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
->checker.getDiagnostics() : ts.Diagnostic[]
->checker.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
->checker : ts.TypeChecker
->getDiagnostics : (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);
@@ -99,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
@@ -115,29 +91,39 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
>lineChar.character : number
>lineChar : ts.LineAndCharacter
>character : number
->diagnostic.messageText : string
+>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
+>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
+ var exitCode = emitResult.emitSkipped ? 1 : 0;
+>exitCode : number
+>emitResult.emitSkipped ? 1 : 0 : number
+>emitResult.emitSkipped : boolean
+>emitResult : ts.EmitResult
+>emitSkipped : boolean
+
+ console.log(`Process exiting with code '${exitCode}'.`);
+>console.log(`Process exiting with code '${exitCode}'.`) : any
>console.log : any
>console : any
>log : any
->result.emitResultStatus : ts.EmitReturnStatus
->result : ts.EmitResult
->emitResultStatus : ts.EmitReturnStatus
+>exitCode : number
- process.exit(result.emitResultStatus);
->process.exit(result.emitResultStatus) : any
+ process.exit(exitCode);
+>process.exit(exitCode) : any
>process.exit : any
>process : any
>exit : any
->result.emitResultStatus : ts.EmitReturnStatus
->result : ts.EmitResult
->emitResultStatus : ts.EmitReturnStatus
+>exitCode : number
}
compile(process.argv.slice(2), {
@@ -2248,6 +2234,16 @@ declare module "typescript" {
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
+ }
+ interface WriteFileCallback {
+>WriteFileCallback : WriteFileCallback
+
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+>fileName : string
+>data : string
+>writeByteOrderMark : boolean
+>onError : (message: string) => void
+>message : string
}
interface Program extends ScriptReferenceHost {
>Program : Program
@@ -2257,12 +2253,26 @@ declare module "typescript" {
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
+>targetSourceFile : SourceFile
+>SourceFile : SourceFile
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
+>EmitResult : EmitResult
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
>sourceFile : SourceFile
>SourceFile : SourceFile
>Diagnostic : Diagnostic
@@ -2271,30 +2281,24 @@ 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
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
->produceDiagnostics : boolean
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+>sourceFile : SourceFile
+>SourceFile : SourceFile
+>Diagnostic : Diagnostic
+
+ getTypeChecker(): TypeChecker;
+>getTypeChecker : () => TypeChecker
>TypeChecker : TypeChecker
getCommonSourceDirectory(): string;
>getCommonSourceDirectory : () => string
-
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
->emitFiles : (targetSourceFile?: SourceFile) => EmitResult
->targetSourceFile : SourceFile
->SourceFile : SourceFile
->EmitResult : EmitResult
-
- isEmitBlocked(sourceFile?: SourceFile): boolean;
->isEmitBlocked : (sourceFile?: SourceFile) => boolean
->sourceFile : SourceFile
->SourceFile : SourceFile
}
interface SourceMapSpan {
>SourceMapSpan : SourceMapSpan
@@ -2348,33 +2352,23 @@ declare module "typescript" {
>sourceMapDecodedMappings : SourceMapSpan[]
>SourceMapSpan : SourceMapSpan
}
- enum EmitReturnStatus {
->EmitReturnStatus : EmitReturnStatus
+ enum ExitStatus {
+>ExitStatus : ExitStatus
- Succeeded = 0,
->Succeeded : EmitReturnStatus
+ Success = 0,
+>Success : ExitStatus
- AllOutputGenerationSkipped = 1,
->AllOutputGenerationSkipped : EmitReturnStatus
+ DiagnosticsPresent_OutputsSkipped = 1,
+>DiagnosticsPresent_OutputsSkipped : ExitStatus
- JSGeneratedWithSemanticErrors = 2,
->JSGeneratedWithSemanticErrors : EmitReturnStatus
-
- DeclarationGenerationSkipped = 3,
->DeclarationGenerationSkipped : EmitReturnStatus
-
- EmitErrorsEncountered = 4,
->EmitErrorsEncountered : EmitReturnStatus
-
- CompilerOptionsErrors = 5,
->CompilerOptionsErrors : EmitReturnStatus
+ DiagnosticsPresent_OutputsGenerated = 2,
+>DiagnosticsPresent_OutputsGenerated : ExitStatus
}
interface EmitResult {
>EmitResult : EmitResult
- emitResultStatus: EmitReturnStatus;
->emitResultStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
diagnostics: Diagnostic[];
>diagnostics : Diagnostic[]
@@ -2391,10 +2385,6 @@ declare module "typescript" {
>getCompilerOptions : () => CompilerOptions
>CompilerOptions : CompilerOptions
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
-
getSourceFiles(): SourceFile[];
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
@@ -2407,32 +2397,6 @@ declare module "typescript" {
interface TypeChecker {
>TypeChecker : TypeChecker
- getEmitResolver(): EmitResolver;
->getEmitResolver : () => EmitResolver
->EmitResolver : EmitResolver
-
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
- getGlobalDiagnostics(): Diagnostic[];
->getGlobalDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
- getNodeCount(): number;
->getNodeCount : () => number
-
- getIdentifierCount(): number;
->getIdentifierCount : () => number
-
- getSymbolCount(): number;
->getSymbolCount : () => number
-
- getTypeCount(): number;
->getTypeCount : () => number
-
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
>symbol : Symbol
@@ -2582,10 +2546,12 @@ declare module "typescript" {
>symbol : Symbol
>Symbol : Symbol
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->node : EnumMember
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
>EnumMember : EnumMember
+>PropertyAccessExpression : PropertyAccessExpression
+>ElementAccessExpression : ElementAccessExpression
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
@@ -2872,16 +2838,6 @@ declare module "typescript" {
>Node : Node
>NodeCheckFlags : NodeCheckFlags
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->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
@@ -2933,9 +2889,10 @@ declare module "typescript" {
>Node : Node
>SymbolVisibilityResult : SymbolVisibilityResult
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
->getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
->node : PropertyAccessExpression | ElementAccessExpression
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
+>EnumMember : EnumMember
>PropertyAccessExpression : PropertyAccessExpression
>ElementAccessExpression : ElementAccessExpression
@@ -3676,8 +3633,9 @@ declare module "typescript" {
length: number;
>length : number
- messageText: string;
->messageText : string
+ messageText: string | DiagnosticMessageChain;
+>messageText : string | DiagnosticMessageChain
+>DiagnosticMessageChain : DiagnosticMessageChain
category: DiagnosticCategory;
>category : DiagnosticCategory
@@ -4276,13 +4234,9 @@ declare module "typescript" {
>getCancellationToken : () => CancellationToken
>CancellationToken : CancellationToken
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
->writeFile : (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
->fileName : string
->data : string
->writeByteOrderMark : boolean
->onError : (message: string) => void
->message : string
+ writeFile: WriteFileCallback;
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
@@ -4530,12 +4484,6 @@ declare module "typescript" {
>SyntaxKind : SyntaxKind
>NodeFlags : NodeFlags
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
->getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
>sourceFile : SourceFile
@@ -4584,8 +4532,20 @@ declare module "typescript" {
>CompilerOptions : CompilerOptions
>CompilerHost : CompilerHost
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
->createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
+ 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[]
>options : CompilerOptions
>CompilerOptions : CompilerOptions
@@ -4780,10 +4740,6 @@ declare module "typescript" {
>line : number
>character : number
- getSyntacticDiagnostics(): Diagnostic[];
->getSyntacticDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
>newText : string
@@ -5534,9 +5490,8 @@ declare module "typescript" {
>outputFiles : OutputFile[]
>OutputFile : OutputFile
- emitOutputStatus: EmitReturnStatus;
->emitOutputStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
}
const enum OutputFileType {
>OutputFileType : OutputFileType
diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js
index c429cec1d1c..c8bec722309 100644
--- a/tests/baselines/reference/APISample_linter.js
+++ b/tests/baselines/reference/APISample_linter.js
@@ -767,16 +767,28 @@ declare module "typescript" {
getSourceFile(fileName: string): SourceFile;
getCurrentDirectory(): string;
}
+ interface WriteFileCallback {
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ }
interface Program extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- getCompilerHost(): CompilerHost;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
- getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
+ getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getTypeChecker(): TypeChecker;
getCommonSourceDirectory(): string;
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
- isEmitBlocked(sourceFile?: SourceFile): boolean;
}
interface SourceMapSpan {
emittedLine: number;
@@ -797,33 +809,22 @@ declare module "typescript" {
sourceMapMappings: string;
sourceMapDecodedMappings: SourceMapSpan[];
}
- enum EmitReturnStatus {
- Succeeded = 0,
- AllOutputGenerationSkipped = 1,
- JSGeneratedWithSemanticErrors = 2,
- DeclarationGenerationSkipped = 3,
- EmitErrorsEncountered = 4,
- CompilerOptionsErrors = 5,
+ enum ExitStatus {
+ Success = 0,
+ DiagnosticsPresent_OutputsSkipped = 1,
+ DiagnosticsPresent_OutputsGenerated = 2,
}
interface EmitResult {
- emitResultStatus: EmitReturnStatus;
+ emitSkipped: boolean;
diagnostics: Diagnostic[];
sourceMaps: SourceMapData[];
}
interface TypeCheckerHost {
getCompilerOptions(): CompilerOptions;
- getCompilerHost(): CompilerHost;
getSourceFiles(): SourceFile[];
getSourceFile(fileName: string): SourceFile;
}
interface TypeChecker {
- getEmitResolver(): EmitResolver;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
- getGlobalDiagnostics(): Diagnostic[];
- getNodeCount(): number;
- getIdentifierCount(): number;
- getSymbolCount(): number;
- getTypeCount(): number;
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
@@ -847,7 +848,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
- getEnumMemberValue(node: EnumMember): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
}
@@ -913,15 +914,13 @@ declare module "typescript" {
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
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;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isUnknownIdentifier(location: Node, name: string): boolean;
}
const enum SymbolFlags {
@@ -1168,7 +1167,7 @@ declare module "typescript" {
file: SourceFile;
start: number;
length: number;
- messageText: string;
+ messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
code: number;
}
@@ -1372,7 +1371,7 @@ declare module "typescript" {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFileName(options: CompilerOptions): string;
getCancellationToken?(): CancellationToken;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
@@ -1436,7 +1435,6 @@ declare module "typescript" {
function createNode(kind: SyntaxKind): Node;
function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
function modifierToFlag(token: SyntaxKind): NodeFlags;
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
function isEvalOrArgumentsIdentifier(node: Node): boolean;
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1448,7 +1446,9 @@ declare module "typescript" {
}
declare module "typescript" {
function createCompilerHost(options: CompilerOptions): CompilerHost;
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
+ 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" {
var servicesVersion: string;
@@ -1500,7 +1500,6 @@ declare module "typescript" {
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionFromLineAndCharacter(line: number, character: number): number;
- getSyntacticDiagnostics(): Diagnostic[];
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
/**
@@ -1753,7 +1752,7 @@ declare module "typescript" {
}
interface EmitOutput {
outputFiles: OutputFile[];
- emitOutputStatus: EmitReturnStatus;
+ emitSkipped: boolean;
}
const enum OutputFileType {
JavaScript = 0,
diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types
index 89411159d9a..26254c69d54 100644
--- a/tests/baselines/reference/APISample_linter.types
+++ b/tests/baselines/reference/APISample_linter.types
@@ -2378,6 +2378,16 @@ declare module "typescript" {
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
+ }
+ interface WriteFileCallback {
+>WriteFileCallback : WriteFileCallback
+
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+>fileName : string
+>data : string
+>writeByteOrderMark : boolean
+>onError : (message: string) => void
+>message : string
}
interface Program extends ScriptReferenceHost {
>Program : Program
@@ -2387,12 +2397,26 @@ declare module "typescript" {
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
+>targetSourceFile : SourceFile
+>SourceFile : SourceFile
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
+>EmitResult : EmitResult
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
>sourceFile : SourceFile
>SourceFile : SourceFile
>Diagnostic : Diagnostic
@@ -2401,30 +2425,24 @@ 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
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
->produceDiagnostics : boolean
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+>sourceFile : SourceFile
+>SourceFile : SourceFile
+>Diagnostic : Diagnostic
+
+ getTypeChecker(): TypeChecker;
+>getTypeChecker : () => TypeChecker
>TypeChecker : TypeChecker
getCommonSourceDirectory(): string;
>getCommonSourceDirectory : () => string
-
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
->emitFiles : (targetSourceFile?: SourceFile) => EmitResult
->targetSourceFile : SourceFile
->SourceFile : SourceFile
->EmitResult : EmitResult
-
- isEmitBlocked(sourceFile?: SourceFile): boolean;
->isEmitBlocked : (sourceFile?: SourceFile) => boolean
->sourceFile : SourceFile
->SourceFile : SourceFile
}
interface SourceMapSpan {
>SourceMapSpan : SourceMapSpan
@@ -2478,33 +2496,23 @@ declare module "typescript" {
>sourceMapDecodedMappings : SourceMapSpan[]
>SourceMapSpan : SourceMapSpan
}
- enum EmitReturnStatus {
->EmitReturnStatus : EmitReturnStatus
+ enum ExitStatus {
+>ExitStatus : ExitStatus
- Succeeded = 0,
->Succeeded : EmitReturnStatus
+ Success = 0,
+>Success : ExitStatus
- AllOutputGenerationSkipped = 1,
->AllOutputGenerationSkipped : EmitReturnStatus
+ DiagnosticsPresent_OutputsSkipped = 1,
+>DiagnosticsPresent_OutputsSkipped : ExitStatus
- JSGeneratedWithSemanticErrors = 2,
->JSGeneratedWithSemanticErrors : EmitReturnStatus
-
- DeclarationGenerationSkipped = 3,
->DeclarationGenerationSkipped : EmitReturnStatus
-
- EmitErrorsEncountered = 4,
->EmitErrorsEncountered : EmitReturnStatus
-
- CompilerOptionsErrors = 5,
->CompilerOptionsErrors : EmitReturnStatus
+ DiagnosticsPresent_OutputsGenerated = 2,
+>DiagnosticsPresent_OutputsGenerated : ExitStatus
}
interface EmitResult {
>EmitResult : EmitResult
- emitResultStatus: EmitReturnStatus;
->emitResultStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
diagnostics: Diagnostic[];
>diagnostics : Diagnostic[]
@@ -2521,10 +2529,6 @@ declare module "typescript" {
>getCompilerOptions : () => CompilerOptions
>CompilerOptions : CompilerOptions
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
-
getSourceFiles(): SourceFile[];
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
@@ -2537,32 +2541,6 @@ declare module "typescript" {
interface TypeChecker {
>TypeChecker : TypeChecker
- getEmitResolver(): EmitResolver;
->getEmitResolver : () => EmitResolver
->EmitResolver : EmitResolver
-
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
- getGlobalDiagnostics(): Diagnostic[];
->getGlobalDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
- getNodeCount(): number;
->getNodeCount : () => number
-
- getIdentifierCount(): number;
->getIdentifierCount : () => number
-
- getSymbolCount(): number;
->getSymbolCount : () => number
-
- getTypeCount(): number;
->getTypeCount : () => number
-
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
>symbol : Symbol
@@ -2712,10 +2690,12 @@ declare module "typescript" {
>symbol : Symbol
>Symbol : Symbol
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->node : EnumMember
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
>EnumMember : EnumMember
+>PropertyAccessExpression : PropertyAccessExpression
+>ElementAccessExpression : ElementAccessExpression
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
@@ -3002,16 +2982,6 @@ declare module "typescript" {
>Node : Node
>NodeCheckFlags : NodeCheckFlags
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->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
@@ -3063,9 +3033,10 @@ declare module "typescript" {
>Node : Node
>SymbolVisibilityResult : SymbolVisibilityResult
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
->getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
->node : PropertyAccessExpression | ElementAccessExpression
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
+>EnumMember : EnumMember
>PropertyAccessExpression : PropertyAccessExpression
>ElementAccessExpression : ElementAccessExpression
@@ -3806,8 +3777,9 @@ declare module "typescript" {
length: number;
>length : number
- messageText: string;
->messageText : string
+ messageText: string | DiagnosticMessageChain;
+>messageText : string | DiagnosticMessageChain
+>DiagnosticMessageChain : DiagnosticMessageChain
category: DiagnosticCategory;
>category : DiagnosticCategory
@@ -4406,13 +4378,9 @@ declare module "typescript" {
>getCancellationToken : () => CancellationToken
>CancellationToken : CancellationToken
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
->writeFile : (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
->fileName : string
->data : string
->writeByteOrderMark : boolean
->onError : (message: string) => void
->message : string
+ writeFile: WriteFileCallback;
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
@@ -4660,12 +4628,6 @@ declare module "typescript" {
>SyntaxKind : SyntaxKind
>NodeFlags : NodeFlags
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
->getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
>sourceFile : SourceFile
@@ -4714,8 +4676,20 @@ declare module "typescript" {
>CompilerOptions : CompilerOptions
>CompilerHost : CompilerHost
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
->createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
+ 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[]
>options : CompilerOptions
>CompilerOptions : CompilerOptions
@@ -4910,10 +4884,6 @@ declare module "typescript" {
>line : number
>character : number
- getSyntacticDiagnostics(): Diagnostic[];
->getSyntacticDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
>newText : string
@@ -5664,9 +5634,8 @@ declare module "typescript" {
>outputFiles : OutputFile[]
>OutputFile : OutputFile
- emitOutputStatus: EmitReturnStatus;
->emitOutputStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
}
const enum OutputFileType {
>OutputFileType : OutputFileType
diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js
index 2ed4242460f..ad66d289eb7 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,18 +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
- var checker = program.getTypeChecker(true);
- errors = checker.getDiagnostics();
- // Generate output
- program.emitFiles();
- }
+ 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);
+ })
};
}
@@ -768,16 +768,28 @@ declare module "typescript" {
getSourceFile(fileName: string): SourceFile;
getCurrentDirectory(): string;
}
+ interface WriteFileCallback {
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ }
interface Program extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- getCompilerHost(): CompilerHost;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
- getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
+ getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getTypeChecker(): TypeChecker;
getCommonSourceDirectory(): string;
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
- isEmitBlocked(sourceFile?: SourceFile): boolean;
}
interface SourceMapSpan {
emittedLine: number;
@@ -798,33 +810,22 @@ declare module "typescript" {
sourceMapMappings: string;
sourceMapDecodedMappings: SourceMapSpan[];
}
- enum EmitReturnStatus {
- Succeeded = 0,
- AllOutputGenerationSkipped = 1,
- JSGeneratedWithSemanticErrors = 2,
- DeclarationGenerationSkipped = 3,
- EmitErrorsEncountered = 4,
- CompilerOptionsErrors = 5,
+ enum ExitStatus {
+ Success = 0,
+ DiagnosticsPresent_OutputsSkipped = 1,
+ DiagnosticsPresent_OutputsGenerated = 2,
}
interface EmitResult {
- emitResultStatus: EmitReturnStatus;
+ emitSkipped: boolean;
diagnostics: Diagnostic[];
sourceMaps: SourceMapData[];
}
interface TypeCheckerHost {
getCompilerOptions(): CompilerOptions;
- getCompilerHost(): CompilerHost;
getSourceFiles(): SourceFile[];
getSourceFile(fileName: string): SourceFile;
}
interface TypeChecker {
- getEmitResolver(): EmitResolver;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
- getGlobalDiagnostics(): Diagnostic[];
- getNodeCount(): number;
- getIdentifierCount(): number;
- getSymbolCount(): number;
- getTypeCount(): number;
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
@@ -848,7 +849,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
- getEnumMemberValue(node: EnumMember): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
}
@@ -914,15 +915,13 @@ declare module "typescript" {
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
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;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isUnknownIdentifier(location: Node, name: string): boolean;
}
const enum SymbolFlags {
@@ -1169,7 +1168,7 @@ declare module "typescript" {
file: SourceFile;
start: number;
length: number;
- messageText: string;
+ messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
code: number;
}
@@ -1373,7 +1372,7 @@ declare module "typescript" {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFileName(options: CompilerOptions): string;
getCancellationToken?(): CancellationToken;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
@@ -1437,7 +1436,6 @@ declare module "typescript" {
function createNode(kind: SyntaxKind): Node;
function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
function modifierToFlag(token: SyntaxKind): NodeFlags;
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
function isEvalOrArgumentsIdentifier(node: Node): boolean;
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1449,7 +1447,9 @@ declare module "typescript" {
}
declare module "typescript" {
function createCompilerHost(options: CompilerOptions): CompilerHost;
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
+ 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" {
var servicesVersion: string;
@@ -1501,7 +1501,6 @@ declare module "typescript" {
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionFromLineAndCharacter(line: number, character: number): number;
- getSyntacticDiagnostics(): Diagnostic[];
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
/**
@@ -1754,7 +1753,7 @@ declare module "typescript" {
}
interface EmitOutput {
outputFiles: OutputFile[];
- emitOutputStatus: EmitReturnStatus;
+ emitSkipped: boolean;
}
const enum OutputFileType {
JavaScript = 0,
@@ -1975,19 +1974,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
- var checker = program.getTypeChecker(true);
- errors = checker.getDiagnostics();
- // Generate output
- program.emitFiles();
- }
+ 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 f44d2f787eb..c6d74cc811d 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
@@ -139,67 +142,58 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost);
>program : ts.Program
>ts.createProgram(["file.ts"], compilerOptions, compilerHost) : ts.Program
->ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host: ts.CompilerHost) => ts.Program
+>ts.createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
>ts : typeof ts
->createProgram : (rootNames: string[], options: ts.CompilerOptions, host: ts.CompilerHost) => ts.Program
+>createProgram : (rootNames: string[], options: ts.CompilerOptions, host?: ts.CompilerHost) => ts.Program
>["file.ts"] : 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
+ 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[]
->length : number
-
- // Type check and get semantic errors
- var checker = program.getTypeChecker(true);
->checker : ts.TypeChecker
->program.getTypeChecker(true) : ts.TypeChecker
->program.getTypeChecker : (produceDiagnostics: boolean) => ts.TypeChecker
->program : ts.Program
->getTypeChecker : (produceDiagnostics: boolean) => ts.TypeChecker
-
- errors = checker.getDiagnostics();
->errors = checker.getDiagnostics() : ts.Diagnostic[]
+>errors.concat(emitResult.diagnostics) : ts.Diagnostic[]
+>errors.concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
>errors : ts.Diagnostic[]
->checker.getDiagnostics() : ts.Diagnostic[]
->checker.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
->checker : ts.TypeChecker
->getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[]
+>concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; }
+>emitResult.diagnostics : ts.Diagnostic[]
+>emitResult : ts.EmitResult
+>diagnostics : ts.Diagnostic[]
- // Generate output
- program.emitFiles();
->program.emitFiles() : ts.EmitResult
->program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
->program : ts.Program
->emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult
- }
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
@@ -219,10 +213,20 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) {
>e : ts.Diagnostic
>start : number
>line : number
->e.messageText : string
->e : ts.Diagnostic
->messageText : string
+ + 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
+
+ })
};
}
@@ -2326,6 +2330,16 @@ declare module "typescript" {
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
+ }
+ interface WriteFileCallback {
+>WriteFileCallback : WriteFileCallback
+
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+>fileName : string
+>data : string
+>writeByteOrderMark : boolean
+>onError : (message: string) => void
+>message : string
}
interface Program extends ScriptReferenceHost {
>Program : Program
@@ -2335,12 +2349,26 @@ declare module "typescript" {
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
+>targetSourceFile : SourceFile
+>SourceFile : SourceFile
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
+>EmitResult : EmitResult
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
>sourceFile : SourceFile
>SourceFile : SourceFile
>Diagnostic : Diagnostic
@@ -2349,30 +2377,24 @@ 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
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
->produceDiagnostics : boolean
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+>sourceFile : SourceFile
+>SourceFile : SourceFile
+>Diagnostic : Diagnostic
+
+ getTypeChecker(): TypeChecker;
+>getTypeChecker : () => TypeChecker
>TypeChecker : TypeChecker
getCommonSourceDirectory(): string;
>getCommonSourceDirectory : () => string
-
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
->emitFiles : (targetSourceFile?: SourceFile) => EmitResult
->targetSourceFile : SourceFile
->SourceFile : SourceFile
->EmitResult : EmitResult
-
- isEmitBlocked(sourceFile?: SourceFile): boolean;
->isEmitBlocked : (sourceFile?: SourceFile) => boolean
->sourceFile : SourceFile
->SourceFile : SourceFile
}
interface SourceMapSpan {
>SourceMapSpan : SourceMapSpan
@@ -2426,33 +2448,23 @@ declare module "typescript" {
>sourceMapDecodedMappings : SourceMapSpan[]
>SourceMapSpan : SourceMapSpan
}
- enum EmitReturnStatus {
->EmitReturnStatus : EmitReturnStatus
+ enum ExitStatus {
+>ExitStatus : ExitStatus
- Succeeded = 0,
->Succeeded : EmitReturnStatus
+ Success = 0,
+>Success : ExitStatus
- AllOutputGenerationSkipped = 1,
->AllOutputGenerationSkipped : EmitReturnStatus
+ DiagnosticsPresent_OutputsSkipped = 1,
+>DiagnosticsPresent_OutputsSkipped : ExitStatus
- JSGeneratedWithSemanticErrors = 2,
->JSGeneratedWithSemanticErrors : EmitReturnStatus
-
- DeclarationGenerationSkipped = 3,
->DeclarationGenerationSkipped : EmitReturnStatus
-
- EmitErrorsEncountered = 4,
->EmitErrorsEncountered : EmitReturnStatus
-
- CompilerOptionsErrors = 5,
->CompilerOptionsErrors : EmitReturnStatus
+ DiagnosticsPresent_OutputsGenerated = 2,
+>DiagnosticsPresent_OutputsGenerated : ExitStatus
}
interface EmitResult {
>EmitResult : EmitResult
- emitResultStatus: EmitReturnStatus;
->emitResultStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
diagnostics: Diagnostic[];
>diagnostics : Diagnostic[]
@@ -2469,10 +2481,6 @@ declare module "typescript" {
>getCompilerOptions : () => CompilerOptions
>CompilerOptions : CompilerOptions
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
-
getSourceFiles(): SourceFile[];
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
@@ -2485,32 +2493,6 @@ declare module "typescript" {
interface TypeChecker {
>TypeChecker : TypeChecker
- getEmitResolver(): EmitResolver;
->getEmitResolver : () => EmitResolver
->EmitResolver : EmitResolver
-
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
- getGlobalDiagnostics(): Diagnostic[];
->getGlobalDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
- getNodeCount(): number;
->getNodeCount : () => number
-
- getIdentifierCount(): number;
->getIdentifierCount : () => number
-
- getSymbolCount(): number;
->getSymbolCount : () => number
-
- getTypeCount(): number;
->getTypeCount : () => number
-
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
>symbol : Symbol
@@ -2660,10 +2642,12 @@ declare module "typescript" {
>symbol : Symbol
>Symbol : Symbol
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->node : EnumMember
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
>EnumMember : EnumMember
+>PropertyAccessExpression : PropertyAccessExpression
+>ElementAccessExpression : ElementAccessExpression
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
@@ -2950,16 +2934,6 @@ declare module "typescript" {
>Node : Node
>NodeCheckFlags : NodeCheckFlags
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->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
@@ -3011,9 +2985,10 @@ declare module "typescript" {
>Node : Node
>SymbolVisibilityResult : SymbolVisibilityResult
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
->getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
->node : PropertyAccessExpression | ElementAccessExpression
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
+>EnumMember : EnumMember
>PropertyAccessExpression : PropertyAccessExpression
>ElementAccessExpression : ElementAccessExpression
@@ -3754,8 +3729,9 @@ declare module "typescript" {
length: number;
>length : number
- messageText: string;
->messageText : string
+ messageText: string | DiagnosticMessageChain;
+>messageText : string | DiagnosticMessageChain
+>DiagnosticMessageChain : DiagnosticMessageChain
category: DiagnosticCategory;
>category : DiagnosticCategory
@@ -4354,13 +4330,9 @@ declare module "typescript" {
>getCancellationToken : () => CancellationToken
>CancellationToken : CancellationToken
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
->writeFile : (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
->fileName : string
->data : string
->writeByteOrderMark : boolean
->onError : (message: string) => void
->message : string
+ writeFile: WriteFileCallback;
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
@@ -4608,12 +4580,6 @@ declare module "typescript" {
>SyntaxKind : SyntaxKind
>NodeFlags : NodeFlags
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
->getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
>sourceFile : SourceFile
@@ -4662,8 +4628,20 @@ declare module "typescript" {
>CompilerOptions : CompilerOptions
>CompilerHost : CompilerHost
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
->createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
+ 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[]
>options : CompilerOptions
>CompilerOptions : CompilerOptions
@@ -4858,10 +4836,6 @@ declare module "typescript" {
>line : number
>character : number
- getSyntacticDiagnostics(): Diagnostic[];
->getSyntacticDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
>newText : string
@@ -5612,9 +5586,8 @@ declare module "typescript" {
>outputFiles : OutputFile[]
>OutputFile : OutputFile
- emitOutputStatus: EmitReturnStatus;
->emitOutputStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
}
const enum OutputFileType {
>OutputFileType : OutputFileType
diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js
index 80dc949ade1..2add8dfd45e 100644
--- a/tests/baselines/reference/APISample_watcher.js
+++ b/tests/baselines/reference/APISample_watcher.js
@@ -67,7 +67,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
function emitFile(fileName: string) {
var output = services.getEmitOutput(fileName);
- if (output.emitOutputStatus === ts.EmitReturnStatus.Succeeded) {
+ if (!output.emitSkipped) {
console.log(`Emitting ${fileName}`);
}
else {
@@ -88,7 +88,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
allDiagnostics.forEach(diagnostic => {
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
- console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
+ console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
}
else {
console.log(` Error: ${diagnostic.messageText}`);
@@ -805,16 +805,28 @@ declare module "typescript" {
getSourceFile(fileName: string): SourceFile;
getCurrentDirectory(): string;
}
+ interface WriteFileCallback {
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ }
interface Program extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
- getCompilerHost(): CompilerHost;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
- getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
+ getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+ getTypeChecker(): TypeChecker;
getCommonSourceDirectory(): string;
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
- isEmitBlocked(sourceFile?: SourceFile): boolean;
}
interface SourceMapSpan {
emittedLine: number;
@@ -835,33 +847,22 @@ declare module "typescript" {
sourceMapMappings: string;
sourceMapDecodedMappings: SourceMapSpan[];
}
- enum EmitReturnStatus {
- Succeeded = 0,
- AllOutputGenerationSkipped = 1,
- JSGeneratedWithSemanticErrors = 2,
- DeclarationGenerationSkipped = 3,
- EmitErrorsEncountered = 4,
- CompilerOptionsErrors = 5,
+ enum ExitStatus {
+ Success = 0,
+ DiagnosticsPresent_OutputsSkipped = 1,
+ DiagnosticsPresent_OutputsGenerated = 2,
}
interface EmitResult {
- emitResultStatus: EmitReturnStatus;
+ emitSkipped: boolean;
diagnostics: Diagnostic[];
sourceMaps: SourceMapData[];
}
interface TypeCheckerHost {
getCompilerOptions(): CompilerOptions;
- getCompilerHost(): CompilerHost;
getSourceFiles(): SourceFile[];
getSourceFile(fileName: string): SourceFile;
}
interface TypeChecker {
- getEmitResolver(): EmitResolver;
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
- getGlobalDiagnostics(): Diagnostic[];
- getNodeCount(): number;
- getIdentifierCount(): number;
- getSymbolCount(): number;
- getTypeCount(): number;
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
@@ -885,7 +886,7 @@ declare module "typescript" {
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
- getEnumMemberValue(node: EnumMember): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
}
@@ -951,15 +952,13 @@ declare module "typescript" {
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
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;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
isUnknownIdentifier(location: Node, name: string): boolean;
}
const enum SymbolFlags {
@@ -1206,7 +1205,7 @@ declare module "typescript" {
file: SourceFile;
start: number;
length: number;
- messageText: string;
+ messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
code: number;
}
@@ -1410,7 +1409,7 @@ declare module "typescript" {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFileName(options: CompilerOptions): string;
getCancellationToken?(): CancellationToken;
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+ writeFile: WriteFileCallback;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
@@ -1474,7 +1473,6 @@ declare module "typescript" {
function createNode(kind: SyntaxKind): Node;
function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
function modifierToFlag(token: SyntaxKind): NodeFlags;
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
function isEvalOrArgumentsIdentifier(node: Node): boolean;
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile;
@@ -1486,7 +1484,9 @@ declare module "typescript" {
}
declare module "typescript" {
function createCompilerHost(options: CompilerOptions): CompilerHost;
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
+ 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" {
var servicesVersion: string;
@@ -1538,7 +1538,6 @@ declare module "typescript" {
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionFromLineAndCharacter(line: number, character: number): number;
- getSyntacticDiagnostics(): Diagnostic[];
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
/**
@@ -1791,7 +1790,7 @@ declare module "typescript" {
}
interface EmitOutput {
outputFiles: OutputFile[];
- emitOutputStatus: EmitReturnStatus;
+ emitSkipped: boolean;
}
const enum OutputFileType {
JavaScript = 0,
@@ -2026,7 +2025,7 @@ function watch(rootFileNames, options) {
});
function emitFile(fileName) {
var output = services.getEmitOutput(fileName);
- if (output.emitOutputStatus === 0 /* Succeeded */) {
+ if (!output.emitSkipped) {
console.log("Emitting " + fileName);
}
else {
@@ -2042,7 +2041,7 @@ function watch(rootFileNames, options) {
allDiagnostics.forEach(function (diagnostic) {
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
- console.log(" Error " + diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText);
+ console.log(" Error " + diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
}
else {
console.log(" Error: " + diagnostic.messageText);
diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types
index 16df3df10c6..3af8537fdb7 100644
--- a/tests/baselines/reference/APISample_watcher.types
+++ b/tests/baselines/reference/APISample_watcher.types
@@ -233,16 +233,11 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
>getEmitOutput : (fileName: string) => ts.EmitOutput
>fileName : string
- if (output.emitOutputStatus === ts.EmitReturnStatus.Succeeded) {
->output.emitOutputStatus === ts.EmitReturnStatus.Succeeded : boolean
->output.emitOutputStatus : ts.EmitReturnStatus
+ if (!output.emitSkipped) {
+>!output.emitSkipped : boolean
+>output.emitSkipped : boolean
>output : ts.EmitOutput
->emitOutputStatus : ts.EmitReturnStatus
->ts.EmitReturnStatus.Succeeded : ts.EmitReturnStatus
->ts.EmitReturnStatus : typeof ts.EmitReturnStatus
->ts : typeof ts
->EmitReturnStatus : typeof ts.EmitReturnStatus
->Succeeded : ts.EmitReturnStatus
+>emitSkipped : boolean
console.log(`Emitting ${fileName}`);
>console.log(`Emitting ${fileName}`) : any
@@ -322,11 +317,11 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
>fileName : string
allDiagnostics.forEach(diagnostic => {
->allDiagnostics.forEach(diagnostic => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); } else { console.log(` Error: ${diagnostic.messageText}`); } }) : void
+>allDiagnostics.forEach(diagnostic => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`); } else { console.log(` Error: ${diagnostic.messageText}`); } }) : 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 => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); } else { console.log(` Error: ${diagnostic.messageText}`); } } : (diagnostic: ts.Diagnostic) => void
+>diagnostic => { if (diagnostic.file) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`); } else { console.log(` Error: ${diagnostic.messageText}`); } } : (diagnostic: ts.Diagnostic) => void
>diagnostic : ts.Diagnostic
if (diagnostic.file) {
@@ -346,8 +341,8 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
>diagnostic : ts.Diagnostic
>start : number
- console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
->console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`) : any
+ console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
+>console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`) : any
>console.log : any
>console : any
>log : any
@@ -362,9 +357,13 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
>lineChar.character : number
>lineChar : ts.LineAndCharacter
>character : number
->diagnostic.messageText : string
+>ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n") : 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
+>messageText : string | ts.DiagnosticMessageChain
}
else {
console.log(` Error: ${diagnostic.messageText}`);
@@ -372,9 +371,9 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
>console.log : any
>console : any
>log : any
->diagnostic.messageText : string
+>diagnostic.messageText : string | ts.DiagnosticMessageChain
>diagnostic : ts.Diagnostic
->messageText : string
+>messageText : string | ts.DiagnosticMessageChain
}
});
}
@@ -2504,6 +2503,16 @@ declare module "typescript" {
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
+ }
+ interface WriteFileCallback {
+>WriteFileCallback : WriteFileCallback
+
+ (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
+>fileName : string
+>data : string
+>writeByteOrderMark : boolean
+>onError : (message: string) => void
+>message : string
}
interface Program extends ScriptReferenceHost {
>Program : Program
@@ -2513,12 +2522,26 @@ declare module "typescript" {
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
+ /**
+ * Emits the javascript and declaration files. If targetSourceFile is not specified, then
+ * the javascript and declaration files will be produced for all the files in this program.
+ * If targetSourceFile is specified, then only the javascript and declaration for that
+ * specific file will be generated.
+ *
+ * If writeFile is not specified then the writeFile callback from the compiler host will be
+ * used for writing the javascript and declaration files. Otherwise, the writeFile parameter
+ * will be invoked when writing the javascript and declaration files.
+ */
+ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
+>emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult
+>targetSourceFile : SourceFile
+>SourceFile : SourceFile
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
+>EmitResult : EmitResult
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+ getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
>sourceFile : SourceFile
>SourceFile : SourceFile
>Diagnostic : Diagnostic
@@ -2527,30 +2550,24 @@ 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
- getTypeChecker(produceDiagnostics: boolean): TypeChecker;
->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker
->produceDiagnostics : boolean
+ getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
+>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
+>sourceFile : SourceFile
+>SourceFile : SourceFile
+>Diagnostic : Diagnostic
+
+ getTypeChecker(): TypeChecker;
+>getTypeChecker : () => TypeChecker
>TypeChecker : TypeChecker
getCommonSourceDirectory(): string;
>getCommonSourceDirectory : () => string
-
- emitFiles(targetSourceFile?: SourceFile): EmitResult;
->emitFiles : (targetSourceFile?: SourceFile) => EmitResult
->targetSourceFile : SourceFile
->SourceFile : SourceFile
->EmitResult : EmitResult
-
- isEmitBlocked(sourceFile?: SourceFile): boolean;
->isEmitBlocked : (sourceFile?: SourceFile) => boolean
->sourceFile : SourceFile
->SourceFile : SourceFile
}
interface SourceMapSpan {
>SourceMapSpan : SourceMapSpan
@@ -2604,33 +2621,23 @@ declare module "typescript" {
>sourceMapDecodedMappings : SourceMapSpan[]
>SourceMapSpan : SourceMapSpan
}
- enum EmitReturnStatus {
->EmitReturnStatus : EmitReturnStatus
+ enum ExitStatus {
+>ExitStatus : ExitStatus
- Succeeded = 0,
->Succeeded : EmitReturnStatus
+ Success = 0,
+>Success : ExitStatus
- AllOutputGenerationSkipped = 1,
->AllOutputGenerationSkipped : EmitReturnStatus
+ DiagnosticsPresent_OutputsSkipped = 1,
+>DiagnosticsPresent_OutputsSkipped : ExitStatus
- JSGeneratedWithSemanticErrors = 2,
->JSGeneratedWithSemanticErrors : EmitReturnStatus
-
- DeclarationGenerationSkipped = 3,
->DeclarationGenerationSkipped : EmitReturnStatus
-
- EmitErrorsEncountered = 4,
->EmitErrorsEncountered : EmitReturnStatus
-
- CompilerOptionsErrors = 5,
->CompilerOptionsErrors : EmitReturnStatus
+ DiagnosticsPresent_OutputsGenerated = 2,
+>DiagnosticsPresent_OutputsGenerated : ExitStatus
}
interface EmitResult {
>EmitResult : EmitResult
- emitResultStatus: EmitReturnStatus;
->emitResultStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
diagnostics: Diagnostic[];
>diagnostics : Diagnostic[]
@@ -2647,10 +2654,6 @@ declare module "typescript" {
>getCompilerOptions : () => CompilerOptions
>CompilerOptions : CompilerOptions
- getCompilerHost(): CompilerHost;
->getCompilerHost : () => CompilerHost
->CompilerHost : CompilerHost
-
getSourceFiles(): SourceFile[];
>getSourceFiles : () => SourceFile[]
>SourceFile : SourceFile
@@ -2663,32 +2666,6 @@ declare module "typescript" {
interface TypeChecker {
>TypeChecker : TypeChecker
- getEmitResolver(): EmitResolver;
->getEmitResolver : () => EmitResolver
->EmitResolver : EmitResolver
-
- getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
- getGlobalDiagnostics(): Diagnostic[];
->getGlobalDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
- getNodeCount(): number;
->getNodeCount : () => number
-
- getIdentifierCount(): number;
->getIdentifierCount : () => number
-
- getSymbolCount(): number;
->getSymbolCount : () => number
-
- getTypeCount(): number;
->getTypeCount : () => number
-
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
>getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type
>symbol : Symbol
@@ -2838,10 +2815,12 @@ declare module "typescript" {
>symbol : Symbol
>Symbol : Symbol
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->node : EnumMember
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
>EnumMember : EnumMember
+>PropertyAccessExpression : PropertyAccessExpression
+>ElementAccessExpression : ElementAccessExpression
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
>isValidPropertyAccess : (node: QualifiedName | PropertyAccessExpression, propertyName: string) => boolean
@@ -3128,16 +3107,6 @@ declare module "typescript" {
>Node : Node
>NodeCheckFlags : NodeCheckFlags
- getEnumMemberValue(node: EnumMember): number;
->getEnumMemberValue : (node: EnumMember) => number
->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
@@ -3189,9 +3158,10 @@ declare module "typescript" {
>Node : Node
>SymbolVisibilityResult : SymbolVisibilityResult
- getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
->getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression) => number
->node : PropertyAccessExpression | ElementAccessExpression
+ getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
+>getConstantValue : (node: PropertyAccessExpression | ElementAccessExpression | EnumMember) => number
+>node : PropertyAccessExpression | ElementAccessExpression | EnumMember
+>EnumMember : EnumMember
>PropertyAccessExpression : PropertyAccessExpression
>ElementAccessExpression : ElementAccessExpression
@@ -3932,8 +3902,9 @@ declare module "typescript" {
length: number;
>length : number
- messageText: string;
->messageText : string
+ messageText: string | DiagnosticMessageChain;
+>messageText : string | DiagnosticMessageChain
+>DiagnosticMessageChain : DiagnosticMessageChain
category: DiagnosticCategory;
>category : DiagnosticCategory
@@ -4532,13 +4503,9 @@ declare module "typescript" {
>getCancellationToken : () => CancellationToken
>CancellationToken : CancellationToken
- writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
->writeFile : (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) => void
->fileName : string
->data : string
->writeByteOrderMark : boolean
->onError : (message: string) => void
->message : string
+ writeFile: WriteFileCallback;
+>writeFile : WriteFileCallback
+>WriteFileCallback : WriteFileCallback
getCurrentDirectory(): string;
>getCurrentDirectory : () => string
@@ -4786,12 +4753,6 @@ declare module "typescript" {
>SyntaxKind : SyntaxKind
>NodeFlags : NodeFlags
- function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[];
->getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[]
->sourceFile : SourceFile
->SourceFile : SourceFile
->Diagnostic : Diagnostic
-
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile;
>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile
>sourceFile : SourceFile
@@ -4840,8 +4801,20 @@ declare module "typescript" {
>CompilerOptions : CompilerOptions
>CompilerHost : CompilerHost
- function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program;
->createProgram : (rootNames: string[], options: CompilerOptions, host: CompilerHost) => Program
+ 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[]
>options : CompilerOptions
>CompilerOptions : CompilerOptions
@@ -5036,10 +5009,6 @@ declare module "typescript" {
>line : number
>character : number
- getSyntacticDiagnostics(): Diagnostic[];
->getSyntacticDiagnostics : () => Diagnostic[]
->Diagnostic : Diagnostic
-
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile
>newText : string
@@ -5790,9 +5759,8 @@ declare module "typescript" {
>outputFiles : OutputFile[]
>OutputFile : OutputFile
- emitOutputStatus: EmitReturnStatus;
->emitOutputStatus : EmitReturnStatus
->EmitReturnStatus : EmitReturnStatus
+ emitSkipped: boolean;
+>emitSkipped : boolean
}
const enum OutputFileType {
>OutputFileType : OutputFileType
diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types.pull b/tests/baselines/reference/TypeGuardWithEnumUnion.types.pull
new file mode 100644
index 00000000000..33a40762445
--- /dev/null
+++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types.pull
@@ -0,0 +1,96 @@
+=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts ===
+enum Color { R, G, B }
+>Color : Color
+>R : Color
+>G : Color
+>B : Color
+
+function f1(x: Color | string) {
+>f1 : (x: string | Color) => void
+>x : string | Color
+>Color : Color
+
+ if (typeof x === "number") {
+>typeof x === "number" : boolean
+>typeof x : string
+>x : string | Color
+
+ var y = x;
+>y : Color
+>x : Color
+
+ var y: Color;
+>y : Color
+>Color : Color
+ }
+ else {
+ var z = x;
+>z : string
+>x : string
+
+ var z: string;
+>z : string
+ }
+}
+
+function f2(x: Color | string | string[]) {
+>f2 : (x: string | Color | string[]) => void
+>x : string | Color | string[]
+>Color : Color
+
+ if (typeof x === "object") {
+>typeof x === "object" : boolean
+>typeof x : string
+>x : string | Color | string[]
+
+ var y = x;
+>y : string[]
+>x : string[]
+
+ var y: string[];
+>y : string[]
+ }
+ if (typeof x === "number") {
+>typeof x === "number" : boolean
+>typeof x : string
+>x : string | Color | string[]
+
+ var z = x;
+>z : Color
+>x : Color
+
+ var z: Color;
+>z : Color
+>Color : Color
+ }
+ else {
+ var w = x;
+>w : string | string[]
+>x : string | string[]
+
+ var w: string | string[];
+>w : string | string[]
+ }
+ if (typeof x === "string") {
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | Color | string[]
+
+ var a = x;
+>a : string
+>x : string
+
+ var a: string;
+>a : string
+ }
+ else {
+ var b = x;
+>b : Color | string[]
+>x : Color | string[]
+
+ var b: Color | string[];
+>b : Color | string[]
+>Color : Color
+ }
+}
+
diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types.pull b/tests/baselines/reference/aliasUsageInOrExpression.types.pull
new file mode 100644
index 00000000000..cc45af29f86
--- /dev/null
+++ b/tests/baselines/reference/aliasUsageInOrExpression.types.pull
@@ -0,0 +1,83 @@
+=== tests/cases/compiler/aliasUsageInOrExpression_main.ts ===
+import Backbone = require("aliasUsageInOrExpression_backbone");
+>Backbone : typeof Backbone
+
+import moduleA = require("aliasUsageInOrExpression_moduleA");
+>moduleA : typeof moduleA
+
+interface IHasVisualizationModel {
+>IHasVisualizationModel : IHasVisualizationModel
+
+ VisualizationModel: typeof Backbone.Model;
+>VisualizationModel : typeof Backbone.Model
+>Backbone : typeof Backbone
+>Model : typeof Backbone.Model
+}
+var i: IHasVisualizationModel;
+>i : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+
+var d1 = i || moduleA;
+>d1 : typeof moduleA
+>i || moduleA : typeof moduleA
+>i : IHasVisualizationModel
+>moduleA : typeof moduleA
+
+var d2: IHasVisualizationModel = i || moduleA;
+>d2 : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+>i || moduleA : typeof moduleA
+>i : IHasVisualizationModel
+>moduleA : typeof moduleA
+
+var d2: IHasVisualizationModel = moduleA || i;
+>d2 : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+>moduleA || i : typeof moduleA
+>moduleA : typeof moduleA
+>i : IHasVisualizationModel
+
+var e: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null || { x: moduleA };
+>e : { x: IHasVisualizationModel; }
+>x : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+><{ x: IHasVisualizationModel }>null || { x: moduleA } : { x: IHasVisualizationModel; }
+><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
+>x : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+>{ x: moduleA } : { x: typeof moduleA; }
+>x : typeof moduleA
+>moduleA : typeof moduleA
+
+var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x: moduleA } : null;
+>f : { x: IHasVisualizationModel; }
+>x : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; }
+><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
+>x : IHasVisualizationModel
+>IHasVisualizationModel : IHasVisualizationModel
+>{ x: moduleA } : { x: typeof moduleA; }
+>x : typeof moduleA
+>moduleA : typeof moduleA
+
+=== tests/cases/compiler/aliasUsageInOrExpression_backbone.ts ===
+export class Model {
+>Model : Model
+
+ public someData: string;
+>someData : string
+}
+
+=== tests/cases/compiler/aliasUsageInOrExpression_moduleA.ts ===
+import Backbone = require("aliasUsageInOrExpression_backbone");
+>Backbone : typeof Backbone
+
+export class VisualizationModel extends Backbone.Model {
+>VisualizationModel : VisualizationModel
+>Backbone : unknown
+>Model : Backbone.Model
+
+ // interesting stuff here
+}
+
diff --git a/tests/baselines/reference/arrayLiterals.types.pull b/tests/baselines/reference/arrayLiterals.types.pull
new file mode 100644
index 00000000000..bd06540aca3
--- /dev/null
+++ b/tests/baselines/reference/arrayLiterals.types.pull
@@ -0,0 +1,124 @@
+=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts ===
+// Empty array literal with no contextual type has type Undefined[]
+
+var arr1= [[], [1], ['']];
+>arr1 : (number[] | string[])[]
+>[[], [1], ['']] : (number[] | string[])[]
+>[] : undefined[]
+>[1] : number[]
+>[''] : string[]
+
+var arr2 = [[null], [1], ['']];
+>arr2 : (number[] | string[])[]
+>[[null], [1], ['']] : (number[] | string[])[]
+>[null] : null[]
+>[1] : number[]
+>[''] : string[]
+
+
+// Array literal with elements of only EveryType E has type E[]
+var stringArrArr = [[''], [""]];
+>stringArrArr : string[][]
+>[[''], [""]] : string[][]
+>[''] : string[]
+>[""] : string[]
+
+var stringArr = ['', ""];
+>stringArr : string[]
+>['', ""] : string[]
+
+var numberArr = [0, 0.0, 0x00, 1e1];
+>numberArr : number[]
+>[0, 0.0, 0x00, 1e1] : number[]
+
+var boolArr = [false, true, false, true];
+>boolArr : boolean[]
+>[false, true, false, true] : boolean[]
+
+class C { private p; }
+>C : C
+>p : any
+
+var classArr = [new C(), new C()];
+>classArr : C[]
+>[new C(), new C()] : C[]
+>new C() : C
+>C : typeof C
+>new C() : C
+>C : typeof C
+
+var classTypeArray = [C, C, C];
+>classTypeArray : typeof C[]
+>[C, C, C] : typeof C[]
+>C : typeof C
+>C : typeof C
+>C : typeof C
+
+var classTypeArray: Array; // Should OK, not be a parse error
+>classTypeArray : typeof C[]
+>Array : T[]
+>C : typeof C
+
+// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
+var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
+>context1 : { [n: number]: { a: string; b: number; }; }
+>n : number
+>a : string
+>b : number
+>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
+>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
+>a : string
+>b : number
+>c : string
+>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
+>a : string
+>b : number
+>c : number
+
+var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
+>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
+>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
+>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
+>a : string
+>b : number
+>c : string
+>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
+>a : string
+>b : number
+>c : number
+
+// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
+class Base { private p; }
+>Base : Base
+>p : any
+
+class Derived1 extends Base { private m };
+>Derived1 : Derived1
+>Base : Base
+>m : any
+
+class Derived2 extends Base { private n };
+>Derived2 : Derived2
+>Base : Base
+>n : any
+
+var context3: Base[] = [new Derived1(), new Derived2()];
+>context3 : Base[]
+>Base : Base
+>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[]
+>new Derived1() : Derived1
+>Derived1 : typeof Derived1
+>new Derived2() : Derived2
+>Derived2 : typeof Derived2
+
+// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
+var context4: Base[] = [new Derived1(), new Derived1()];
+>context4 : Base[]
+>Base : Base
+>[new Derived1(), new Derived1()] : Derived1[]
+>new Derived1() : Derived1
+>Derived1 : typeof Derived1
+>new Derived1() : Derived1
+>Derived1 : typeof Derived1
+
+
diff --git a/tests/baselines/reference/classdecl.js b/tests/baselines/reference/classdecl.js
index 6c6e542e032..859476c0dad 100644
--- a/tests/baselines/reference/classdecl.js
+++ b/tests/baselines/reference/classdecl.js
@@ -204,3 +204,65 @@ var e = (function () {
};
return e;
})();
+
+
+//// [classdecl.d.ts]
+declare class a {
+ constructor(n: number);
+ constructor(s: string);
+ pgF(): void;
+ pv: any;
+ d: number;
+ static p2: {
+ x: number;
+ y: number;
+ };
+ private static d2();
+ private static p3;
+ private pv3;
+ private foo(n);
+ private foo(s);
+}
+declare class b extends a {
+}
+declare module m1 {
+ class b {
+ }
+ interface ib {
+ }
+}
+declare module m2 {
+ module m3 {
+ class c extends b {
+ }
+ class ib2 implements m1.ib {
+ }
+ }
+}
+declare class c extends m1.b {
+}
+declare class ib2 implements m1.ib {
+}
+declare class aAmbient {
+ constructor(n: number);
+ constructor(s: string);
+ pgF(): void;
+ pv: any;
+ d: number;
+ static p2: {
+ x: number;
+ y: number;
+ };
+ static d2(): any;
+ static p3: any;
+ private pv3;
+ private foo(s);
+}
+declare class d {
+ private foo(n);
+ private foo(s);
+}
+declare class e {
+ private foo(s);
+ private foo(n);
+}
diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6.types.pull b/tests/baselines/reference/computedPropertyNamesContextualType6.types.pull
new file mode 100644
index 00000000000..a7a65d6618d
--- /dev/null
+++ b/tests/baselines/reference/computedPropertyNamesContextualType6.types.pull
@@ -0,0 +1,40 @@
+=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts ===
+interface I {
+>I : I
+>T : T
+
+ [s: string]: T;
+>s : string
+>T : T
+}
+
+declare function foo(obj: I): T
+>foo : (obj: I) => T
+>T : T
+>obj : I
+>I : I
+>T : T
+>T : T
+
+foo({
+>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[]
+>foo : (obj: I) => T
+>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; }
+
+ p: "",
+>p : string
+
+ 0: () => { },
+>() => { } : () => void
+
+ ["hi" + "bye"]: true,
+>"hi" + "bye" : string
+
+ [0 + 1]: 0,
+>0 + 1 : number
+
+ [+"hi"]: [0]
+>+"hi" : number
+>[0] : number[]
+
+});
diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7.types.pull b/tests/baselines/reference/computedPropertyNamesContextualType7.types.pull
new file mode 100644
index 00000000000..ff68ec8d0b0
--- /dev/null
+++ b/tests/baselines/reference/computedPropertyNamesContextualType7.types.pull
@@ -0,0 +1,40 @@
+=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts ===
+interface I {
+>I : I
+>T : T
+
+ [s: number]: T;
+>s : number
+>T : T
+}
+
+declare function foo(obj: I): T
+>foo : (obj: I) => T
+>T : T
+>obj : I
+>I : I
+>T : T
+>T : T
+
+foo({
+>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[]
+>foo : (obj: I) => T
+>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; }
+
+ p: "",
+>p : string
+
+ 0: () => { },
+>() => { } : () => void
+
+ ["hi" + "bye"]: true,
+>"hi" + "bye" : string
+
+ [0 + 1]: 0,
+>0 + 1 : number
+
+ [+"hi"]: [0]
+>+"hi" : number
+>[0] : number[]
+
+});
diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.js
index df351acf6e9..affe949797e 100644
--- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.js
+++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.js
@@ -4,3 +4,8 @@ interface I {
}
//// [computedPropertyNamesDeclarationEmit3.js]
+
+
+//// [computedPropertyNamesDeclarationEmit3.d.ts]
+interface I {
+}
diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.js
index 870f87bb613..f68c1633ef9 100644
--- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.js
+++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.js
@@ -5,3 +5,8 @@ var v: {
//// [computedPropertyNamesDeclarationEmit4.js]
var v;
+
+
+//// [computedPropertyNamesDeclarationEmit4.d.ts]
+declare var v: {
+};
diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types.pull b/tests/baselines/reference/contextualSignatureInstantiation.types.pull
new file mode 100644
index 00000000000..d7246ab79aa
--- /dev/null
+++ b/tests/baselines/reference/contextualSignatureInstantiation.types.pull
@@ -0,0 +1,142 @@
+=== tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts ===
+// TypeScript Spec, section 4.12.2:
+// If e is an expression of a function type that contains exactly one generic call signature and no other members,
+// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
+// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
+// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5).
+
+declare function foo(cb: (x: number, y: string) => T): T;
+>foo : (cb: (x: number, y: string) => T) => T
+>T : T
+>cb : (x: number, y: string) => T
+>x : number
+>y : string
+>T : T
+>T : T
+
+declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V;
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>T : T
+>U : U
+>V : V
+>x : T
+>T : T
+>y : U
+>U : U
+>cb : (x: T, y: U) => V
+>x : T
+>T : T
+>y : U
+>U : U
+>V : V
+>V : V
+
+declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U;
+>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U
+>T : T
+>U : U
+>x : T
+>T : T
+>y : T
+>T : T
+>cb : (x: T, y: T) => U
+>x : T
+>T : T
+>y : T
+>T : T
+>U : U
+>U : U
+
+declare function g(x: T, y: T): T;
+>g : (x: T, y: T) => T
+>T : T
+>x : T
+>T : T
+>y : T
+>T : T
+>T : T
+
+declare function h(x: T, y: U): T[] | U[];
+>h : (x: T, y: U) => T[] | U[]
+>T : T
+>U : U
+>x : T
+>T : T
+>y : U
+>U : U
+>T : T
+>U : U
+
+var a: number;
+>a : number
+
+var a = bar(1, 1, g); // Should be number
+>a : number
+>bar(1, 1, g) : number
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>g : (x: T, y: T) => T
+
+var a = baz(1, 1, g); // Should be number
+>a : number
+>baz(1, 1, g) : number
+>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U
+>g : (x: T, y: T) => T
+
+var b: number | string;
+>b : string | number
+
+var b = foo(g); // Should be number | string
+>b : string | number
+>foo(g) : string | number
+>foo : (cb: (x: number, y: string) => T) => T
+>g : (x: T, y: T) => T
+
+var b = bar(1, "one", g); // Should be number | string
+>b : string | number
+>bar(1, "one", g) : string | number
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>g : (x: T, y: T) => T
+
+var b = bar("one", 1, g); // Should be number | string
+>b : string | number
+>bar("one", 1, g) : string | number
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>g : (x: T, y: T) => T
+
+var b = baz(b, b, g); // Should be number | string
+>b : string | number
+>baz(b, b, g) : string | number
+>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U
+>b : string | number
+>b : string | number
+>g : (x: T, y: T) => T
+
+var d: number[] | string[];
+>d : number[] | string[]
+
+var d = foo(h); // Should be number[] | string[]
+>d : number[] | string[]
+>foo(h) : number[] | string[]
+>foo : (cb: (x: number, y: string) => T) => T
+>h : (x: T, y: U) => T[] | U[]
+
+var d = bar(1, "one", h); // Should be number[] | string[]
+>d : number[] | string[]
+>bar(1, "one", h) : number[] | string[]
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>h : (x: T, y: U) => T[] | U[]
+
+var d = bar("one", 1, h); // Should be number[] | string[]
+>d : number[] | string[]
+>bar("one", 1, h) : number[] | string[]
+>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V
+>h : (x: T, y: U) => T[] | U[]
+
+var d = baz(d, d, g); // Should be number[] | string[]
+>d : number[] | string[]
+>baz(d, d, g) : number[] | string[]
+>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U
+>d : number[] | string[]
+>d : number[] | string[]
+>g : (x: T, y: T) => T
+
diff --git a/tests/baselines/reference/declFileObjectLiteralWithAccessors.js b/tests/baselines/reference/declFileObjectLiteralWithAccessors.js
index 00598cfcf3e..7d7c6ee73d3 100644
--- a/tests/baselines/reference/declFileObjectLiteralWithAccessors.js
+++ b/tests/baselines/reference/declFileObjectLiteralWithAccessors.js
@@ -27,3 +27,15 @@ function makePoint(x) {
var point = makePoint(2);
var x = point.x;
point.x = 30;
+
+
+//// [declFileObjectLiteralWithAccessors.d.ts]
+declare function makePoint(x: number): {
+ b: number;
+ x: number;
+};
+declare var point: {
+ b: number;
+ x: number;
+};
+declare var x: number;
diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js
index ed457931a69..b3d41829637 100644
--- a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js
+++ b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js
@@ -20,3 +20,13 @@ function makePoint(x) {
;
var point = makePoint(2);
var x = point.x;
+
+
+//// [declFileObjectLiteralWithOnlyGetter.d.ts]
+declare function makePoint(x: number): {
+ x: number;
+};
+declare var point: {
+ x: number;
+};
+declare var x: number;
diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.js b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.js
index f5716bb06e0..dae362caf36 100644
--- a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.js
+++ b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.js
@@ -21,3 +21,14 @@ function makePoint(x) {
;
var point = makePoint(2);
point.x = 30;
+
+
+//// [declFileObjectLiteralWithOnlySetter.d.ts]
+declare function makePoint(x: number): {
+ b: number;
+ x: number;
+};
+declare var point: {
+ b: number;
+ x: number;
+};
diff --git a/tests/baselines/reference/declFilePrivateStatic.js b/tests/baselines/reference/declFilePrivateStatic.js
index 38dbdb126af..5bec38e4dee 100644
--- a/tests/baselines/reference/declFilePrivateStatic.js
+++ b/tests/baselines/reference/declFilePrivateStatic.js
@@ -52,3 +52,16 @@ var C = (function () {
C.y = 1;
return C;
})();
+
+
+//// [declFilePrivateStatic.d.ts]
+declare class C {
+ private static x;
+ static y: number;
+ private static a();
+ static b(): void;
+ private static c;
+ static d: number;
+ private static e;
+ static f: any;
+}
diff --git a/tests/baselines/reference/declInput.js b/tests/baselines/reference/declInput.js
index 94c825d87f0..39d466498fa 100644
--- a/tests/baselines/reference/declInput.js
+++ b/tests/baselines/reference/declInput.js
@@ -28,3 +28,17 @@ var bar = (function () {
};
return bar;
})();
+
+
+//// [declInput.d.ts]
+interface bar {
+}
+declare class bar {
+ f(): string;
+ g(): {
+ a: bar;
+ b: any;
+ c: any;
+ };
+ h(x?: number, y?: any, z?: string): void;
+}
diff --git a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline
index 111448faa61..5552851dec4 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
+EmitSkipped: false
+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
+
+EmitSkipped: false
+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..4abc99b05c2 100644
--- a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline
+++ b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : Succeeded
-FileName : declSingleFile.js
+EmitSkipped: false
+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..ac2f7cb3dac 100644
--- a/tests/baselines/reference/getEmitOutputExternalModule.baseline
+++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline
@@ -1,9 +1,9 @@
-EmitOutputStatus : Succeeded
-FileName : declSingleFile.js
+EmitSkipped: false
+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..c32472d318f 100644
--- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline
+++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : JSGeneratedWithSemanticErrors
-FileName : declSingleFile.js
+EmitSkipped: false
+FileName : declSingleFile.js
var x = 5;
var Bar = (function () {
function Bar() {
@@ -12,4 +12,4 @@ var Bar2 = (function () {
}
return Bar2;
})();
-
+
diff --git a/tests/baselines/reference/getEmitOutputMapRoots.baseline b/tests/baselines/reference/getEmitOutputMapRoots.baseline
index 733897879df..16f39169e23 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
+EmitSkipped: false
+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..a1efeecd321 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
+EmitSkipped: false
+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..981b4710e41 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
+EmitSkipped: false
+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..4a71299dcc0 100644
--- a/tests/baselines/reference/getEmitOutputSingleFile.baseline
+++ b/tests/baselines/reference/getEmitOutputSingleFile.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : Succeeded
-FileName : outputDir/singleFile.js
+EmitSkipped: false
+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..c9409c5ca8c 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
+EmitSkipped: false
+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..39cff967d89 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
+EmitSkipped: false
+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..713aa4f3c08 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
+EmitSkipped: false
+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
+EmitSkipped: false
+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..5424def98ee 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
+EmitSkipped: false
+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..7948ad99673 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
+EmitSkipped: false
+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
+EmitSkipped: false
+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..4fda32ad7c4 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
+EmitSkipped: false
+
+EmitSkipped: false
+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..4582af47f5a 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
+EmitSkipped: false
+
+EmitSkipped: false
+FileName : tests/cases/fourslash/inputFile2.js
var Foo = (function () {
function Foo() {
}
return Foo;
})();
exports.Foo = Foo;
-
-EmitOutputStatus : Succeeded
-FileName : tests/cases/fourslash/inputFile3.js
+
+EmitSkipped: false
+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..1ce3d9f33c3 100644
--- a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline
+++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : Succeeded
-FileName : declSingle.js
+EmitSkipped: false
+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..8dc9355bca2 100644
--- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline
+++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : JSGeneratedWithSemanticErrors
-FileName : tests/cases/fourslash/inputFile1.js
+EmitSkipped: false
+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..f854a619a47 100644
--- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline
+++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : EmitErrorsEncountered
-FileName : tests/cases/fourslash/inputFile.js
+EmitSkipped: false
+FileName : tests/cases/fourslash/inputFile.js
var M;
(function (M) {
var C = (function () {
@@ -9,4 +9,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..463dfe6899a 100644
--- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline
+++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline
@@ -1,5 +1,5 @@
-EmitOutputStatus : EmitErrorsEncountered
-FileName : tests/cases/fourslash/inputFile.js
+EmitSkipped: false
+FileName : tests/cases/fourslash/inputFile.js
define(["require", "exports"], function (require, exports) {
var C = (function () {
function C() {
@@ -11,4 +11,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..b6249822131 100644
--- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline
+++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline
@@ -1,4 +1,4 @@
-EmitOutputStatus : JSGeneratedWithSemanticErrors
-FileName : tests/cases/fourslash/inputFile.js
+EmitSkipped: false
+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..396e220bdb6 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
+EmitSkipped: false
+FileName : tests/cases/fourslash/inputFile.js
var x = "hello world";
-
+FileName : tests/cases/fourslash/inputFile.d.ts
+declare var x: number;
+
diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline
index 91865045420..7f012b6a546 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
+EmitSkipped: false
+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..6a58015c1b3 100644
--- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline
+++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline
@@ -1,8 +1,11 @@
-EmitOutputStatus : DeclarationGenerationSkipped
-FileName : out.js
+EmitSkipped: false
+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";
-
+FileName : out.d.ts
+declare var noErrors: boolean;
+declare var semanticError: boolean;
+
diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline
index 0edb4e3bb61..701b275eb31 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
+EmitSkipped: false
+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..b66f83dc6b6 100644
--- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline
+++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline
@@ -1,8 +1,8 @@
-EmitOutputStatus : Succeeded
-FileName : out.js
+EmitSkipped: false
+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..2c341821fb0 100644
--- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline
+++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline
@@ -1,4 +1,4 @@
-EmitOutputStatus : Succeeded
-FileName : tests/cases/fourslash/inputFile.js
+EmitSkipped: false
+FileName : tests/cases/fourslash/inputFile.js
var x;
-
+
diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js
index d5f17c9728f..b16d0f5231c 100644
--- a/tests/baselines/reference/giant.js
+++ b/tests/baselines/reference/giant.js
@@ -1218,3 +1218,307 @@ define(["require", "exports"], function (require, exports) {
})(eM = exports.eM || (exports.eM = {}));
;
});
+
+
+//// [giant.d.ts]
+export declare var eV: any;
+export declare function eF(): void;
+export declare class eC {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ private rF();
+ pgF(): void;
+ pgF: any;
+ psF(param: any): void;
+ psF: any;
+ private rgF();
+ private rgF;
+ private rsF(param);
+ private rsF;
+ static tV: any;
+ static tF(): void;
+ static tsF(param: any): void;
+ static tsF: any;
+ static tgF(): void;
+ static tgF: any;
+}
+export interface eI {
+ (): any;
+ (): number;
+ (p: any): any;
+ (p1: string): any;
+ (p2?: string): any;
+ (...p3: any[]): any;
+ (p4: string, p5?: string): any;
+ (p6: string, ...p7: any[]): any;
+ new (): any;
+ new (): number;
+ new (p: string): any;
+ new (p2?: string): any;
+ new (...p3: any[]): any;
+ new (p4: string, p5?: string): any;
+ new (p6: string, ...p7: any[]): any;
+ [p1: string]: any;
+ [p2: string, p3: number]: any;
+ p: any;
+ p1?: any;
+ p2?: string;
+ p3(): any;
+ p4?(): any;
+ p5?(): void;
+ p6(pa1: any): void;
+ p7(pa1: any, pa2: any): void;
+ p7?(pa1: any, pa2: any): void;
+}
+export declare module eM {
+ var eV: any;
+ function eF(): void;
+ class eC {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ private rF();
+ pgF(): void;
+ pgF: any;
+ psF(param: any): void;
+ psF: any;
+ private rgF();
+ private rgF;
+ private rsF(param);
+ private rsF;
+ static tV: any;
+ static tF(): void;
+ static tsF(param: any): void;
+ static tsF: any;
+ static tgF(): void;
+ static tgF: any;
+ }
+ interface eI {
+ (): any;
+ (): number;
+ (p: any): any;
+ (p1: string): any;
+ (p2?: string): any;
+ (...p3: any[]): any;
+ (p4: string, p5?: string): any;
+ (p6: string, ...p7: any[]): any;
+ new (): any;
+ new (): number;
+ new (p: string): any;
+ new (p2?: string): any;
+ new (...p3: any[]): any;
+ new (p4: string, p5?: string): any;
+ new (p6: string, ...p7: any[]): any;
+ [p1: string]: any;
+ [p2: string, p3: number]: any;
+ p: any;
+ p1?: any;
+ p2?: string;
+ p3(): any;
+ p4?(): any;
+ p5?(): void;
+ p6(pa1: any): void;
+ p7(pa1: any, pa2: any): void;
+ p7?(pa1: any, pa2: any): void;
+ }
+ module eM {
+ var eV: any;
+ function eF(): void;
+ class eC {
+ }
+ interface eI {
+ }
+ module eM {
+ }
+ var eaV: any;
+ function eaF(): void;
+ class eaC {
+ }
+ module eaM {
+ }
+ }
+ var eaV: any;
+ function eaF(): void;
+ class eaC {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ private rF();
+ pgF(): void;
+ pgF: any;
+ psF(param: any): void;
+ psF: any;
+ private rgF();
+ private rgF;
+ private rsF(param);
+ private rsF;
+ static tV: any;
+ static tF(): void;
+ static tsF(param: any): void;
+ static tsF: any;
+ static tgF(): void;
+ static tgF: any;
+ }
+ module eaM {
+ var V: any;
+ function F(): void;
+ class C {
+ }
+ interface I {
+ }
+ module M {
+ }
+ var eV: any;
+ function eF(): void;
+ class eC {
+ }
+ interface eI {
+ }
+ module eM {
+ }
+ }
+}
+export declare var eaV: any;
+export declare function eaF(): void;
+export declare class eaC {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ private rF();
+ pgF(): void;
+ pgF: any;
+ psF(param: any): void;
+ psF: any;
+ private rgF();
+ private rgF;
+ private rsF(param);
+ private rsF;
+ static tV: any;
+ static tF(): void;
+ static tsF(param: any): void;
+ static tsF: any;
+ static tgF(): void;
+ static tgF: any;
+}
+export declare module eaM {
+ var V: any;
+ function F(): void;
+ class C {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ static tV: any;
+ static tF(): void;
+ }
+ interface I {
+ (): any;
+ (): number;
+ (p: string): any;
+ (p2?: string): any;
+ (...p3: any[]): any;
+ (p4: string, p5?: string): any;
+ (p6: string, ...p7: any[]): any;
+ new (): any;
+ new (): number;
+ new (p: string): any;
+ new (p2?: string): any;
+ new (...p3: any[]): any;
+ new (p4: string, p5?: string): any;
+ new (p6: string, ...p7: any[]): any;
+ [p1: string]: any;
+ [p2: string, p3: number]: any;
+ p: any;
+ p1?: any;
+ p2?: string;
+ p3(): any;
+ p4?(): any;
+ p5?(): void;
+ p6(pa1: any): void;
+ p7(pa1: any, pa2: any): void;
+ p7?(pa1: any, pa2: any): void;
+ }
+ module M {
+ var V: any;
+ function F(): void;
+ class C {
+ }
+ interface I {
+ }
+ module M {
+ }
+ var eV: any;
+ function eF(): void;
+ class eC {
+ }
+ interface eI {
+ }
+ module eM {
+ }
+ var eaV: any;
+ function eaF(): void;
+ class eaC {
+ }
+ module eaM {
+ }
+ }
+ var eV: any;
+ function eF(): void;
+ class eC {
+ constructor();
+ pV: any;
+ private rV;
+ pF(): void;
+ static tV: any;
+ static tF(): void;
+ }
+ interface eI {
+ (): any;
+ (): number;
+ (p: any): any;
+ (p1: string): any;
+ (p2?: string): any;
+ (...p3: any[]): any;
+ (p4: string, p5?: string): any;
+ (p6: string, ...p7: any[]): any;
+ new (): any;
+ new (): number;
+ new (p: string): any;
+ new (p2?: string): any;
+ new (...p3: any[]): any;
+ new (p4: string, p5?: string): any;
+ new (p6: string, ...p7: any[]): any;
+ [p1: string]: any;
+ [p2: string, p3: number]: any;
+ p: any;
+ p1?: any;
+ p2?: string;
+ p3(): any;
+ p4?(): any;
+ p5?(): void;
+ p6(pa1: any): void;
+ p7(pa1: any, pa2: any): void;
+ p7?(pa1: any, pa2: any): void;
+ }
+ module eM {
+ var V: any;
+ function F(): void;
+ class C {
+ }
+ module M {
+ }
+ var eV: any;
+ function eF(): void;
+ class eC {
+ }
+ interface eI {
+ }
+ module eM {
+ }
+ }
+}
diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types.pull b/tests/baselines/reference/heterogeneousArrayLiterals.types.pull
new file mode 100644
index 00000000000..e35caeed74a
--- /dev/null
+++ b/tests/baselines/reference/heterogeneousArrayLiterals.types.pull
@@ -0,0 +1,548 @@
+=== tests/cases/conformance/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals.ts ===
+// type of an array is the best common type of its elements (plus its contextual type if it exists)
+
+var a = [1, '']; // {}[]
+>a : (string | number)[]
+>[1, ''] : (string | number)[]
+
+var b = [1, null]; // number[]
+>b : number[]
+>[1, null] : number[]
+
+var c = [1, '', null]; // {}[]
+>c : (string | number)[]
+>[1, '', null] : (string | number)[]
+
+var d = [{}, 1]; // {}[]
+>d : {}[]
+>[{}, 1] : {}[]
+>{} : {}
+
+var e = [{}, Object]; // {}[]
+>e : {}[]
+>[{}, Object] : {}[]
+>{} : {}
+>Object : ObjectConstructor
+
+var f = [[], [1]]; // number[][]
+>f : number[][]
+>[[], [1]] : number[][]
+>[] : undefined[]
+>[1] : number[]
+
+var g = [[1], ['']]; // {}[]
+>g : (number[] | string[])[]
+>[[1], ['']] : (number[] | string[])[]
+>[1] : number[]
+>[''] : string[]
+
+var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[]
+>h : { foo: number; }[]
+>[{ foo: 1, bar: '' }, { foo: 2 }] : { foo: number; }[]
+>{ foo: 1, bar: '' } : { foo: number; bar: string; }
+>foo : number
+>bar : string
+>{ foo: 2 } : { foo: number; }
+>foo : number
+
+var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[]
+>i : ({ foo: number; bar: string; } | { foo: string; })[]
+>[{ foo: 1, bar: '' }, { foo: '' }] : ({ foo: number; bar: string; } | { foo: string; })[]
+>{ foo: 1, bar: '' } : { foo: number; bar: string; }
+>foo : number
+>bar : string
+>{ foo: '' } : { foo: string; }
+>foo : string
+
+var j = [() => 1, () => '']; // {}[]
+>j : ((() => number) | (() => string))[]
+>[() => 1, () => ''] : ((() => number) | (() => string))[]
+>() => 1 : () => number
+>() => '' : () => string
+
+var k = [() => 1, () => 1]; // { (): number }[]
+>k : (() => number)[]
+>[() => 1, () => 1] : (() => number)[]
+>() => 1 : () => number
+>() => 1 : () => number
+
+var l = [() => 1, () => null]; // { (): any }[]
+>l : (() => any)[]
+>[() => 1, () => null] : (() => any)[]
+>() => 1 : () => number
+>() => null : () => any
+
+var m = [() => 1, () => '', () => null]; // { (): any }[]
+>m : (() => any)[]
+>[() => 1, () => '', () => null] : (() => any)[]
+>() => 1 : () => number
+>() => '' : () => string
+>() => null : () => any
+
+var n = [[() => 1], [() => '']]; // {}[]
+>n : ((() => number)[] | (() => string)[])[]
+>[[() => 1], [() => '']] : ((() => number)[] | (() => string)[])[]
+>[() => 1] : (() => number)[]
+>() => 1 : () => number
+>[() => ''] : (() => string)[]
+>() => '' : () => string
+
+class Base { foo: string; }
+>Base : Base
+>foo : string
+
+class Derived extends Base { bar: string; }
+>Derived : Derived
+>Base : Base
+>bar : string
+
+class Derived2 extends Base { baz: string; }
+>Derived2 : Derived2
+>Base : Base
+>baz : string
+
+var base: Base;
+>base : Base
+>Base : Base
+
+var derived: Derived;
+>derived : Derived
+>Derived : Derived
+
+var derived2: Derived2;
+>derived2 : Derived2
+>Derived2 : Derived2
+
+module Derived {
+>Derived : typeof Derived
+
+ var h = [{ foo: base, basear: derived }, { foo: base }]; // {foo: Base}[]
+>h : { foo: Base; }[]
+>[{ foo: base, basear: derived }, { foo: base }] : { foo: Base; }[]
+>{ foo: base, basear: derived } : { foo: Base; basear: Derived; }
+>foo : Base
+>base : Base
+>basear : Derived
+>derived : Derived
+>{ foo: base } : { foo: Base; }
+>foo : Base
+>base : Base
+
+ var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[]
+>i : ({ foo: Base; basear: Derived; } | { foo: Derived; })[]
+>[{ foo: base, basear: derived }, { foo: derived }] : ({ foo: Base; basear: Derived; } | { foo: Derived; })[]
+>{ foo: base, basear: derived } : { foo: Base; basear: Derived; }
+>foo : Base
+>base : Base
+>basear : Derived
+>derived : Derived
+>{ foo: derived } : { foo: Derived; }
+>foo : Derived
+>derived : Derived
+
+ var j = [() => base, () => derived]; // { {}: Base }
+>j : (() => Base)[]
+>[() => base, () => derived] : (() => Base)[]
+>() => base : () => Base
+>base : Base
+>() => derived : () => Derived
+>derived : Derived
+
+ var k = [() => base, () => 1]; // {}[]~
+>k : ((() => Base) | (() => number))[]
+>[() => base, () => 1] : ((() => Base) | (() => number))[]
+>() => base : () => Base
+>base : Base
+>() => 1 : () => number
+
+ var l = [() => base, () => null]; // { (): any }[]
+>l : (() => any)[]
+>[() => base, () => null] : (() => any)[]
+>() => base : () => Base
+>base : Base
+>() => null : () => any
+
+ var m = [() => base, () => derived, () => null]; // { (): any }[]
+>m : (() => any)[]
+>[() => base, () => derived, () => null] : (() => any)[]
+>() => base : () => Base
+>base : Base
+>() => derived : () => Derived
+>derived : Derived
+>() => null : () => any
+
+ var n = [[() => base], [() => derived]]; // { (): Base }[]
+>n : (() => Base)[][]
+>[[() => base], [() => derived]] : (() => Base)[][]
+>[() => base] : (() => Base)[]
+>() => base : () => Base
+>base : Base
+>[() => derived] : (() => Derived)[]
+>() => derived : () => Derived
+>derived : Derived
+
+ var o = [derived, derived2]; // {}[]
+>o : (Derived | Derived2)[]
+>[derived, derived2] : (Derived | Derived2)[]
+>derived : Derived
+>derived2 : Derived2
+
+ var p = [derived, derived2, base]; // Base[]
+>p : Base[]
+>[derived, derived2, base] : Base[]
+>derived : Derived
+>derived2 : Derived2
+>base : Base
+
+ var q = [[() => derived2], [() => derived]]; // {}[]
+>q : ((() => Derived2)[] | (() => Derived)[])[]
+>[[() => derived2], [() => derived]] : ((() => Derived2)[] | (() => Derived)[])[]
+>[() => derived2] : (() => Derived2)[]
+>() => derived2 : () => Derived2
+>derived2 : Derived2
+>[() => derived] : (() => Derived)[]
+>() => derived : () => Derived
+>derived : Derived
+}
+
+module WithContextualType {
+>WithContextualType : typeof WithContextualType
+
+ // no errors
+ var a: Base[] = [derived, derived2];
+>a : Base[]
+>Base : Base
+>[derived, derived2] : (Derived | Derived2)[]
+>derived : Derived
+>derived2 : Derived2
+
+ var b: Derived[] = [null];
+>b : Derived[]
+>Derived : Derived
+>[null] : null[]
+
+ var c: Derived[] = [];
+>c : Derived[]
+>Derived : Derived
+>[] : undefined[]
+
+ var d: { (): Base }[] = [() => derived, () => derived2];
+>d : (() => Base)[]
+>Base : Base
+>[() => derived, () => derived2] : ((() => Derived) | (() => Derived2))[]
+>() => derived : () => Derived
+>derived : Derived
+>() => derived2 : () => Derived2
+>derived2 : Derived2
+}
+
+function foo(t: T, u: U) {
+>foo : (t: T, u: U) => void
+>T : T
+>U : U
+>t : T
+>T : T
+>u : U
+>U : U
+
+ var a = [t, t]; // T[]
+>a : T[]
+>[t, t] : T[]
+>t : T
+>t : T
+
+ var b = [t, null]; // T[]
+>b : T[]
+>[t, null] : T[]
+>t : T
+
+ var c = [t, u]; // {}[]
+>c : (T | U)[]
+>[t, u] : (T | U)[]
+>t : T
+>u : U
+
+ var d = [t, 1]; // {}[]
+>d : (number | T)[]
+>[t, 1] : (number | T)[]
+>t : T
+
+ var e = [() => t, () => u]; // {}[]
+>e : ((() => T) | (() => U))[]
+>[() => t, () => u] : ((() => T) | (() => U))[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+
+ var f = [() => t, () => u, () => null]; // { (): any }[]
+>f : (() => any)[]
+>[() => t, () => u, () => null] : (() => any)[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+>() => null : () => any
+}
+
+function foo2(t: T, u: U) {
+>foo2 : (t: T, u: U) => void
+>T : T
+>Base : Base
+>U : U
+>Derived : Derived
+>t : T
+>T : T
+>u : U
+>U : U
+
+ var a = [t, t]; // T[]
+>a : T[]
+>[t, t] : T[]
+>t : T
+>t : T
+
+ var b = [t, null]; // T[]
+>b : T[]
+>[t, null] : T[]
+>t : T
+
+ var c = [t, u]; // {}[]
+>c : (T | U)[]
+>[t, u] : (T | U)[]
+>t : T
+>u : U
+
+ var d = [t, 1]; // {}[]
+>d : (number | T)[]
+>[t, 1] : (number | T)[]
+>t : T
+
+ var e = [() => t, () => u]; // {}[]
+>e : ((() => T) | (() => U))[]
+>[() => t, () => u] : ((() => T) | (() => U))[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+
+ var f = [() => t, () => u, () => null]; // { (): any }[]
+>f : (() => any)[]
+>[() => t, () => u, () => null] : (() => any)[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+>() => null : () => any
+
+ var g = [t, base]; // Base[]
+>g : Base[]
+>[t, base] : Base[]
+>t : T
+>base : Base
+
+ var h = [t, derived]; // Derived[]
+>h : (Derived | T)[]
+>[t, derived] : (Derived | T)[]
+>t : T
+>derived : Derived
+
+ var i = [u, base]; // Base[]
+>i : Base[]
+>[u, base] : Base[]
+>u : U
+>base : Base
+
+ var j = [u, derived]; // Derived[]
+>j : Derived[]
+>[u, derived] : Derived[]
+>u : U
+>derived : Derived
+}
+
+function foo3(t: T, u: U) {
+>foo3 : (t: T, u: U) => void
+>T : T
+>Derived : Derived
+>U : U
+>Derived : Derived
+>t : T
+>T : T
+>u : U
+>U : U
+
+ var a = [t, t]; // T[]
+>a : T[]
+>[t, t] : T[]
+>t : T
+>t : T
+
+ var b = [t, null]; // T[]
+>b : T[]
+>[t, null] : T[]
+>t : T
+
+ var c = [t, u]; // {}[]
+>c : (T | U)[]
+>[t, u] : (T | U)[]
+>t : T
+>u : U
+
+ var d = [t, 1]; // {}[]
+>d : (number | T)[]
+>[t, 1] : (number | T)[]
+>t : T
+
+ var e = [() => t, () => u]; // {}[]
+>e : ((() => T) | (() => U))[]
+>[() => t, () => u] : ((() => T) | (() => U))[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+
+ var f = [() => t, () => u, () => null]; // { (): any }[]
+>f : (() => any)[]
+>[() => t, () => u, () => null] : (() => any)[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+>() => null : () => any
+
+ var g = [t, base]; // Base[]
+>g : Base[]
+>[t, base] : Base[]
+>t : T
+>base : Base
+
+ var h = [t, derived]; // Derived[]
+>h : Derived[]
+>[t, derived] : Derived[]
+>t : T
+>derived : Derived
+
+ var i = [u, base]; // Base[]
+>i : Base[]
+>[u, base] : Base[]
+>u : U
+>base : Base
+
+ var j = [u, derived]; // Derived[]
+>j : Derived[]
+>[u, derived] : Derived[]
+>u : U
+>derived : Derived
+}
+
+function foo4(t: T, u: U) {
+>foo4 : (t: T, u: U) => void
+>T : T
+>Base : Base
+>U : U
+>Base : Base
+>t : T
+>T : T
+>u : U
+>U : U
+
+ var a = [t, t]; // T[]
+>a : T[]
+>[t, t] : T[]
+>t : T
+>t : T
+
+ var b = [t, null]; // T[]
+>b : T[]
+>[t, null] : T[]
+>t : T
+
+ var c = [t, u]; // BUG 821629
+>c : (T | U)[]
+>[t, u] : (T | U)[]
+>t : T
+>u : U
+
+ var d = [t, 1]; // {}[]
+>d : (number | T)[]
+>[t, 1] : (number | T)[]
+>t : T
+
+ var e = [() => t, () => u]; // {}[]
+>e : ((() => T) | (() => U))[]
+>[() => t, () => u] : ((() => T) | (() => U))[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+
+ var f = [() => t, () => u, () => null]; // { (): any }[]
+>f : (() => any)[]
+>[() => t, () => u, () => null] : (() => any)[]
+>() => t : () => T
+>t : T
+>() => u : () => U
+>u : U
+>() => null : () => any
+
+ var g = [t, base]; // Base[]
+>g : Base[]
+>[t, base] : Base[]
+>t : T
+>base : Base
+
+ var h = [t, derived]; // Derived[]
+>h : (Derived | T)[]
+>[t, derived] : (Derived | T)[]
+>t : T
+>derived : Derived
+
+ var i = [u, base]; // Base[]
+>i : Base[]
+>[u, base] : Base[]
+>u : U
+>base : Base
+
+ var j = [u, derived]; // Derived[]
+>j : (Derived | U)[]
+>[u, derived] : (Derived | U)[]
+>u : U
+>derived : Derived
+
+ var k: Base[] = [t, u];
+>k : Base[]
+>Base : Base
+>[t, u] : (T | U)[]
+>t : T
+>u : U
+}
+
+//function foo3(t: T, u: U) {
+// var a = [t, t]; // T[]
+// var b = [t, null]; // T[]
+// var c = [t, u]; // {}[]
+// var d = [t, 1]; // {}[]
+// var e = [() => t, () => u]; // {}[]
+// var f = [() => t, () => u, () => null]; // { (): any }[]
+
+// var g = [t, base]; // Base[]
+// var h = [t, derived]; // Derived[]
+// var i = [u, base]; // Base[]
+// var j = [u, derived]; // Derived[]
+//}
+
+//function foo4(t: T, u: U) {
+// var a = [t, t]; // T[]
+// var b = [t, null]; // T[]
+// var c = [t, u]; // BUG 821629
+// var d = [t, 1]; // {}[]
+// var e = [() => t, () => u]; // {}[]
+// var f = [() => t, () => u, () => null]; // { (): any }[]
+
+// var g = [t, base]; // Base[]
+// var h = [t, derived]; // Derived[]
+// var i = [u, base]; // Base[]
+// var j = [u, derived]; // Derived[]
+
+// var k: Base[] = [t, u];
+//}
diff --git a/tests/baselines/reference/intrinsics.errors.txt b/tests/baselines/reference/intrinsics.errors.txt
index e9529d4b9f0..342b84e02b9 100644
--- a/tests/baselines/reference/intrinsics.errors.txt
+++ b/tests/baselines/reference/intrinsics.errors.txt
@@ -1,12 +1,15 @@
tests/cases/compiler/intrinsics.ts(2,21): error TS2304: Cannot find name 'hasOwnProperty'.
+tests/cases/compiler/intrinsics.ts(2,21): error TS4025: Exported variable 'hasOwnProperty' has or is using private name 'hasOwnProperty'.
tests/cases/compiler/intrinsics.ts(11,1): error TS2304: Cannot find name '__proto__'.
-==== tests/cases/compiler/intrinsics.ts (2 errors) ====
+==== tests/cases/compiler/intrinsics.ts (3 errors) ====
var hasOwnProperty: hasOwnProperty; // Error
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'hasOwnProperty'.
+ ~~~~~~~~~~~~~~
+!!! error TS4025: Exported variable 'hasOwnProperty' has or is using private name 'hasOwnProperty'.
module m1 {
export var __proto__;
diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types.pull b/tests/baselines/reference/logicalOrOperatorWithEveryType.types.pull
new file mode 100644
index 00000000000..e0d75463414
--- /dev/null
+++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types.pull
@@ -0,0 +1,618 @@
+=== tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrOperatorWithEveryType.ts ===
+// The || operator permits the operands to be of any type.
+// If the || expression is not contextually typed, the right operand is contextually typed
+// by the type of the left operand and the result is of the best common type of the two
+// operand types.
+
+enum E { a, b, c }
+>E : E
+>a : E
+>b : E
+>c : E
+
+var a1: any;
+>a1 : any
+
+var a2: boolean;
+>a2 : boolean
+
+var a3: number
+>a3 : number
+
+var a4: string;
+>a4 : string
+
+var a5: void;
+>a5 : void
+
+var a6: E;
+>a6 : E
+>E : E
+
+var a7: {a: string};
+>a7 : { a: string; }
+>a : string
+
+var a8: string[];
+>a8 : string[]
+
+var ra1 = a1 || a1; // any || any is any
+>ra1 : any
+>a1 || a1 : any
+>a1 : any
+>a1 : any
+
+var ra2 = a2 || a1; // boolean || any is any
+>ra2 : any
+>a2 || a1 : any
+>a2 : boolean
+>a1 : any
+
+var ra3 = a3 || a1; // number || any is any
+>ra3 : any
+>a3 || a1 : any
+>a3 : number
+>a1 : any
+
+var ra4 = a4 || a1; // string || any is any
+>ra4 : any
+>a4 || a1 : any
+>a4 : string
+>a1 : any
+
+var ra5 = a5 || a1; // void || any is any
+>ra5 : any
+>a5 || a1 : any
+>a5 : void
+>a1 : any
+
+var ra6 = a6 || a1; // enum || any is any
+>ra6 : any
+>a6 || a1 : any
+>a6 : E
+>a1 : any
+
+var ra7 = a7 || a1; // object || any is any
+>ra7 : any
+>a7 || a1 : any
+>a7 : { a: string; }
+>a1 : any
+
+var ra8 = a8 || a1; // array || any is any
+>ra8 : any
+>a8 || a1 : any
+>a8 : string[]
+>a1 : any
+
+var ra9 = null || a1; // null || any is any
+>ra9 : any
+>null || a1 : any
+>a1 : any
+
+var ra10 = undefined || a1; // undefined || any is any
+>ra10 : any
+>undefined || a1 : any
+>undefined : undefined
+>a1 : any
+
+var rb1 = a1 || a2; // any || boolean is any
+>rb1 : any
+>a1 || a2 : any
+>a1 : any
+>a2 : boolean
+
+var rb2 = a2 || a2; // boolean || boolean is boolean
+>rb2 : boolean
+>a2 || a2 : boolean
+>a2 : boolean
+>a2 : boolean
+
+var rb3 = a3 || a2; // number || boolean is number | boolean
+>rb3 : number | boolean
+>a3 || a2 : number | boolean
+>a3 : number
+>a2 : boolean
+
+var rb4 = a4 || a2; // string || boolean is string | boolean
+>rb4 : string | boolean
+>a4 || a2 : string | boolean
+>a4 : string
+>a2 : boolean
+
+var rb5 = a5 || a2; // void || boolean is void | boolean
+>rb5 : boolean | void
+>a5 || a2 : boolean | void
+>a5 : void
+>a2 : boolean
+
+var rb6 = a6 || a2; // enum || boolean is E | boolean
+>rb6 : boolean | E
+>a6 || a2 : boolean | E
+>a6 : E
+>a2 : boolean
+
+var rb7 = a7 || a2; // object || boolean is object | boolean
+>rb7 : boolean | { a: string; }
+>a7 || a2 : boolean | { a: string; }
+>a7 : { a: string; }
+>a2 : boolean
+
+var rb8 = a8 || a2; // array || boolean is array | boolean
+>rb8 : boolean | string[]
+>a8 || a2 : boolean | string[]
+>a8 : string[]
+>a2 : boolean
+
+var rb9 = null || a2; // null || boolean is boolean
+>rb9 : boolean
+>null || a2 : boolean
+>a2 : boolean
+
+var rb10= undefined || a2; // undefined || boolean is boolean
+>rb10 : boolean
+>undefined || a2 : boolean
+>undefined : undefined
+>a2 : boolean
+
+var rc1 = a1 || a3; // any || number is any
+>rc1 : any
+>a1 || a3 : any
+>a1 : any
+>a3 : number
+
+var rc2 = a2 || a3; // boolean || number is boolean | number
+>rc2 : number | boolean
+>a2 || a3 : number | boolean
+>a2 : boolean
+>a3 : number
+
+var rc3 = a3 || a3; // number || number is number
+>rc3 : number
+>a3 || a3 : number
+>a3 : number
+>a3 : number
+
+var rc4 = a4 || a3; // string || number is string | number
+>rc4 : string | number
+>a4 || a3 : string | number
+>a4 : string
+>a3 : number
+
+var rc5 = a5 || a3; // void || number is void | number
+>rc5 : number | void
+>a5 || a3 : number | void
+>a5 : void
+>a3 : number
+
+var rc6 = a6 || a3; // enum || number is number
+>rc6 : number
+>a6 || a3 : number
+>a6 : E
+>a3 : number
+
+var rc7 = a7 || a3; // object || number is object | number
+>rc7 : number | { a: string; }
+>a7 || a3 : number | { a: string; }
+>a7 : { a: string; }
+>a3 : number
+
+var rc8 = a8 || a3; // array || number is array | number
+>rc8 : number | string[]
+>a8 || a3 : number | string[]
+>a8 : string[]
+>a3 : number
+
+var rc9 = null || a3; // null || number is number
+>rc9 : number
+>null || a3 : number
+>a3 : number
+
+var rc10 = undefined || a3; // undefined || number is number
+>rc10 : number
+>undefined || a3 : number
+>undefined : undefined
+>a3 : number
+
+var rd1 = a1 || a4; // any || string is any
+>rd1 : any
+>a1 || a4 : any
+>a1 : any
+>a4 : string
+
+var rd2 = a2 || a4; // boolean || string is boolean | string
+>rd2 : string | boolean
+>a2 || a4 : string | boolean
+>a2 : boolean
+>a4 : string
+
+var rd3 = a3 || a4; // number || string is number | string
+>rd3 : string | number
+>a3 || a4 : string | number
+>a3 : number
+>a4 : string
+
+var rd4 = a4 || a4; // string || string is string
+>rd4 : string
+>a4 || a4 : string
+>a4 : string
+>a4 : string
+
+var rd5 = a5 || a4; // void || string is void | string
+>rd5 : string | void
+>a5 || a4 : string | void
+>a5 : void
+>a4 : string
+
+var rd6 = a6 || a4; // enum || string is enum | string
+>rd6 : string | E
+>a6 || a4 : string | E
+>a6 : E
+>a4 : string
+
+var rd7 = a7 || a4; // object || string is object | string
+>rd7 : string | { a: string; }
+>a7 || a4 : string | { a: string; }
+>a7 : { a: string; }
+>a4 : string
+
+var rd8 = a8 || a4; // array || string is array | string
+>rd8 : string | string[]
+>a8 || a4 : string | string[]
+>a8 : string[]
+>a4 : string
+
+var rd9 = null || a4; // null || string is string
+>rd9 : string
+>null || a4 : string
+>a4 : string
+
+var rd10 = undefined || a4; // undefined || string is string
+>rd10 : string
+>undefined || a4 : string
+>undefined : undefined
+>a4 : string
+
+var re1 = a1 || a5; // any || void is any
+>re1 : any
+>a1 || a5 : any
+>a1 : any
+>a5 : void
+
+var re2 = a2 || a5; // boolean || void is boolean | void
+>re2 : boolean | void
+>a2 || a5 : boolean | void
+>a2 : boolean
+>a5 : void
+
+var re3 = a3 || a5; // number || void is number | void
+>re3 : number | void
+>a3 || a5 : number | void
+>a3 : number
+>a5 : void
+
+var re4 = a4 || a5; // string || void is string | void
+>re4 : string | void
+>a4 || a5 : string | void
+>a4 : string
+>a5 : void
+
+var re5 = a5 || a5; // void || void is void
+>re5 : void
+>a5 || a5 : void
+>a5 : void
+>a5 : void
+
+var re6 = a6 || a5; // enum || void is enum | void
+>re6 : void | E
+>a6 || a5 : void | E
+>a6 : E
+>a5 : void
+
+var re7 = a7 || a5; // object || void is object | void
+>re7 : void | { a: string; }
+>a7 || a5 : void | { a: string; }
+>a7 : { a: string; }
+>a5 : void
+
+var re8 = a8 || a5; // array || void is array | void
+>re8 : void | string[]
+>a8 || a5 : void | string[]
+>a8 : string[]
+>a5 : void
+
+var re9 = null || a5; // null || void is void
+>re9 : void
+>null || a5 : void
+>a5 : void
+
+var re10 = undefined || a5; // undefined || void is void
+>re10 : void
+>undefined || a5 : void
+>undefined : undefined
+>a5 : void
+
+var rg1 = a1 || a6; // any || enum is any
+>rg1 : any
+>a1 || a6 : any
+>a1 : any
+>a6 : E
+
+var rg2 = a2 || a6; // boolean || enum is boolean | enum
+>rg2 : boolean | E
+>a2 || a6 : boolean | E
+>a2 : boolean
+>a6 : E
+
+var rg3 = a3 || a6; // number || enum is number
+>rg3 : number
+>a3 || a6 : number
+>a3 : number
+>a6 : E
+
+var rg4 = a4 || a6; // string || enum is string | enum
+>rg4 : string | E
+>a4 || a6 : string | E
+>a4 : string
+>a6 : E
+
+var rg5 = a5 || a6; // void || enum is void | enum
+>rg5 : void | E
+>a5 || a6 : void | E
+>a5 : void
+>a6 : E
+
+var rg6 = a6 || a6; // enum || enum is E
+>rg6 : E
+>a6 || a6 : E
+>a6 : E
+>a6 : E
+
+var rg7 = a7 || a6; // object || enum is object | enum
+>rg7 : E | { a: string; }
+>a7 || a6 : E | { a: string; }
+>a7 : { a: string; }
+>a6 : E
+
+var rg8 = a8 || a6; // array || enum is array | enum
+>rg8 : E | string[]
+>a8 || a6 : E | string[]
+>a8 : string[]
+>a6 : E
+
+var rg9 = null || a6; // null || enum is E
+>rg9 : E
+>null || a6 : E
+>a6 : E
+
+var rg10 = undefined || a6; // undefined || enum is E
+>rg10 : E
+>undefined || a6 : E
+>undefined : undefined
+>a6 : E
+
+var rh1 = a1 || a7; // any || object is any
+>rh1 : any
+>a1 || a7 : any
+>a1 : any
+>a7 : { a: string; }
+
+var rh2 = a2 || a7; // boolean || object is boolean | object
+>rh2 : boolean | { a: string; }
+>a2 || a7 : boolean | { a: string; }
+>a2 : boolean
+>a7 : { a: string; }
+
+var rh3 = a3 || a7; // number || object is number | object
+>rh3 : number | { a: string; }
+>a3 || a7 : number | { a: string; }
+>a3 : number
+>a7 : { a: string; }
+
+var rh4 = a4 || a7; // string || object is string | object
+>rh4 : string | { a: string; }
+>a4 || a7 : string | { a: string; }
+>a4 : string
+>a7 : { a: string; }
+
+var rh5 = a5 || a7; // void || object is void | object
+>rh5 : void | { a: string; }
+>a5 || a7 : void | { a: string; }
+>a5 : void
+>a7 : { a: string; }
+
+var rh6 = a6 || a7; // enum || object is enum | object
+>rh6 : E | { a: string; }
+>a6 || a7 : E | { a: string; }
+>a6 : E
+>a7 : { a: string; }
+
+var rh7 = a7 || a7; // object || object is object
+>rh7 : { a: string; }
+>a7 || a7 : { a: string; }
+>a7 : { a: string; }
+>a7 : { a: string; }
+
+var rh8 = a8 || a7; // array || object is array | object
+>rh8 : { a: string; } | string[]
+>a8 || a7 : { a: string; } | string[]
+>a8 : string[]
+>a7 : { a: string; }
+
+var rh9 = null || a7; // null || object is object
+>rh9 : { a: string; }
+>null || a7 : { a: string; }
+>a7 : { a: string; }
+
+var rh10 = undefined || a7; // undefined || object is object
+>rh10 : { a: string; }
+>undefined || a7 : { a: string; }
+>undefined : undefined
+>a7 : { a: string; }
+
+var ri1 = a1 || a8; // any || array is any
+>ri1 : any
+>a1 || a8 : any
+>a1 : any
+>a8 : string[]
+
+var ri2 = a2 || a8; // boolean || array is boolean | array
+>ri2 : boolean | string[]
+>a2 || a8 : boolean | string[]
+>a2 : boolean
+>a8 : string[]
+
+var ri3 = a3 || a8; // number || array is number | array
+>ri3 : number | string[]
+>a3 || a8 : number | string[]
+>a3 : number
+>a8 : string[]
+
+var ri4 = a4 || a8; // string || array is string | array
+>ri4 : string | string[]
+>a4 || a8 : string | string[]
+>a4 : string
+>a8 : string[]
+
+var ri5 = a5 || a8; // void || array is void | array
+>ri5 : void | string[]
+>a5 || a8 : void | string[]
+>a5 : void
+>a8 : string[]
+
+var ri6 = a6 || a8; // enum || array is enum | array
+>ri6 : E | string[]
+>a6 || a8 : E | string[]
+>a6 : E
+>a8 : string[]
+
+var ri7 = a7 || a8; // object || array is object | array
+>ri7 : { a: string; } | string[]
+>a7 || a8 : { a: string; } | string[]
+>a7 : { a: string; }
+>a8 : string[]
+
+var ri8 = a8 || a8; // array || array is array
+>ri8 : string[]
+>a8 || a8 : string[]
+>a8 : string[]
+>a8 : string[]
+
+var ri9 = null || a8; // null || array is array
+>ri9 : string[]
+>null || a8 : string[]
+>a8 : string[]
+
+var ri10 = undefined || a8; // undefined || array is array
+>ri10 : string[]
+>undefined || a8 : string[]
+>undefined : undefined
+>a8 : string[]
+
+var rj1 = a1 || null; // any || null is any
+>rj1 : any
+>a1 || null : any
+>a1 : any
+
+var rj2 = a2 || null; // boolean || null is boolean
+>rj2 : boolean
+>a2 || null : boolean
+>a2 : boolean
+
+var rj3 = a3 || null; // number || null is number
+>rj3 : number
+>a3 || null : number
+>a3 : number
+
+var rj4 = a4 || null; // string || null is string
+>rj4 : string
+>a4 || null : string
+>a4 : string
+
+var rj5 = a5 || null; // void || null is void
+>rj5 : void
+>a5 || null : void
+>a5 : void
+
+var rj6 = a6 || null; // enum || null is E
+>rj6 : E
+>a6 || null : E
+>a6 : E
+
+var rj7 = a7 || null; // object || null is object
+>rj7 : { a: string; }
+>a7 || null : { a: string; }
+>a7 : { a: string; }
+
+var rj8 = a8 || null; // array || null is array
+>rj8 : string[]
+>a8 || null : string[]
+>a8 : string[]
+
+var rj9 = null || null; // null || null is any
+>rj9 : any
+>null || null : null
+
+var rj10 = undefined || null; // undefined || null is any
+>rj10 : any
+>undefined || null : null
+>undefined : undefined
+
+var rf1 = a1 || undefined; // any || undefined is any
+>rf1 : any
+>a1 || undefined : any
+>a1 : any
+>undefined : undefined
+
+var rf2 = a2 || undefined; // boolean || undefined is boolean
+>rf2 : boolean
+>a2 || undefined : boolean
+>a2 : boolean
+>undefined : undefined
+
+var rf3 = a3 || undefined; // number || undefined is number
+>rf3 : number
+>a3 || undefined : number
+>a3 : number
+>undefined : undefined
+
+var rf4 = a4 || undefined; // string || undefined is string
+>rf4 : string
+>a4 || undefined : string
+>a4 : string
+>undefined : undefined
+
+var rf5 = a5 || undefined; // void || undefined is void
+>rf5 : void
+>a5 || undefined : void
+>a5 : void
+>undefined : undefined
+
+var rf6 = a6 || undefined; // enum || undefined is E
+>rf6 : E
+>a6 || undefined : E
+>a6 : E
+>undefined : undefined
+
+var rf7 = a7 || undefined; // object || undefined is object
+>rf7 : { a: string; }
+>a7 || undefined : { a: string; }
+>a7 : { a: string; }
+>undefined : undefined
+
+var rf8 = a8 || undefined; // array || undefined is array
+>rf8 : string[]
+>a8 || undefined : string[]
+>a8 : string[]
+>undefined : undefined
+
+var rf9 = null || undefined; // null || undefined is any
+>rf9 : any
+>null || undefined : null
+>undefined : undefined
+
+var rf10 = undefined || undefined; // undefined || undefined is any
+>rf10 : any
+>undefined || undefined : undefined
+>undefined : undefined
+>undefined : undefined
+
diff --git a/tests/baselines/reference/moduledecl.js b/tests/baselines/reference/moduledecl.js
index 9be1b116a5e..4a27e0fbe1f 100644
--- a/tests/baselines/reference/moduledecl.js
+++ b/tests/baselines/reference/moduledecl.js
@@ -376,3 +376,137 @@ var m3cVar = new mAmbient.m3.C();
var m3aVar = mAmbient.m3.aVar;
var m3bB;
var m3eVar;
+
+
+//// [moduledecl.d.ts]
+declare module a {
+}
+declare module b.a {
+}
+declare module c.a.b {
+}
+declare module mImport {
+}
+declare module m0 {
+}
+declare module m1 {
+ function f1(): void;
+ function f2(s: string): any;
+ function f2(n: number): any;
+ class c1 {
+ n: any;
+ n2: number;
+ private n3;
+ private n4;
+ a: () => string;
+ private b;
+ private static s1;
+ static s2: any;
+ d(): string;
+ e: {
+ x: number;
+ y: string;
+ };
+ constructor(n: any, n2: number, n3: any, n4: string);
+ }
+ interface i1 {
+ (): Object;
+ [n: number]: c1;
+ }
+}
+declare module m {
+ module m2 {
+ var b: number;
+ }
+ module m3 {
+ var c: number;
+ }
+}
+declare module m {
+ module m25 {
+ module m5 {
+ var c: number;
+ }
+ }
+}
+declare module m13 {
+ module m4 {
+ module m2 {
+ module m3 {
+ var c: number;
+ }
+ }
+ function f(): number;
+ }
+}
+declare module m4 {
+ var b: any;
+}
+declare module m5 {
+ var c: any;
+}
+declare module m43 {
+ var b: any;
+}
+declare module m55 {
+ var c: any;
+}
+declare module "m3" {
+ var b: number;
+}
+declare module exportTests {
+ class C1_public {
+ private f2();
+ f3(): string;
+ }
+ class C3_public {
+ private getC2_private();
+ private setC2_private(arg);
+ private c2;
+ getC1_public(): C1_public;
+ setC1_public(arg: C1_public): void;
+ c1: C1_public;
+ }
+}
+declare module mAmbient {
+ class C {
+ myProp: number;
+ }
+ function foo(): C;
+ var aVar: C;
+ interface B {
+ x: number;
+ y: C;
+ }
+ enum e {
+ x,
+ y,
+ z,
+ }
+ module m3 {
+ class C {
+ myProp: number;
+ }
+ function foo(): C;
+ var aVar: C;
+ interface B {
+ x: number;
+ y: C;
+ }
+ enum e {
+ x,
+ y,
+ z,
+ }
+ }
+}
+declare function foo(): mAmbient.C;
+declare var cVar: mAmbient.C;
+declare var aVar: mAmbient.C;
+declare var bB: mAmbient.B;
+declare var eVar: mAmbient.e;
+declare function m3foo(): mAmbient.m3.C;
+declare var m3cVar: mAmbient.m3.C;
+declare var m3aVar: mAmbient.m3.C;
+declare var m3bB: mAmbient.m3.B;
+declare var m3eVar: mAmbient.m3.e;
diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt
index 360259adf7c..2a7c07bfcdb 100644
--- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt
+++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt
@@ -1,9 +1,11 @@
tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules.
tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules.
+tests/cases/compiler/privacyGloImportParseErrors.ts(49,29): error TS4000: Import declaration 'm1_im2_private' is using private name 'm1_M2_private'.
tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS1147: Import declarations in an internal module cannot reference an external module.
tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'.
tests/cases/compiler/privacyGloImportParseErrors.ts(69,37): error TS1147: Import declarations in an internal module cannot reference an external module.
tests/cases/compiler/privacyGloImportParseErrors.ts(69,37): error TS2307: Cannot find external module 'm1_M4_private'.
+tests/cases/compiler/privacyGloImportParseErrors.ts(80,35): error TS4000: Import declaration 'm1_im2_public' is using private name 'm1_M2_private'.
tests/cases/compiler/privacyGloImportParseErrors.ts(81,43): error TS1147: Import declarations in an internal module cannot reference an external module.
tests/cases/compiler/privacyGloImportParseErrors.ts(81,43): error TS2307: Cannot find external module 'm1_M3_public'.
tests/cases/compiler/privacyGloImportParseErrors.ts(82,43): error TS1147: Import declarations in an internal module cannot reference an external module.
@@ -18,7 +20,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Impor
tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Import declarations in an internal module cannot reference an external module.
-==== tests/cases/compiler/privacyGloImportParseErrors.ts (18 errors) ====
+==== tests/cases/compiler/privacyGloImportParseErrors.ts (20 errors) ====
module m1 {
export module m1_M1_public {
export class c1 {
@@ -72,6 +74,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor
import m1_im2_private = m1_M2_private;
+ ~~~~~~~~~~~~~
+!!! error TS4000: Import declaration 'm1_im2_private' is using private name 'm1_M2_private'.
export var m1_im2_private_v1_public = m1_im2_private.c1;
export var m1_im2_private_v2_public = new m1_im2_private.c1();
export var m1_im2_private_v3_public = m1_im2_private.f1;
@@ -111,6 +115,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor
export import m1_im1_public = m1_M1_public;
export import m1_im2_public = m1_M2_private;
+ ~~~~~~~~~~~~~
+!!! error TS4000: Import declaration 'm1_im2_public' is using private name 'm1_M2_private'.
export import m1_im3_public = require("m1_M3_public");
~~~~~~~~~~~~~~
!!! error TS1147: Import declarations in an internal module cannot reference an external module.
diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt
index 45741b88910..25059478bf5 100644
--- a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt
+++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt
@@ -1,8 +1,6 @@
error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
error TS6053: File 'a.ts' not found.
-error TS6053: File 'a.ts' not found.
!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
-!!! error TS6053: File 'a.ts' not found.
!!! error TS6053: File 'a.ts' not found.
\ No newline at end of file
diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt
index 45741b88910..25059478bf5 100644
--- a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt
+++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt
@@ -1,8 +1,6 @@
error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
error TS6053: File 'a.ts' not found.
-error TS6053: File 'a.ts' not found.
!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'.
-!!! error TS6053: File 'a.ts' not found.
!!! error TS6053: File 'a.ts' not found.
\ No newline at end of file
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/baselines/reference/typeGuardsInConditionalExpression.types.pull b/tests/baselines/reference/typeGuardsInConditionalExpression.types.pull
new file mode 100644
index 00000000000..147a24b690a
--- /dev/null
+++ b/tests/baselines/reference/typeGuardsInConditionalExpression.types.pull
@@ -0,0 +1,356 @@
+=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts ===
+// In the true expression of a conditional expression,
+// the type of a variable or parameter is narrowed by any type guard in the condition when true,
+// provided the true expression contains no assignments to the variable or parameter.
+// In the false expression of a conditional expression,
+// the type of a variable or parameter is narrowed by any type guard in the condition when false,
+// provided the false expression contains no assignments to the variable or parameter.
+
+function foo(x: number | string) {
+>foo : (x: string | number) => number
+>x : string | number
+
+ return typeof x === "string"
+>typeof x === "string" ? x.length // string : x++ : number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? x.length // string
+>x.length : number
+>x : string
+>length : number
+
+ : x++; // number
+>x++ : number
+>x : number
+}
+function foo2(x: number | string) {
+>foo2 : (x: string | number) => string | number
+>x : string | number
+
+ // x is assigned in the if true branch, the type is not narrowed
+ return typeof x === "string"
+>typeof x === "string" ? (x = 10 && x)// string | number : x : string | number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? (x = 10 && x)// string | number
+>(x = 10 && x) : string | number
+>x = 10 && x : string | number
+>x : string | number
+>10 && x : string | number
+>x : string | number
+
+ : x; // string | number
+>x : string | number
+}
+function foo3(x: number | string) {
+>foo3 : (x: string | number) => string | number
+>x : string | number
+
+ // x is assigned in the if false branch, the type is not narrowed
+ // even though assigned using same type as narrowed expression
+ return typeof x === "string"
+>typeof x === "string" ? (x = "Hello" && x) // string | number : x : string | number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? (x = "Hello" && x) // string | number
+>(x = "Hello" && x) : string | number
+>x = "Hello" && x : string | number
+>x : string | number
+>"Hello" && x : string | number
+>x : string | number
+
+ : x; // string | number
+>x : string | number
+}
+function foo4(x: number | string) {
+>foo4 : (x: string | number) => string | number
+>x : string | number
+
+ // false branch updates the variable - so here it is not number
+ // even though assigned using same type as narrowed expression
+ return typeof x === "string"
+>typeof x === "string" ? x // string | number : (x = 10 && x) : string | number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? x // string | number
+>x : string | number
+
+ : (x = 10 && x); // string | number
+>(x = 10 && x) : string | number
+>x = 10 && x : string | number
+>x : string | number
+>10 && x : string | number
+>x : string | number
+}
+function foo5(x: number | string) {
+>foo5 : (x: string | number) => string | number
+>x : string | number
+
+ // false branch updates the variable - so here it is not number
+ return typeof x === "string"
+>typeof x === "string" ? x // string | number : (x = "hello" && x) : string | number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? x // string | number
+>x : string | number
+
+ : (x = "hello" && x); // string | number
+>(x = "hello" && x) : string | number
+>x = "hello" && x : string | number
+>x : string | number
+>"hello" && x : string | number
+>x : string | number
+}
+function foo6(x: number | string) {
+>foo6 : (x: string | number) => string | number
+>x : string | number
+
+ // Modify in both branches
+ return typeof x === "string"
+>typeof x === "string" ? (x = 10 && x) // string | number : (x = "hello" && x) : string | number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? (x = 10 && x) // string | number
+>(x = 10 && x) : string | number
+>x = 10 && x : string | number
+>x : string | number
+>10 && x : string | number
+>x : string | number
+
+ : (x = "hello" && x); // string | number
+>(x = "hello" && x) : string | number
+>x = "hello" && x : string | number
+>x : string | number
+>"hello" && x : string | number
+>x : string | number
+}
+function foo7(x: number | string | boolean) {
+>foo7 : (x: string | number | boolean) => boolean
+>x : string | number | boolean
+
+ return typeof x === "string"
+>typeof x === "string" ? x === "hello" // string : typeof x === "boolean" ? x // boolean : x == 10 : boolean
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ ? x === "hello" // string
+>x === "hello" : boolean
+>x : string
+
+ : typeof x === "boolean"
+>typeof x === "boolean" ? x // boolean : x == 10 : boolean
+>typeof x === "boolean" : boolean
+>typeof x : string
+>x : number | boolean
+
+ ? x // boolean
+>x : boolean
+
+ : x == 10; // number
+>x == 10 : boolean
+>x : number
+}
+function foo8(x: number | string | boolean) {
+>foo8 : (x: string | number | boolean) => boolean
+>x : string | number | boolean
+
+ var b: number | boolean;
+>b : number | boolean
+
+ return typeof x === "string"
+>typeof x === "string" ? x === "hello" : ((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ ? x === "hello"
+>x === "hello" : boolean
+>x : string
+
+ : ((b = x) && // number | boolean
+>((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
+>(b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10) : boolean
+>(b = x) : number | boolean
+>b = x : number | boolean
+>b : number | boolean
+>x : number | boolean
+
+ (typeof x === "boolean"
+>(typeof x === "boolean" ? x // boolean : x == 10) : boolean
+>typeof x === "boolean" ? x // boolean : x == 10 : boolean
+>typeof x === "boolean" : boolean
+>typeof x : string
+>x : number | boolean
+
+ ? x // boolean
+>x : boolean
+
+ : x == 10)); // number
+>x == 10 : boolean
+>x : number
+}
+function foo9(x: number | string) {
+>foo9 : (x: string | number) => boolean
+>x : string | number
+
+ var y = 10;
+>y : number
+
+ // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
+ return typeof x === "string"
+>typeof x === "string" ? ((y = x.length) && x === "hello") // string : x === 10 : boolean
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number
+
+ ? ((y = x.length) && x === "hello") // string
+>((y = x.length) && x === "hello") : boolean
+>(y = x.length) && x === "hello" : boolean
+>(y = x.length) : number
+>y = x.length : number
+>y : number
+>x.length : number
+>x : string
+>length : number
+>x === "hello" : boolean
+>x : string
+
+ : x === 10; // number
+>x === 10 : boolean
+>x : number
+}
+function foo10(x: number | string | boolean) {
+>foo10 : (x: string | number | boolean) => string
+>x : string | number | boolean
+
+ // Mixing typeguards
+ var b: boolean | number;
+>b : number | boolean
+
+ return typeof x === "string"
+>typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ ? x // string
+>x : string
+
+ : ((b = x) // x is number | boolean
+>((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
+>(b = x) // x is number | boolean && typeof x === "number" && x.toString() : string
+>(b = x) // x is number | boolean && typeof x === "number" : boolean
+>(b = x) : number | boolean
+>b = x : number | boolean
+>b : number | boolean
+>x : number | boolean
+
+ && typeof x === "number"
+>typeof x === "number" : boolean
+>typeof x : string
+>x : number | boolean
+
+ && x.toString()); // x is number
+>x.toString() : string
+>x.toString : (radix?: number) => string
+>x : number
+>toString : (radix?: number) => string
+}
+function foo11(x: number | string | boolean) {
+>foo11 : (x: string | number | boolean) => string | number | boolean
+>x : string | number | boolean
+
+ // Mixing typeguards
+ // Assigning value to x deep inside another guard stops narrowing of type too
+ var b: number | boolean | string;
+>b : string | number | boolean
+
+ return typeof x === "string"
+>typeof x === "string" ? x // number | boolean | string - changed in the false branch : ((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ ? x // number | boolean | string - changed in the false branch
+>x : string | number | boolean
+
+ : ((b = x) // x is number | boolean | string - because the assignment changed it
+>((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean
+>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x : string | number | boolean
+>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) : number
+>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" : boolean
+>(b = x) : string | number | boolean
+>b = x : string | number | boolean
+>b : string | number | boolean
+>x : string | number | boolean
+
+ && typeof x === "number"
+>typeof x === "number" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ && (x = 10) // assignment to x
+>(x = 10) : number
+>x = 10 : number
+>x : string | number | boolean
+
+ && x); // x is number | boolean | string
+>x : string | number | boolean
+}
+function foo12(x: number | string | boolean) {
+>foo12 : (x: string | number | boolean) => number
+>x : string | number | boolean
+
+ // Mixing typeguards
+ // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
+ var b: number | boolean | string;
+>b : string | number | boolean
+
+ return typeof x === "string"
+>typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here : ((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
+>typeof x === "string" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ ? (x = 10 && x.toString().length) // number | boolean | string - changed here
+>(x = 10 && x.toString().length) : number
+>x = 10 && x.toString().length : number
+>x : string | number | boolean
+>10 && x.toString().length : number
+>x.toString().length : number
+>x.toString() : string
+>x.toString : (radix?: number) => string
+>x : string | number | boolean
+>toString : (radix?: number) => string
+>length : number
+
+ : ((b = x) // x is number | boolean | string - changed in true branch
+>((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
+>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x : number
+>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" : boolean
+>(b = x) : string | number | boolean
+>b = x : string | number | boolean
+>b : string | number | boolean
+>x : string | number | boolean
+
+ && typeof x === "number"
+>typeof x === "number" : boolean
+>typeof x : string
+>x : string | number | boolean
+
+ && x); // x is number
+>x : number
+}
diff --git a/tests/baselines/reference/widenedTypes.js b/tests/baselines/reference/widenedTypes.js
index 92dae28b6e4..5a76ae72905 100644
--- a/tests/baselines/reference/widenedTypes.js
+++ b/tests/baselines/reference/widenedTypes.js
@@ -43,3 +43,17 @@ var ob = { x: "" };
// Highlights the difference between array literals and object literals
var arr = [3, null]; // not assignable because null is not widened. BCT is {}
var obj = { x: 3, y: null }; // assignable because null is widened, and therefore BCT is any
+
+
+//// [widenedTypes.d.ts]
+declare var t: number[];
+declare var x: typeof undefined;
+declare var y: any;
+declare var u: number[];
+declare var ob: {
+ x: typeof undefined;
+};
+declare var arr: string[];
+declare var obj: {
+ [x: string]: string;
+};
diff --git a/tests/baselines/reference/withExportDecl.js b/tests/baselines/reference/withExportDecl.js
index 7fbaa603c31..ccd13123721 100644
--- a/tests/baselines/reference/withExportDecl.js
+++ b/tests/baselines/reference/withExportDecl.js
@@ -101,3 +101,31 @@ define(["require", "exports"], function (require, exports) {
var eVar22;
exports.eVar3 = 10, exports.eVar4, exports.eVar5;
});
+
+
+//// [withExportDecl.d.ts]
+export declare var exportedSimpleVar: any;
+export declare var exportedVarWithInitialValue: number;
+export declare var exportedWithComplicatedValue: {
+ x: number;
+ y: number;
+ desc: string;
+};
+export declare var exportedDeclaredVar: number;
+export declare var exportedArrayVar: {
+ x: number;
+ y: string;
+}[];
+export declare function exportedFunction(): {
+ x: string;
+ y: string;
+ n: number;
+};
+export declare module m2 {
+ var a: number;
+}
+export declare module m3 {
+ function foo(): string;
+}
+export declare var eVar1: any, eVar2: number;
+export declare var eVar3: number, eVar4: any, eVar5: any;
diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts
index 757574c0d7d..50ec02ab6f3 100644
--- a/tests/cases/compiler/APISample_compile.ts
+++ b/tests/cases/compiler/APISample_compile.ts
@@ -10,26 +10,24 @@
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 host = ts.createCompilerHost(options);
- var program = ts.createProgram(fileNames, options, host);
- var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true);
- var result = program.emitFiles();
+ var program = ts.createProgram(fileNames, options);
+ var emitResult = program.emit();
- var allDiagnostics = program.getDiagnostics()
- .concat(checker.getDiagnostics())
- .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);
+ var exitCode = emitResult.emitSkipped ? 1 : 0;
+ console.log(`Process exiting with code '${exitCode}'.`);
+ process.exit(exitCode);
}
compile(process.argv.slice(2), {
diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts
index c3e214b0e37..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,18 +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
- var checker = program.getTypeChecker(true);
- errors = checker.getDiagnostics();
- // Generate output
- program.emitFiles();
- }
+ 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/compiler/APISample_watcher.ts b/tests/cases/compiler/APISample_watcher.ts
index f29e72604d5..212f83b3935 100644
--- a/tests/cases/compiler/APISample_watcher.ts
+++ b/tests/cases/compiler/APISample_watcher.ts
@@ -67,7 +67,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
function emitFile(fileName: string) {
var output = services.getEmitOutput(fileName);
- if (output.emitOutputStatus === ts.EmitReturnStatus.Succeeded) {
+ if (!output.emitSkipped) {
console.log(`Emitting ${fileName}`);
}
else {
@@ -88,7 +88,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
allDiagnostics.forEach(diagnostic => {
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start);
- console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`);
+ console.log(` Error ${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
}
else {
console.log(` Error: ${diagnostic.messageText}`);
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
diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts
index 1b5e1a665ab..7c4213e22c2 100644
--- a/tests/cases/unittests/incrementalParser.ts
+++ b/tests/cases/unittests/incrementalParser.ts
@@ -24,8 +24,8 @@ module ts {
}
function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) {
- var diagnostics1 = getSyntacticDiagnostics(file1);
- var diagnostics2 = getSyntacticDiagnostics(file2);
+ var diagnostics1 = file1.parseDiagnostics;
+ var diagnostics2 = file2.parseDiagnostics;
assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length");
for (var i = 0, n = diagnostics1.length; i < n; i++) {