From 35a6d0e68a7ed4118619ca963dc1454f7f0d7a10 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 13:04:42 -0800 Subject: [PATCH 01/26] Introduce an object to store and manage diagnostics for different compiler components. --- src/compiler/checker.ts | 46 ++++++++-------------- src/compiler/parser.ts | 3 +- src/compiler/types.ts | 20 ++++++++++ src/compiler/utilities.ts | 80 +++++++++++++++++++++++++++++++++++++++ src/harness/harness.ts | 3 +- 5 files changed, 118 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6aa4862abc5..433cb79d29b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -104,8 +104,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 +121,11 @@ module ts { } }; - function addDiagnostic(diagnostic: Diagnostic) { - diagnostics.push(diagnostic); - diagnosticsModified = true; - } - 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 +3473,8 @@ module ts { if (containingMessageChain) { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } - addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine())); + + diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine())); } return result !== Ternary.False; @@ -5705,9 +5700,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 +8922,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, host.getCompilerHost().getNewLine())); } } } @@ -9578,30 +9573,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[]{ throwIfNonDiagnosticsProducing(); - return filter(getSortedDiagnostics(), d => !d.file); + return diagnostics.getGlobalDiagnostics(); } function throwIfNonDiagnosticsProducing() { @@ -10234,7 +10218,7 @@ module ts { // Bind all source files and propagate errors forEach(host.getSourceFiles(), file => { bindSourceFile(file); - forEach(file.semanticDiagnostics, addDiagnostic); + forEach(file.semanticDiagnostics, d => diagnostics.add(d)); }); // Initialize global symbol table forEach(host.getSourceFiles(), file => { @@ -11035,14 +11019,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 +11036,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 +11170,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/parser.ts b/src/compiler/parser.ts index 866d66d5151..9589e25dd97 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -358,10 +358,9 @@ module ts { 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; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ff8f5d2ed48..069f2a15bba 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1678,4 +1678,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 collectoin 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..69c64ba4880 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1068,4 +1068,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[] = []; + forEach(nonFileDiagnostics, d => { allDiagnostics.push(d) }); + + for (var key in fileDiagnostics) { + if (hasProperty(fileDiagnostics, key)) { + forEach(fileDiagnostics[key], d => { allDiagnostics.push(d) }); + } + } + + return sortAndDeplicateList(allDiagnostics); + } + + function sortAndDeduplicate() { + if (!diagnosticsModified) { + return; + } + + diagnosticsModified = false; + nonFileDiagnostics = sortAndDeplicateList(nonFileDiagnostics); + + for (var key in fileDiagnostics) { + if (hasProperty(fileDiagnostics, key)) { + fileDiagnostics[key] = sortAndDeplicateList(fileDiagnostics[key]); + } + } + } + + function sortAndDeplicateList(diagnostics: Diagnostic[]): Diagnostic[] { + return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)) + } + } } \ No newline at end of file diff --git a/src/harness/harness.ts b/src/harness/harness.ts index c17a8da78e8..02e14bec954 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -921,6 +921,7 @@ module Harness { // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file currentDirectory?: string) { + debugger; options = options || { noResolve: false }; options.target = options.target || ts.ScriptTarget.ES3; options.module = options.module || ts.ModuleKind.None; @@ -1074,7 +1075,7 @@ 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 }), From 9fac51b10863ccb03b61b3aaa6871303a47c30a2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 13:11:20 -0800 Subject: [PATCH 02/26] Make more diagnostic features internal so they're not exposed in our DTS. --- src/compiler/types.ts | 35 +++++++------------ .../baselines/reference/APISample_compile.js | 4 --- .../reference/APISample_compile.types | 12 ------- tests/baselines/reference/APISample_linter.js | 4 --- .../reference/APISample_linter.types | 12 ------- .../reference/APISample_transform.js | 4 --- .../reference/APISample_transform.types | 12 ------- .../baselines/reference/APISample_watcher.js | 4 --- .../reference/APISample_watcher.types | 12 ------- 9 files changed, 13 insertions(+), 86 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 069f2a15bba..91162998555 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -896,37 +896,27 @@ module ts { 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 "///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 diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 9cc9c2ffd50..d850585ea37 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -820,10 +820,6 @@ declare module "typescript" { 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[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index aaa07714c61..f84338d9d1c 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2551,18 +2551,6 @@ declare module "typescript" { >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 diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 201053584ac..4c86119f6a0 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -821,10 +821,6 @@ declare module "typescript" { 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[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 408285caaaa..2093ec7d8f5 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2499,18 +2499,6 @@ declare module "typescript" { >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 diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 47f40c01d8e..0e242eaca34 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -858,10 +858,6 @@ declare module "typescript" { 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[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index dfdc133817e..9255c64511c 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2677,18 +2677,6 @@ declare module "typescript" { >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 From c7160ddb319fc1b3da3884306cba1a96422b4ee6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 13:31:36 -0800 Subject: [PATCH 03/26] Rename semanticDiagnostics to bindDiagnotics. --- src/compiler/binder.ts | 6 +++--- src/compiler/checker.ts | 2 +- src/compiler/parser.ts | 4 ++-- src/compiler/types.ts | 6 ++++-- src/services/services.ts | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c97e1f34772..a8055d993a1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -136,9 +136,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 +159,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 433cb79d29b..05e60ddcd46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10218,7 +10218,7 @@ module ts { // Bind all source files and propagate errors forEach(host.getSourceFiles(), file => { bindSourceFile(file); - forEach(file.semanticDiagnostics, d => diagnostics.add(d)); + forEach(file.bindDiagnostics, d => diagnostics.add(d)); }); // Initialize global symbol table forEach(host.getSourceFiles(), file => { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9589e25dd97..e563291f762 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -873,7 +873,7 @@ module ts { sourceFile.pos = sourceFile.end = 0; sourceFile.referenceDiagnostics = []; sourceFile.parseDiagnostics = []; - sourceFile.semanticDiagnostics = []; + sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0; @@ -958,7 +958,7 @@ module ts { sourceFile.syntacticDiagnostics = undefined; sourceFile.referenceDiagnostics = []; sourceFile.parseDiagnostics = []; - sourceFile.semanticDiagnostics = []; + sourceFile.bindDiagnostics = []; sourceFile.end = sourceText.length; sourceFile.text = sourceText; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 91162998555..ff71bd8a0a0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -892,7 +892,9 @@ 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; @@ -908,7 +910,7 @@ module ts { /* @internal */ parseDiagnostics: Diagnostic[]; // File level diagnostics reported by the binder. - /* @internal */ semanticDiagnostics: Diagnostic[]; + /* @internal */ bindDiagnostics: Diagnostic[]; // Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics). // This field should never be used directly, use getSyntacticDiagnostics function instead. diff --git a/src/services/services.ts b/src/services/services.ts index 630e5567beb..6a2040543ba 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -733,7 +733,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 From 5b049feb36eafd59b07538e46652295d105c99d4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 14:29:25 -0800 Subject: [PATCH 04/26] Hide the diagnostic producing methods from TypeChecker. Instead, consumers should get these diagnostics through the Program instance. --- src/compiler/program.ts | 18 ++++++-- src/compiler/types.ts | 10 ++++- src/services/services.ts | 3 +- .../baselines/reference/APISample_compile.js | 10 ++--- .../reference/APISample_compile.types | 44 ++++++++----------- tests/baselines/reference/APISample_linter.js | 4 +- .../reference/APISample_linter.types | 20 ++++----- .../reference/APISample_transform.js | 10 ++--- .../reference/APISample_transform.types | 39 +++++++--------- .../baselines/reference/APISample_watcher.js | 4 +- .../reference/APISample_watcher.types | 20 ++++----- tests/cases/compiler/APISample_compile.ts | 3 +- tests/cases/compiler/APISample_transform.ts | 3 +- 13 files changed, 91 insertions(+), 97 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e764e20f29f..56aaf75f667 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -98,9 +98,11 @@ module ts { getSourceFiles: () => files, getCompilerOptions: () => options, getCompilerHost: () => host, - getDiagnostics: getDiagnostics, - getGlobalDiagnostics: getGlobalDiagnostics, - getDeclarationDiagnostics: getDeclarationDiagnostics, + getDiagnostics, + getGlobalDiagnostics, + getTypeCheckerDiagnostics, + getTypeCheckerGlobalDiagnostics, + getDeclarationDiagnostics, getTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, emitFiles: invokeEmitter, @@ -115,7 +117,7 @@ module ts { function isEmitBlocked(sourceFile?: SourceFile): boolean { if (options.noEmitOnError) { - return getDiagnostics(sourceFile).length !== 0 || getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile).length !== 0; + return getDiagnostics(sourceFile).length !== 0 || getTypeCheckerDiagnostics(sourceFile).length !== 0; } return false; @@ -151,6 +153,14 @@ module ts { return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; } + function getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + return getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile); + } + + function getTypeCheckerGlobalDiagnostics(): Diagnostic[] { + return getDiagnosticsProducingTypeChecker().getGlobalDiagnostics(); + } + function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] { return sourceFile ? filter(errors, e => e.file === sourceFile) : errors; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ff71bd8a0a0..1f139b093c4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -931,6 +931,10 @@ module ts { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + // These will merge with the below diagnostics function in a followup checkin. + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; + getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; @@ -997,8 +1001,6 @@ module ts { export interface TypeChecker { getEmitResolver(): EmitResolver; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -1028,6 +1030,10 @@ module ts { 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 */ getNodeCount(): number; /* @internal */ getIdentifierCount(): number; /* @internal */ getSymbolCount(): number; diff --git a/src/services/services.ts b/src/services/services.ts index 6a2040543ba..b58376f2c1e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2184,13 +2184,12 @@ module ts { 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); + var allDiagnostics = program.getTypeCheckerDiagnostics(targetSourceFile); if (compilerOptions.declaration) { // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface allDiagnostics = allDiagnostics.concat(program.getDeclarationDiagnostics(targetSourceFile)); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 4131e78284d..9033b832415 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -16,11 +16,10 @@ 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 allDiagnostics = program.getDiagnostics() - .concat(checker.getDiagnostics()) + .concat(program.getTypeCheckerDiagnostics()) .concat(result.diagnostics); allDiagnostics.forEach(diagnostic => { @@ -741,6 +740,8 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; @@ -789,8 +790,6 @@ declare module "typescript" { } interface TypeChecker { getEmitResolver(): EmitResolver; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -1917,9 +1916,8 @@ 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 allDiagnostics = program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(result.diagnostics); allDiagnostics.forEach(function (diagnostic) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText); diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 2b887bd94ab..744ca08b874 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -40,14 +40,6 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >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 ->program : ts.Program - var result = program.emitFiles(); >result : ts.EmitResult >program.emitFiles() : ts.EmitResult @@ -57,21 +49,21 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void var allDiagnostics = program.getDiagnostics() >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(program.getTypeCheckerDiagnostics()) .concat(result.diagnostics) : ts.Diagnostic[] +>program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) : ts.Diagnostic[] >program.getDiagnostics() .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } >program.getDiagnostics() : ts.Diagnostic[] >program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] >program : ts.Program >getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - .concat(checker.getDiagnostics()) + .concat(program.getTypeCheckerDiagnostics()) >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[] +>program.getTypeCheckerDiagnostics() : ts.Diagnostic[] +>program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>program : ts.Program +>getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] .concat(result.diagnostics); >concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } @@ -2261,6 +2253,16 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; +>getTypeCheckerGlobalDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2411,16 +2413,6 @@ declare module "typescript" { >getEmitResolver : () => EmitResolver >EmitResolver : EmitResolver - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getGlobalDiagnostics(): Diagnostic[]; ->getGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index d850585ea37..49519af6f8e 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -770,6 +770,8 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; @@ -818,8 +820,6 @@ declare module "typescript" { } interface TypeChecker { getEmitResolver(): EmitResolver; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index f84338d9d1c..9d5a62f9c66 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2391,6 +2391,16 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; +>getTypeCheckerGlobalDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2541,16 +2551,6 @@ declare module "typescript" { >getEmitResolver : () => EmitResolver >EmitResolver : EmitResolver - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getGlobalDiagnostics(): Diagnostic[]; ->getGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 4c86119f6a0..ec48720eb9c 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -49,8 +49,7 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { // 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(); + errors = program.getTypeCheckerDiagnostics(); // Generate output program.emitFiles(); } @@ -771,6 +770,8 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; @@ -819,8 +820,6 @@ declare module "typescript" { } interface TypeChecker { getEmitResolver(): EmitResolver; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -1974,8 +1973,7 @@ function transform(contents, compilerOptions) { // 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(); + errors = program.getTypeCheckerDiagnostics(); // Generate output program.emitFiles(); } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 2093ec7d8f5..bb9f6823e4c 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -162,20 +162,13 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >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 = program.getTypeCheckerDiagnostics(); +>errors = program.getTypeCheckerDiagnostics() : 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[] +>program.getTypeCheckerDiagnostics() : ts.Diagnostic[] +>program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>program : ts.Program +>getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] // Generate output program.emitFiles(); @@ -2339,6 +2332,16 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; +>getTypeCheckerGlobalDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2489,16 +2492,6 @@ declare module "typescript" { >getEmitResolver : () => EmitResolver >EmitResolver : EmitResolver - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getGlobalDiagnostics(): Diagnostic[]; ->getGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 0e242eaca34..2abce891f35 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -808,6 +808,8 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; @@ -856,8 +858,6 @@ declare module "typescript" { } interface TypeChecker { getEmitResolver(): EmitResolver; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 9255c64511c..949eab3e5eb 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2517,6 +2517,16 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getTypeCheckerGlobalDiagnostics(): Diagnostic[]; +>getTypeCheckerGlobalDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2667,16 +2677,6 @@ declare module "typescript" { >getEmitResolver : () => EmitResolver >EmitResolver : EmitResolver - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getGlobalDiagnostics(): Diagnostic[]; ->getGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 757574c0d7d..5278fb16682 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -16,11 +16,10 @@ 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 allDiagnostics = program.getDiagnostics() - .concat(checker.getDiagnostics()) + .concat(program.getTypeCheckerDiagnostics()) .concat(result.diagnostics); allDiagnostics.forEach(diagnostic => { diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index c3e214b0e37..284e8a4dc5d 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -49,8 +49,7 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { // 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(); + errors = program.getTypeCheckerDiagnostics(); // Generate output program.emitFiles(); } From b6d083fa408fd6db7ca09e5ec94028b580e08ac5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 16:11:38 -0800 Subject: [PATCH 05/26] Do not publicly expose a way on a Program instance to get typecheckers with differing behavior. Now, you can only get the non-diagnostics, pull-type-checker from the Program instance. If you want diagnostics, you simply ask the Program instance for the diagnostics you want. --- src/compiler/program.ts | 16 +- src/compiler/tsc.ts | 11 +- src/compiler/types.ts | 14 +- src/harness/compilerRunner.ts | 35 +- src/harness/harness.ts | 4 +- src/harness/projectsRunner.ts | 3 +- src/harness/typeWriter.ts | 6 +- src/services/services.ts | 10 +- .../baselines/reference/APISample_compile.js | 4 +- .../reference/APISample_compile.types | 13 +- tests/baselines/reference/APISample_linter.js | 4 +- .../reference/APISample_linter.types | 13 +- .../reference/APISample_transform.js | 4 +- .../reference/APISample_transform.types | 13 +- .../baselines/reference/APISample_watcher.js | 4 +- .../reference/APISample_watcher.types | 13 +- .../TypeGuardWithEnumUnion.types.pull | 96 +++ .../aliasUsageInOrExpression.types.pull | 83 +++ .../reference/arrayLiterals.types.pull | 124 ++++ ...tedPropertyNamesContextualType6.types.pull | 40 ++ ...tedPropertyNamesContextualType7.types.pull | 40 ++ ...ontextualSignatureInstantiation.types.pull | 142 ++++ .../heterogeneousArrayLiterals.types.pull | 548 ++++++++++++++++ .../logicalOrOperatorWithEveryType.types.pull | 618 ++++++++++++++++++ ...peGuardsInConditionalExpression.types.pull | 356 ++++++++++ 25 files changed, 2145 insertions(+), 69 deletions(-) create mode 100644 tests/baselines/reference/TypeGuardWithEnumUnion.types.pull create mode 100644 tests/baselines/reference/aliasUsageInOrExpression.types.pull create mode 100644 tests/baselines/reference/arrayLiterals.types.pull create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType6.types.pull create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType7.types.pull create mode 100644 tests/baselines/reference/contextualSignatureInstantiation.types.pull create mode 100644 tests/baselines/reference/heterogeneousArrayLiterals.types.pull create mode 100644 tests/baselines/reference/logicalOrOperatorWithEveryType.types.pull create mode 100644 tests/baselines/reference/typeGuardsInConditionalExpression.types.pull diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 56aaf75f667..ddd9cb4ed3a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -88,7 +88,6 @@ module ts { verifyCompilerOptions(); errors.sort(compareDiagnostics); - var diagnosticsProducingTypeChecker: TypeChecker; var noDiagnosticsTypeChecker: TypeChecker; var emitHost: EmitHost; @@ -104,10 +103,16 @@ module ts { getTypeCheckerGlobalDiagnostics, getDeclarationDiagnostics, getTypeChecker, + getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, emitFiles: invokeEmitter, isEmitBlocked, getCurrentDirectory: host.getCurrentDirectory, + getEmitResolver: () => getDiagnosticsProducingTypeChecker().getEmitResolver(), + getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(), + getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(), + getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), + getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), }; return program; @@ -127,13 +132,8 @@ module ts { 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[]{ diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index cf71869ab14..2c31c008b21 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -336,9 +336,8 @@ module ts { exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; } else { - var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - errors = checker.getDiagnostics(); + errors = program.getTypeCheckerDiagnostics(); if (program.isEmitBlocked()) { exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; } @@ -367,10 +366,10 @@ 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"); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1f139b093c4..58898605959 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -930,6 +930,7 @@ module ts { export interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getEmitResolver(): EmitResolver; // These will merge with the below diagnostics function in a followup checkin. getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -947,11 +948,20 @@ module ts { // // 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 { @@ -1000,7 +1010,6 @@ module ts { } export interface TypeChecker { - getEmitResolver(): EmitResolver; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; @@ -1033,6 +1042,7 @@ module ts { // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; /* @internal */ getGlobalDiagnostics(): Diagnostic[]; + /* @internal */ getEmitResolver(): EmitResolver; /* @internal */ getNodeCount(): number; /* @internal */ getIdentifierCount(): number; 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/harness.ts b/src/harness/harness.ts index 02e14bec954..1b7a7b31dbd 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1081,8 +1081,6 @@ module Harness { (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 @@ -1092,7 +1090,7 @@ module Harness { } var errors: HarnessDiagnostic[] = []; - program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? emitResult.diagnostics : []).forEach(err => { + program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(emitResult ? emitResult.diagnostics : []).forEach(err => { // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now errors.push(getMinimalDiagnostic(err)); }); diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index fac5219f5c1..8daa4a9afdc 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -130,8 +130,7 @@ class ProjectRunner extends RunnerBase { var errors = program.getDiagnostics(); var sourceMapData: ts.SourceMapData[] = null; if (!errors.length) { - var checker = program.getTypeChecker(/*produceDiagnostics:*/ true); - errors = checker.getDiagnostics(); + errors = program.getTypeCheckerDiagnostics(); var emitResult = program.emitFiles(); errors = ts.concatenate(errors, emitResult.diagnostics); sourceMapData = emitResult.sourceMaps; 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 b58376f2c1e..771263919e5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2024,10 +2024,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) { @@ -2076,7 +2072,7 @@ module ts { } program = newProgram; - typeInfoResolver = program.getTypeChecker(/*produceDiagnostics*/ false); + typeInfoResolver = program.getTypeChecker(); return; @@ -2155,7 +2151,7 @@ module ts { */ function cleanupSemanticCache(): void { if (program) { - typeInfoResolver = program.getTypeChecker(/*produceDiagnostics*/ false); + typeInfoResolver = program.getTypeChecker(); } } @@ -4673,7 +4669,7 @@ module ts { var emitHost = createEmitHostFromProgram(program); emitHost.writeFile = writeFile; - var emitOutput = emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(), emitHost, sourceFile); + var emitOutput = emitFiles(program.getEmitResolver(), emitHost, sourceFile); return { outputFiles, diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 9033b832415..fd741d793b4 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -740,12 +740,13 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getEmitResolver(): EmitResolver; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; - getTypeChecker(produceDiagnostics: boolean): TypeChecker; + getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; emitFiles(targetSourceFile?: SourceFile): EmitResult; isEmitBlocked(sourceFile?: SourceFile): boolean; @@ -789,7 +790,6 @@ declare module "typescript" { getSourceFile(fileName: string): SourceFile; } interface TypeChecker { - getEmitResolver(): EmitResolver; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 744ca08b874..5aeb7f096e1 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2253,6 +2253,10 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getEmitResolver(): EmitResolver; +>getEmitResolver : () => EmitResolver +>EmitResolver : EmitResolver + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2279,9 +2283,8 @@ declare module "typescript" { >SourceFile : SourceFile >Diagnostic : Diagnostic - getTypeChecker(produceDiagnostics: boolean): TypeChecker; ->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker ->produceDiagnostics : boolean + getTypeChecker(): TypeChecker; +>getTypeChecker : () => TypeChecker >TypeChecker : TypeChecker getCommonSourceDirectory(): string; @@ -2409,10 +2412,6 @@ declare module "typescript" { interface TypeChecker { >TypeChecker : TypeChecker - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 49519af6f8e..b32f7036038 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -770,12 +770,13 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getEmitResolver(): EmitResolver; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; - getTypeChecker(produceDiagnostics: boolean): TypeChecker; + getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; emitFiles(targetSourceFile?: SourceFile): EmitResult; isEmitBlocked(sourceFile?: SourceFile): boolean; @@ -819,7 +820,6 @@ declare module "typescript" { getSourceFile(fileName: string): SourceFile; } interface TypeChecker { - getEmitResolver(): EmitResolver; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 9d5a62f9c66..386830d2c1c 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2391,6 +2391,10 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getEmitResolver(): EmitResolver; +>getEmitResolver : () => EmitResolver +>EmitResolver : EmitResolver + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2417,9 +2421,8 @@ declare module "typescript" { >SourceFile : SourceFile >Diagnostic : Diagnostic - getTypeChecker(produceDiagnostics: boolean): TypeChecker; ->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker ->produceDiagnostics : boolean + getTypeChecker(): TypeChecker; +>getTypeChecker : () => TypeChecker >TypeChecker : TypeChecker getCommonSourceDirectory(): string; @@ -2547,10 +2550,6 @@ declare module "typescript" { interface TypeChecker { >TypeChecker : TypeChecker - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index ec48720eb9c..cdccf5e83f4 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -770,12 +770,13 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getEmitResolver(): EmitResolver; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; - getTypeChecker(produceDiagnostics: boolean): TypeChecker; + getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; emitFiles(targetSourceFile?: SourceFile): EmitResult; isEmitBlocked(sourceFile?: SourceFile): boolean; @@ -819,7 +820,6 @@ declare module "typescript" { getSourceFile(fileName: string): SourceFile; } interface TypeChecker { - getEmitResolver(): EmitResolver; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index bb9f6823e4c..e689bba7527 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2332,6 +2332,10 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getEmitResolver(): EmitResolver; +>getEmitResolver : () => EmitResolver +>EmitResolver : EmitResolver + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2358,9 +2362,8 @@ declare module "typescript" { >SourceFile : SourceFile >Diagnostic : Diagnostic - getTypeChecker(produceDiagnostics: boolean): TypeChecker; ->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker ->produceDiagnostics : boolean + getTypeChecker(): TypeChecker; +>getTypeChecker : () => TypeChecker >TypeChecker : TypeChecker getCommonSourceDirectory(): string; @@ -2488,10 +2491,6 @@ declare module "typescript" { interface TypeChecker { >TypeChecker : TypeChecker - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 2abce891f35..411cd4f9d51 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -808,12 +808,13 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; + getEmitResolver(): EmitResolver; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; - getTypeChecker(produceDiagnostics: boolean): TypeChecker; + getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; emitFiles(targetSourceFile?: SourceFile): EmitResult; isEmitBlocked(sourceFile?: SourceFile): boolean; @@ -857,7 +858,6 @@ declare module "typescript" { getSourceFile(fileName: string): SourceFile; } interface TypeChecker { - getEmitResolver(): EmitResolver; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 949eab3e5eb..c26d8e241e3 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2517,6 +2517,10 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost + getEmitResolver(): EmitResolver; +>getEmitResolver : () => EmitResolver +>EmitResolver : EmitResolver + getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile @@ -2543,9 +2547,8 @@ declare module "typescript" { >SourceFile : SourceFile >Diagnostic : Diagnostic - getTypeChecker(produceDiagnostics: boolean): TypeChecker; ->getTypeChecker : (produceDiagnostics: boolean) => TypeChecker ->produceDiagnostics : boolean + getTypeChecker(): TypeChecker; +>getTypeChecker : () => TypeChecker >TypeChecker : TypeChecker getCommonSourceDirectory(): string; @@ -2673,10 +2676,6 @@ declare module "typescript" { interface TypeChecker { >TypeChecker : TypeChecker - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; >getTypeOfSymbolAtLocation : (symbol: Symbol, node: Node) => Type >symbol : Symbol 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/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/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/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/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/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 +} From bb307f81639b2bc29a86aef5f92492e38e88ba67 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 16:53:14 -0800 Subject: [PATCH 06/26] Simplify the API for emitting code from the Program instance. --- src/compiler/emitter.ts | 3 +- src/compiler/program.ts | 24 +++++-- src/compiler/tsc.ts | 2 +- src/compiler/types.ts | 24 +++++-- src/compiler/utilities.ts | 17 +---- src/harness/fourslash.ts | 2 +- src/harness/harness.ts | 2 +- src/harness/projectsRunner.ts | 2 +- src/services/services.ts | 7 +- .../baselines/reference/APISample_compile.js | 24 +++++-- .../reference/APISample_compile.types | 64 +++++++++++-------- tests/baselines/reference/APISample_linter.js | 20 ++++-- .../reference/APISample_linter.types | 56 ++++++++++------ .../reference/APISample_transform.js | 24 +++++-- .../reference/APISample_transform.types | 64 +++++++++++-------- .../baselines/reference/APISample_watcher.js | 20 ++++-- .../reference/APISample_watcher.types | 56 ++++++++++------ tests/cases/compiler/APISample_compile.ts | 2 +- tests/cases/compiler/APISample_transform.ts | 2 +- 19 files changed, 263 insertions(+), 152 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a4521977802..cb0b8faab5b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1504,8 +1504,9 @@ module ts { return diagnostics; } + // @internal // 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 { + 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; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ddd9cb4ed3a..a6ed7fb51ab 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -90,7 +90,6 @@ module ts { var diagnosticsProducingTypeChecker: TypeChecker; var noDiagnosticsTypeChecker: TypeChecker; - var emitHost: EmitHost; program = { getSourceFile: getSourceFile, @@ -105,7 +104,7 @@ module ts { getTypeChecker, getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, - emitFiles: invokeEmitter, + emit, isEmitBlocked, getCurrentDirectory: host.getCurrentDirectory, getEmitResolver: () => getDiagnosticsProducingTypeChecker().getEmitResolver(), @@ -116,10 +115,22 @@ module ts { }; return program; - function getEmitHost() { - return emitHost || (emitHost = createEmitHostFromProgram(program)); + function getEmitHost(writeFileCallback?: WriteFileCallback) { + 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: writeFileCallback || compilerHost.writeFile, + }; } + function isEmitBlocked(sourceFile?: SourceFile): boolean { if (options.noEmitOnError) { return getDiagnostics(sourceFile).length !== 0 || getTypeCheckerDiagnostics(sourceFile).length !== 0; @@ -143,9 +154,10 @@ module ts { return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); } - function invokeEmitter(targetSourceFile?: SourceFile) { + function emit(targetSourceFile?: SourceFile, writeFileCallback?: WriteFileCallback) { var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); - return emitFiles(resolver, getEmitHost(), targetSourceFile); + var host = getEmitHost(writeFileCallback); + return emitFiles(resolver, host, targetSourceFile); } function getSourceFile(fileName: string) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2c31c008b21..05f2305acf7 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -346,7 +346,7 @@ module ts { } else { var emitStart = new Date().getTime(); - var emitOutput = program.emitFiles(); + var emitOutput = program.emit(); var emitErrors = emitOutput.diagnostics; exitStatus = emitOutput.emitResultStatus; var reportStart = new Date().getTime(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 58898605959..b04a5944bfc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -927,10 +927,27 @@ module ts { getCurrentDirectory(): string; } + export interface WriteFileCallback { + (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } + export interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; getCompilerHost(): CompilerHost; - getEmitResolver(): EmitResolver; + + /** + * 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 getCompilerHost() 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; + + isEmitBlocked(sourceFile?: SourceFile): boolean; // These will merge with the below diagnostics function in a followup checkin. getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -951,9 +968,6 @@ module ts { 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; @@ -1671,7 +1685,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; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 69c64ba4880..9df23b22dd0 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -31,7 +31,7 @@ module ts { 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. @@ -843,21 +843,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 } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b3c9c118e97..dd55e702d09 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2216,7 +2216,7 @@ module FourSlash { if (errors.length > 0) { throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => e.messageText).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 1b7a7b31dbd..7b68ac80efa 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1086,7 +1086,7 @@ module Harness { // only emit if there weren't parse errors var emitResult: ts.EmitResult; if (!isEmitBlocked) { - emitResult = program.emitFiles(); + emitResult = program.emit(); } var errors: HarnessDiagnostic[] = []; diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 8daa4a9afdc..327ebc3520e 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -131,7 +131,7 @@ class ProjectRunner extends RunnerBase { var sourceMapData: ts.SourceMapData[] = null; if (!errors.length) { errors = program.getTypeCheckerDiagnostics(); - var emitResult = program.emitFiles(); + var emitResult = program.emit(); errors = ts.concatenate(errors, emitResult.diagnostics); sourceMapData = emitResult.sourceMaps; diff --git a/src/services/services.ts b/src/services/services.ts index 771263919e5..7311e5f7596 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4664,12 +4664,7 @@ 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(program.getEmitResolver(), emitHost, sourceFile); + var emitOutput = program.emit(sourceFile, writeFile); return { outputFiles, diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index fd741d793b4..c20c601823f 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -16,7 +16,7 @@ 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 result = program.emitFiles(); + var result = program.emit(); var allDiagnostics = program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) @@ -737,10 +737,24 @@ 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; - getEmitResolver(): EmitResolver; + /** + * 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 getCompilerHost() 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; + isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -748,8 +762,6 @@ declare module "typescript" { getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; - emitFiles(targetSourceFile?: SourceFile): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -1338,7 +1350,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; @@ -1916,7 +1928,7 @@ var ts = require("typescript"); function compile(fileNames, options) { var host = ts.createCompilerHost(options); var program = ts.createProgram(fileNames, options, host); - var result = program.emitFiles(); + var result = program.emit(); var allDiagnostics = program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(result.diagnostics); allDiagnostics.forEach(function (diagnostic) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 5aeb7f096e1..469dc8098aa 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -40,12 +40,12 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >options : ts.CompilerOptions >host : ts.CompilerHost - var result = program.emitFiles(); + var result = program.emit(); >result : ts.EmitResult ->program.emitFiles() : ts.EmitResult ->program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult +>program.emit() : ts.EmitResult +>program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program ->emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult +>emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult var allDiagnostics = program.getDiagnostics() >allDiagnostics : ts.Diagnostic[] @@ -2240,6 +2240,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 @@ -2253,9 +2263,28 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver + /** + * 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 getCompilerHost() 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 + + isEmitBlocked(sourceFile?: SourceFile): boolean; +>isEmitBlocked : (sourceFile?: SourceFile) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] @@ -2289,17 +2318,6 @@ declare module "typescript" { 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 @@ -4255,13 +4273,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 diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b32f7036038..eed54d13542 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -767,10 +767,24 @@ 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; - getEmitResolver(): EmitResolver; + /** + * 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 getCompilerHost() 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; + isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -778,8 +792,6 @@ declare module "typescript" { getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; - emitFiles(targetSourceFile?: SourceFile): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -1368,7 +1380,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; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 386830d2c1c..3af13c6b068 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 @@ -2391,9 +2401,28 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver + /** + * 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 getCompilerHost() 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 + + isEmitBlocked(sourceFile?: SourceFile): boolean; +>isEmitBlocked : (sourceFile?: SourceFile) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] @@ -2427,17 +2456,6 @@ declare module "typescript" { 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 @@ -4393,13 +4411,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 diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index cdccf5e83f4..59976015fb4 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -51,7 +51,7 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { // Type check and get semantic errors errors = program.getTypeCheckerDiagnostics(); // Generate output - program.emitFiles(); + program.emit(); } return { outputs: outputs, @@ -767,10 +767,24 @@ 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; - getEmitResolver(): EmitResolver; + /** + * 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 getCompilerHost() 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; + isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -778,8 +792,6 @@ declare module "typescript" { getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; - emitFiles(targetSourceFile?: SourceFile): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -1368,7 +1380,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; @@ -1975,7 +1987,7 @@ function transform(contents, compilerOptions) { // Type check and get semantic errors errors = program.getTypeCheckerDiagnostics(); // Generate output - program.emitFiles(); + program.emit(); } return { outputs: outputs, diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index e689bba7527..e4f0e56910a 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -171,11 +171,11 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] // Generate output - program.emitFiles(); ->program.emitFiles() : ts.EmitResult ->program.emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult + program.emit(); +>program.emit() : ts.EmitResult +>program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program ->emitFiles : (targetSourceFile?: ts.SourceFile) => ts.EmitResult +>emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => 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[]; } @@ -2319,6 +2319,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 @@ -2332,9 +2342,28 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver + /** + * 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 getCompilerHost() 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 + + isEmitBlocked(sourceFile?: SourceFile): boolean; +>isEmitBlocked : (sourceFile?: SourceFile) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] @@ -2368,17 +2397,6 @@ declare module "typescript" { 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 @@ -4334,13 +4352,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 diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 411cd4f9d51..5879903340d 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -805,10 +805,24 @@ 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; - getEmitResolver(): EmitResolver; + /** + * 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 getCompilerHost() 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; + isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -816,8 +830,6 @@ declare module "typescript" { getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; - emitFiles(targetSourceFile?: SourceFile): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; } interface SourceMapSpan { emittedLine: number; @@ -1406,7 +1418,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; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index c26d8e241e3..67eff31dfb8 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2504,6 +2504,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 @@ -2517,9 +2527,28 @@ declare module "typescript" { >getCompilerHost : () => CompilerHost >CompilerHost : CompilerHost - getEmitResolver(): EmitResolver; ->getEmitResolver : () => EmitResolver ->EmitResolver : EmitResolver + /** + * 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 getCompilerHost() 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 + + isEmitBlocked(sourceFile?: SourceFile): boolean; +>isEmitBlocked : (sourceFile?: SourceFile) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] @@ -2553,17 +2582,6 @@ declare module "typescript" { 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 @@ -4519,13 +4537,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 diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 5278fb16682..af1eb9e0462 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -16,7 +16,7 @@ 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 result = program.emitFiles(); + var result = program.emit(); var allDiagnostics = program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index 284e8a4dc5d..eccdb1ccecc 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -51,7 +51,7 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { // Type check and get semantic errors errors = program.getTypeCheckerDiagnostics(); // Generate output - program.emitFiles(); + program.emit(); } return { outputs: outputs, From 2a1d78d9e374f9460b253feceaddf30955cc194e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 17:02:26 -0800 Subject: [PATCH 07/26] Simplify the createProgram API. Allow the host parameter to be optional to simplify command line programs. --- src/compiler/program.ts | 3 ++- .../baselines/reference/APISample_compile.js | 8 +++---- .../reference/APISample_compile.types | 21 ++++++------------- tests/baselines/reference/APISample_linter.js | 2 +- .../reference/APISample_linter.types | 4 ++-- .../reference/APISample_transform.js | 2 +- .../reference/APISample_transform.types | 8 +++---- .../baselines/reference/APISample_watcher.js | 2 +- .../reference/APISample_watcher.types | 4 ++-- tests/cases/compiler/APISample_compile.ts | 3 +-- 10 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a6ed7fb51ab..6976195cc04 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -73,13 +73,14 @@ module ts { }; } - export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { + export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; var filesByName: Map = {}; var errors: Diagnostic[] = []; var seenNoDefaultLib = options.noLib; var commonSourceDirectory: string; + host = host || createCompilerHost(options); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index c20c601823f..6df54cc1b64 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -14,8 +14,7 @@ declare var console: 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 program = ts.createProgram(fileNames, options); var result = program.emit(); var allDiagnostics = program.getDiagnostics() @@ -1426,7 +1425,7 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { var servicesVersion: string; @@ -1926,8 +1925,7 @@ declare module "typescript" { */ var ts = require("typescript"); function compile(fileNames, options) { - var host = ts.createCompilerHost(options); - var program = ts.createProgram(fileNames, options, host); + var program = ts.createProgram(fileNames, options); var result = program.emit(); var allDiagnostics = program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(result.diagnostics); allDiagnostics.forEach(function (diagnostic) { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 469dc8098aa..cc07d75b0c6 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -22,23 +22,14 @@ 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 result = program.emit(); >result : ts.EmitResult @@ -4577,8 +4568,8 @@ 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 createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; +>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] >options : CompilerOptions >CompilerOptions : CompilerOptions diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index eed54d13542..1cf0ea77098 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1456,7 +1456,7 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { var servicesVersion: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 3af13c6b068..922a9ebea8e 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4715,8 +4715,8 @@ 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 createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; +>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] >options : CompilerOptions >CompilerOptions : CompilerOptions diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 59976015fb4..8d0352ed170 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1456,7 +1456,7 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { var servicesVersion: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index e4f0e56910a..8c81d46e5bc 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -139,9 +139,9 @@ 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; } @@ -4656,8 +4656,8 @@ 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 createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; +>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] >options : CompilerOptions >CompilerOptions : CompilerOptions diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 5879903340d..a4216e78ecd 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1494,7 +1494,7 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; - function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { var servicesVersion: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 67eff31dfb8..95f87b4978b 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4841,8 +4841,8 @@ 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 createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; +>createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] >options : CompilerOptions >CompilerOptions : CompilerOptions diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index af1eb9e0462..4731f856e2a 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -14,8 +14,7 @@ declare var console: 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 program = ts.createProgram(fileNames, options); var result = program.emit(); var allDiagnostics = program.getDiagnostics() From 476c8249ac91e298c881a33f772f14833abafa75 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 17:48:29 -0800 Subject: [PATCH 08/26] Remove 'isEmitBlocked' from the program API. If emitting is blocked, then calling .emit on the program will simply return immediately with an appropriate reason given in the EmitResult. --- src/compiler/emitter.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/tsc.ts | 5 +---- src/compiler/types.ts | 2 -- src/harness/harness.ts | 12 +++--------- tests/baselines/reference/APISample_compile.js | 1 - tests/baselines/reference/APISample_compile.types | 5 ----- tests/baselines/reference/APISample_linter.js | 1 - tests/baselines/reference/APISample_linter.types | 5 ----- tests/baselines/reference/APISample_transform.js | 1 - tests/baselines/reference/APISample_transform.types | 5 ----- tests/baselines/reference/APISample_watcher.js | 1 - tests/baselines/reference/APISample_watcher.types | 5 ----- 13 files changed, 6 insertions(+), 41 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cb0b8faab5b..9b080fa4c39 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4471,7 +4471,7 @@ module ts { return { emitResultStatus, diagnostics, - sourceMaps: sourceMapDataList + sourceMaps: isEmitBlocked ? undefined : sourceMapDataList }; } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6976195cc04..0c1d5a24daf 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -126,7 +126,7 @@ module ts { getNewLine: compilerHost.getNewLine, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - isEmitBlocked: program.isEmitBlocked, + isEmitBlocked, writeFile: writeFileCallback || compilerHost.writeFile, }; } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 05f2305acf7..1491c90e979 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -338,10 +338,7 @@ module ts { else { var checkStart = new Date().getTime(); errors = program.getTypeCheckerDiagnostics(); - if (program.isEmitBlocked()) { - exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; - } - else if (compilerOptions.noEmit) { + if (compilerOptions.noEmit) { exitStatus = EmitReturnStatus.Succeeded; } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b04a5944bfc..69735803e2b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -947,8 +947,6 @@ module ts { */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; - // These will merge with the below diagnostics function in a followup checkin. getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 7b68ac80efa..a7d107c66d5 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1081,22 +1081,16 @@ module Harness { (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), options.target, useCaseSensitiveFileNames, currentDirectory)); - var isEmitBlocked = program.isEmitBlocked(); - - // only emit if there weren't parse errors - var emitResult: ts.EmitResult; - if (!isEmitBlocked) { - emitResult = program.emit(); - } + var emitResult = program.emit(); var errors: HarnessDiagnostic[] = []; - program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(emitResult ? emitResult.diagnostics : []).forEach(err => { + program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).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 diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 6df54cc1b64..f057f673607 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -753,7 +753,6 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index cc07d75b0c6..00a34474041 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2272,11 +2272,6 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - isEmitBlocked(sourceFile?: SourceFile): boolean; ->isEmitBlocked : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 1cf0ea77098..bc4b118891a 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -784,7 +784,6 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 922a9ebea8e..3fbd07f08d8 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2419,11 +2419,6 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - isEmitBlocked(sourceFile?: SourceFile): boolean; ->isEmitBlocked : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 8d0352ed170..4b50058a855 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -784,7 +784,6 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 8c81d46e5bc..3882bd50445 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2360,11 +2360,6 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - isEmitBlocked(sourceFile?: SourceFile): boolean; ->isEmitBlocked : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index a4216e78ecd..5f99e7beefb 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -822,7 +822,6 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - isEmitBlocked(sourceFile?: SourceFile): boolean; getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeCheckerGlobalDiagnostics(): Diagnostic[]; getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 95f87b4978b..dadd3a08cea 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2545,11 +2545,6 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - isEmitBlocked(sourceFile?: SourceFile): boolean; ->isEmitBlocked : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; >getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile From d8a7e376f1040f2e4abc7f0939f4ce1998928380 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 17:58:19 -0800 Subject: [PATCH 09/26] Update comment. --- src/compiler/types.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 69735803e2b..60d19b4a5d3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -956,14 +956,8 @@ module ts { 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(): TypeChecker; + getCommonSourceDirectory(): string; // For testing purposes only. Should not be used by any other consumers (including the From 3cadb3c30ca686414f8e35af6644c202876377e2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 18:12:13 -0800 Subject: [PATCH 10/26] Use a diagnostics collection inside the program instance. --- src/compiler/program.ts | 35 +++++++++---------- .../amd/invalidRootFile.errors.txt | 2 -- .../node/invalidRootFile.errors.txt | 2 -- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0c1d5a24daf..34f044b8ebe 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -77,7 +77,7 @@ module ts { 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); @@ -87,7 +87,6 @@ module ts { processRootFile(host.getDefaultLibFileName(options), true); } verifyCompilerOptions(); - errors.sort(compareDiagnostics); var diagnosticsProducingTypeChecker: TypeChecker; var noDiagnosticsTypeChecker: TypeChecker; @@ -174,12 +173,12 @@ module ts { return getDiagnosticsProducingTypeChecker().getGlobalDiagnostics(); } - function getDiagnostics(sourceFile?: SourceFile): Diagnostic[] { - return sourceFile ? filter(errors, e => e.file === sourceFile) : errors; + function getDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ + return sourceFile ? diagnostics.getDiagnostics(sourceFile.fileName) : diagnostics.getDiagnostics(); } - function getGlobalDiagnostics(): Diagnostic[] { - return filter(errors, e => !e.file); + function getGlobalDiagnostics(): Diagnostic[]{ + return diagnostics.getGlobalDiagnostics(); } function hasExtension(fileName: string): boolean { @@ -219,10 +218,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)); } } } @@ -244,11 +243,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) { @@ -269,7 +268,7 @@ module ts { files.push(file); } forEach(getSyntacticDiagnostics(file), e => { - errors.push(e); + diagnostics.add(e); }); } } @@ -280,7 +279,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)); } } @@ -354,10 +353,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; } @@ -368,7 +367,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 @@ -389,7 +388,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; } @@ -422,11 +421,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/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 From 28c1a23e7c570975124b5fa62ff9d0a23812f944 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 18:42:44 -0800 Subject: [PATCH 11/26] Track performance statistics in the ts module. This allows us to greatly simplify the compile function in tsc. --- src/compiler/binder.ts | 9 ++++++++- src/compiler/checker.ts | 10 +++++++++- src/compiler/parser.ts | 8 +++++++- src/compiler/program.ts | 9 ++++++++- src/compiler/tsc.ts | 30 +++++++++++++++--------------- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a8055d993a1..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; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05e60ddcd46..945dc4d7a2a 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(); @@ -9537,8 +9539,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 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e563291f762..4f23e2f30a7 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)); @@ -856,8 +857,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 { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 34f044b8ebe..c28ca61e548 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 = {}; @@ -155,9 +157,14 @@ module ts { } function emit(targetSourceFile?: SourceFile, writeFileCallback?: WriteFileCallback) { + var start = new Date().getTime(); + var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); var host = getEmitHost(writeFileCallback); - return emitFiles(resolver, host, targetSourceFile); + var result = emitFiles(resolver, host, targetSourceFile); + + emitTime += new Date().getTime() - start; + return result; } function getSourceFile(fileName: string) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 1491c90e979..e4a9f92164d 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -322,35 +322,33 @@ 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 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 checkStart = new Date().getTime(); errors = program.getTypeCheckerDiagnostics(); if (compilerOptions.noEmit) { exitStatus = EmitReturnStatus.Succeeded; } else { - var emitStart = new Date().getTime(); var emitOutput = program.emit(); - var emitErrors = emitOutput.diagnostics; exitStatus = emitOutput.emitResultStatus; - var reportStart = new Date().getTime(); - errors = concatenate(errors, emitErrors); + errors = concatenate(errors, emitOutput.diagnostics); } } + var end = start - new Date().getTime(); reportDiagnostics(errors); if (compilerOptions.listFiles) { @@ -367,14 +365,16 @@ module ts { 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 }; From de308664604cd50e8f1690a60ec33eadd27fafbd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 22:26:03 -0800 Subject: [PATCH 12/26] Simplify the code for actually compiling within tsc. --- src/compiler/tsc.ts | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e4a9f92164d..f0dcb872950 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -328,28 +328,11 @@ module ts { ts.emitTime = 0; var start = new Date().getTime(); + var program = createProgram(fileNames, compilerOptions, compilerHost); - - var errors: Diagnostic[] = program.getDiagnostics(); - var exitStatus: EmitReturnStatus; - - if (errors.length) { - exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; - } - else { - errors = program.getTypeCheckerDiagnostics(); - if (compilerOptions.noEmit) { - exitStatus = EmitReturnStatus.Succeeded; - } - else { - var emitOutput = program.emit(); - exitStatus = emitOutput.emitResultStatus; - errors = concatenate(errors, emitOutput.diagnostics); - } - } + var exitStatus = compileProgram(); var end = start - new Date().getTime(); - reportDiagnostics(errors); if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { @@ -378,6 +361,29 @@ module ts { } return { program, exitStatus }; + + function compileProgram(): EmitReturnStatus { + // First get any syntactic errors. + var errors = program.getDiagnostics(); + reportDiagnostics(errors); + + // If we didn't have any syntactic errors, then also try getting the semantic errors. + if (errors.length === 0) { + var errors = program.getTypeCheckerDiagnostics(); + reportDiagnostics(errors); + } + + // If the user doesn't want us to emit, then we're done at this point. + if (compilerOptions.noEmit) { + return EmitReturnStatus.Succeeded; + } + + // Otherwise, emit and report any errors we ran into. + var emitOutput = program.emit(); + reportDiagnostics(emitOutput.diagnostics); + + return emitOutput.emitResultStatus; + } } function printVersion() { From b12be3db1909164642f7dd04d5b78a4aa0efd489 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 23:20:26 -0800 Subject: [PATCH 13/26] Remove dependency from the typechecker to the compiler host. This also lets us not expose the compiler host from the Program instance. The compiler host was only needed by the type checker to get the host newline. The host newline was used for concatenating diagnostic message chains. Now we don't concatenate them up front. Instead, we just store the message chain in the diagnostic itself. Then when we pass it to the host, it can then decide what newline to use. --- src/compiler/checker.ts | 4 +- src/compiler/core.ts | 58 ++++++++----------- src/compiler/program.ts | 16 +++-- src/compiler/tsc.ts | 6 +- src/compiler/types.ts | 6 +- src/compiler/utilities.ts | 37 +++++++++++- src/harness/fourslash.ts | 11 +++- src/harness/harness.ts | 8 ++- src/harness/harnessLanguageService.ts | 4 ++ src/harness/projectsRunner.ts | 4 +- src/services/shims.ts | 15 +++-- .../baselines/reference/APISample_compile.js | 6 +- .../reference/APISample_compile.types | 19 ++---- tests/baselines/reference/APISample_linter.js | 6 +- .../reference/APISample_linter.types | 15 ++--- .../reference/APISample_transform.js | 6 +- .../reference/APISample_transform.types | 19 ++---- .../baselines/reference/APISample_watcher.js | 6 +- .../reference/APISample_watcher.types | 23 +++----- 19 files changed, 135 insertions(+), 134 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 945dc4d7a2a..50dcbd21fdc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3476,7 +3476,7 @@ module ts { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } - diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, host.getCompilerHost().getNewLine())); + diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo)); } return result !== Ternary.False; @@ -8924,7 +8924,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); - diagnostics.add(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, host.getCompilerHost().getNewLine())); + diagnostics.add(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo)); } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 87094150baf..9b852a37ff6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -325,38 +325,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; @@ -373,10 +341,34 @@ module ts { compareValues(d1.start, d2.start) || compareValues(d1.length, d2.length) || compareValues(d1.code, d2.code) || - compareValues(d1.messageText, d2.messageText) || + compareMessageText(d1.messageText, d2.messageText) || 0; } + function compareMessageText(text1: string | DiagnosticMessageChain, text2: string | DiagnosticMessageChain): number { + 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 0; + } + + // We still have one chain remaining. The shorter chain should come first. + return text1 ? 1 : -1; + } + export function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { if (diagnostics.length < 2) { return diagnostics; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c28ca61e548..85181b2aa55 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -23,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 = ""; } @@ -97,7 +97,6 @@ module ts { getSourceFile: getSourceFile, getSourceFiles: () => files, getCompilerOptions: () => options, - getCompilerHost: () => host, getDiagnostics, getGlobalDiagnostics, getTypeCheckerDiagnostics, @@ -118,17 +117,16 @@ module ts { return program; function getEmitHost(writeFileCallback?: WriteFileCallback) { - var compilerHost = program.getCompilerHost(); return { - getCanonicalFileName: compilerHost.getCanonicalFileName, + getCanonicalFileName: host.getCanonicalFileName, getCommonSourceDirectory: program.getCommonSourceDirectory, getCompilerOptions: program.getCompilerOptions, - getCurrentDirectory: compilerHost.getCurrentDirectory, - getNewLine: compilerHost.getNewLine, + getCurrentDirectory: host.getCurrentDirectory, + getNewLine: host.getNewLine, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, isEmitBlocked, - writeFile: writeFileCallback || compilerHost.writeFile, + writeFile: writeFileCallback || host.writeFile, }; } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index f0dcb872950..15f97e028fc 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); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 60d19b4a5d3..467d9b6cc90 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -933,7 +933,6 @@ module ts { export interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - getCompilerHost(): CompilerHost; /** * Emits the javascript and declaration files. If targetSourceFile is not specified, then @@ -941,7 +940,7 @@ module ts { * 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 getCompilerHost() will be + * 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. */ @@ -1009,7 +1008,6 @@ module ts { export interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getCompilerHost(): CompilerHost; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; @@ -1451,7 +1449,7 @@ module ts { file: SourceFile; start: number; length: number; - messageText: string; + messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; code: number; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9df23b22dd0..4204acc4716 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -199,12 +199,45 @@ 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 + }; + } + + export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { + if (typeof messageText === "string") { + return messageText; + } + else { + var diagnosticChain = messageText; + var result = ""; + + var indent = 0; + while (diagnosticChain) { + if (indent) { + result += newLine; + + for (var i = 0; i < indent; i++) { + result += " "; + } + } + result += diagnosticChain.messageText; + indent++; + diagnosticChain = diagnosticChain.next; + } + + return result; + } } export function getErrorSpanForNode(node: Node): Node { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index dd55e702d09..5e046c070ab 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"); }); } @@ -1179,7 +1181,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)); }); } } @@ -2214,7 +2219,7 @@ module FourSlash { 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')); + throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); } program.emit(); result = result || ''; // Might have an empty fourslash file diff --git a/src/harness/harness.ts b/src/harness/harness.ts index a7d107c66d5..84aaf66be3d 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"); } @@ -1182,7 +1184,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 327ebc3520e..53ce8e507a0 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -275,14 +275,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/services/shims.ts b/src/services/shims.ts index c5b2b24108d..8b7a48d03f3 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,9 @@ module ts { }); } - private static realizeDiagnostic(diagnostic: Diagnostic): { message: string; start: number; length: number; category: string; } { + 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 +397,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); + return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()); }); } @@ -410,7 +415,7 @@ module ts { "getSemanticDiagnostics('" + fileName + "')", () => { var errors = this.languageService.getSemanticDiagnostics(fileName); - return errors.map(LanguageServiceShimObject.realizeDiagnostic); + return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()); }); } @@ -419,7 +424,7 @@ module ts { "getCompilerOptionsDiagnostics()", () => { var errors = this.languageService.getCompilerOptionsDiagnostics(); - return errors.map(LanguageServiceShimObject.realizeDiagnostic) + return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()) }); } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index f057f673607..db4f29683d2 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -741,14 +741,13 @@ declare module "typescript" { } interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - getCompilerHost(): 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 getCompilerHost() will be + * 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. */ @@ -795,7 +794,6 @@ declare module "typescript" { } interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getCompilerHost(): CompilerHost; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; } @@ -1144,7 +1142,7 @@ declare module "typescript" { file: SourceFile; start: number; length: number; - messageText: string; + messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; code: number; } diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 00a34474041..5124312b6d3 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -98,9 +98,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >lineChar.character : number >lineChar : ts.LineAndCharacter >character : number ->diagnostic.messageText : string +>diagnostic.messageText : string | ts.DiagnosticMessageChain >diagnostic : ts.Diagnostic ->messageText : string +>messageText : string | ts.DiagnosticMessageChain }); @@ -2250,17 +2250,13 @@ 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 getCompilerHost() will be + * 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. */ @@ -2400,10 +2396,6 @@ declare module "typescript" { >getCompilerOptions : () => CompilerOptions >CompilerOptions : CompilerOptions - getCompilerHost(): CompilerHost; ->getCompilerHost : () => CompilerHost ->CompilerHost : CompilerHost - getSourceFiles(): SourceFile[]; >getSourceFiles : () => SourceFile[] >SourceFile : SourceFile @@ -3659,8 +3651,9 @@ declare module "typescript" { length: number; >length : number - messageText: string; ->messageText : string + messageText: string | DiagnosticMessageChain; +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain category: DiagnosticCategory; >category : DiagnosticCategory diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index bc4b118891a..646d0e47a4e 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -772,14 +772,13 @@ declare module "typescript" { } interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - getCompilerHost(): 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 getCompilerHost() will be + * 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. */ @@ -826,7 +825,6 @@ declare module "typescript" { } interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getCompilerHost(): CompilerHost; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; } @@ -1175,7 +1173,7 @@ declare module "typescript" { file: SourceFile; start: number; length: number; - messageText: string; + messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; code: number; } diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 3fbd07f08d8..1e917893832 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2397,17 +2397,13 @@ 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 getCompilerHost() will be + * 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. */ @@ -2547,10 +2543,6 @@ declare module "typescript" { >getCompilerOptions : () => CompilerOptions >CompilerOptions : CompilerOptions - getCompilerHost(): CompilerHost; ->getCompilerHost : () => CompilerHost ->CompilerHost : CompilerHost - getSourceFiles(): SourceFile[]; >getSourceFiles : () => SourceFile[] >SourceFile : SourceFile @@ -3806,8 +3798,9 @@ declare module "typescript" { length: number; >length : number - messageText: string; ->messageText : string + messageText: string | DiagnosticMessageChain; +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain category: DiagnosticCategory; >category : DiagnosticCategory diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 4b50058a855..280c5202db3 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -772,14 +772,13 @@ declare module "typescript" { } interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - getCompilerHost(): 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 getCompilerHost() will be + * 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. */ @@ -826,7 +825,6 @@ declare module "typescript" { } interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getCompilerHost(): CompilerHost; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; } @@ -1175,7 +1173,7 @@ declare module "typescript" { file: SourceFile; start: number; length: number; - messageText: string; + messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; code: number; } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 3882bd50445..c8b7e10fa89 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -212,9 +212,9 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >e : ts.Diagnostic >start : number >line : number ->e.messageText : string +>e.messageText : string | ts.DiagnosticMessageChain >e : ts.Diagnostic ->messageText : string +>messageText : string | ts.DiagnosticMessageChain }; } @@ -2338,17 +2338,13 @@ 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 getCompilerHost() will be + * 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. */ @@ -2488,10 +2484,6 @@ declare module "typescript" { >getCompilerOptions : () => CompilerOptions >CompilerOptions : CompilerOptions - getCompilerHost(): CompilerHost; ->getCompilerHost : () => CompilerHost ->CompilerHost : CompilerHost - getSourceFiles(): SourceFile[]; >getSourceFiles : () => SourceFile[] >SourceFile : SourceFile @@ -3747,8 +3739,9 @@ declare module "typescript" { length: number; >length : number - messageText: string; ->messageText : string + messageText: string | DiagnosticMessageChain; +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain category: DiagnosticCategory; >category : DiagnosticCategory diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 5f99e7beefb..89f3bc43d37 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -810,14 +810,13 @@ declare module "typescript" { } interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - getCompilerHost(): 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 getCompilerHost() will be + * 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. */ @@ -864,7 +863,6 @@ declare module "typescript" { } interface TypeCheckerHost { getCompilerOptions(): CompilerOptions; - getCompilerHost(): CompilerHost; getSourceFiles(): SourceFile[]; getSourceFile(fileName: string): SourceFile; } @@ -1213,7 +1211,7 @@ declare module "typescript" { file: SourceFile; start: number; length: number; - messageText: string; + messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; code: number; } diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index dadd3a08cea..f286fe18eb2 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -362,9 +362,9 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) { >lineChar.character : number >lineChar : ts.LineAndCharacter >character : number ->diagnostic.messageText : string +>diagnostic.messageText : string | ts.DiagnosticMessageChain >diagnostic : ts.Diagnostic ->messageText : string +>messageText : string | ts.DiagnosticMessageChain } else { console.log(` Error: ${diagnostic.messageText}`); @@ -372,9 +372,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 } }); } @@ -2523,17 +2523,13 @@ 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 getCompilerHost() will be + * 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. */ @@ -2673,10 +2669,6 @@ declare module "typescript" { >getCompilerOptions : () => CompilerOptions >CompilerOptions : CompilerOptions - getCompilerHost(): CompilerHost; ->getCompilerHost : () => CompilerHost ->CompilerHost : CompilerHost - getSourceFiles(): SourceFile[]; >getSourceFiles : () => SourceFile[] >SourceFile : SourceFile @@ -3932,8 +3924,9 @@ declare module "typescript" { length: number; >length : number - messageText: string; ->messageText : string + messageText: string | DiagnosticMessageChain; +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain category: DiagnosticCategory; >category : DiagnosticCategory From 337a99f62af832dcb7e232952a7b44d27dd9c3fe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 01:47:29 -0800 Subject: [PATCH 14/26] Change the API for getting diagnostics so that all calls go through a Program instance. --- src/compiler/checker.ts | 9 +- src/compiler/core.ts | 10 ++ src/compiler/emitter.ts | 23 ++-- src/compiler/parser.ts | 2 +- src/compiler/program.ts | 105 ++++++++++++--- src/compiler/tsc.ts | 12 +- src/compiler/types.ts | 36 ++++-- src/compiler/utilities.ts | 40 +----- src/harness/fourslash.ts | 25 ++-- src/harness/harness.ts | 3 +- src/harness/projectsRunner.ts | 27 ++-- src/services/services.ts | 15 ++- .../baselines/reference/APISample_compile.js | 39 +++--- .../reference/APISample_compile.types | 119 ++++++++--------- tests/baselines/reference/APISample_linter.js | 16 +-- .../reference/APISample_linter.types | 53 ++++---- .../reference/APISample_transform.js | 48 ++++--- .../reference/APISample_transform.types | 120 ++++++++++-------- .../baselines/reference/APISample_watcher.js | 16 +-- .../reference/APISample_watcher.types | 53 ++++---- .../declarationEmit_invalidReference2.js | 4 - ...etEmitOutputDeclarationMultiFiles.baseline | 16 +-- ...etEmitOutputDeclarationSingleFile.baseline | 8 +- .../getEmitOutputExternalModule.baseline | 6 +- .../getEmitOutputExternalModule2.baseline | 9 +- .../reference/getEmitOutputMapRoots.baseline | 8 +- .../reference/getEmitOutputNoErrors.baseline | 6 +- .../getEmitOutputOnlyOneFile.baseline | 6 +- .../getEmitOutputSingleFile.baseline | 6 +- .../getEmitOutputSingleFile2.baseline | 8 +- .../reference/getEmitOutputSourceMap.baseline | 8 +- .../getEmitOutputSourceMap2.baseline | 16 +-- .../getEmitOutputSourceRoot.baseline | 8 +- ...getEmitOutputSourceRootMultiFiles.baseline | 16 +-- .../getEmitOutputWithDeclarationFile.baseline | 10 +- ...getEmitOutputWithDeclarationFile2.baseline | 16 +-- ...getEmitOutputWithDeclarationFile3.baseline | 6 +- ...mitOutputWithEarlySyntacticErrors.baseline | 9 +- .../getEmitOutputWithEmitterErrors.baseline | 7 +- .../getEmitOutputWithEmitterErrors2.baseline | 7 +- .../getEmitOutputWithSemanticErrors.baseline | 8 +- .../getEmitOutputWithSemanticErrors2.baseline | 8 +- ...ithSemanticErrorsForMultipleFiles.baseline | 8 +- ...thSemanticErrorsForMultipleFiles2.baseline | 8 +- ...thSyntacticErrorsForMultipleFiles.baseline | 6 +- ...hSyntacticErrorsForMultipleFiles2.baseline | 8 +- .../getEmitOutputWithSyntaxErrors.baseline | 8 +- ...apRootSourceRootWithNoSourceMapOption.json | 5 +- ...apRootSourceRootWithNoSourceMapOption.json | 5 +- .../amd/mapRootWithNoSourceMapOption.json | 5 +- .../node/mapRootWithNoSourceMapOption.json | 5 +- .../amd/sourceRootWithNoSourceMapOption.json | 5 +- .../node/sourceRootWithNoSourceMapOption.json | 5 +- .../visibilityOfTypeUsedAcrossModules2.json | 4 +- .../visibilityOfTypeUsedAcrossModules2.json | 4 +- tests/cases/compiler/APISample_compile.ts | 13 +- tests/cases/compiler/APISample_transform.ts | 19 +-- .../getEmitOutputWithDeclarationFile3.ts | 2 +- ...utputWithSemanticErrorsForMultipleFiles.ts | 2 +- 59 files changed, 601 insertions(+), 478 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50dcbd21fdc..7eb13e52a29 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10111,11 +10111,6 @@ module ts { return isImportResolvedToValue(getSymbolOfNode(node)); } - function hasSemanticDiagnostics(sourceFile?: SourceFile) { - // Return true if there is any semantic error in a file or globally - return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0; - } - function isImportResolvedToValue(symbol: Symbol): boolean { var target = resolveImport(symbol); // const enums and modules that contain only const enums are not considered values from the emit perespective @@ -10210,7 +10205,6 @@ module ts { getNodeCheckFlags, getEnumMemberValue, isTopLevelValueImportWithEntityName, - hasSemanticDiagnostics, isDeclarationVisible, isImplementationOfOverload, writeTypeOfDeclaration, @@ -10226,14 +10220,15 @@ module ts { // Bind all source files and propagate errors forEach(host.getSourceFiles(), file => { bindSourceFile(file); - forEach(file.bindDiagnostics, d => diagnostics.add(d)); }); + // Initialize global symbol table forEach(host.getSourceFiles(), file => { if (!isExternalModule(file)) { extendSymbolTable(globals, file.locals); } }); + // Initialize special symbols getSymbolLinks(undefinedSymbol).type = undefinedType; getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9b852a37ff6..b82ca2f07af 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -118,6 +118,12 @@ module ts { return result; } + export function addRange(to: T[], from: T[]): void { + for (var i = 0, n = from.length; i < n; i++) { + to.push(from[i]); + } + } + /** * Returns the last element of an array if non-empty, undefined otherwise. */ @@ -369,6 +375,10 @@ module ts { return text1 ? 1 : -1; } + export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { + return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)); + } + export function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { if (diagnostics.length < 2) { return diagnostics; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9b080fa4c39..467bef144fe 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4395,13 +4395,13 @@ module ts { } } - var hasSemanticDiagnostics = false; var isEmitBlocked = false; + var isDeclarationEmitBlocked = false; if (targetSourceFile === undefined) { // No targetSourceFile is specified (e.g. calling emitter from batch compiler) - hasSemanticDiagnostics = resolver.hasSemanticDiagnostics(); isEmitBlocked = host.isEmitBlocked(); + isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(); forEach(host.getSourceFiles(), sourceFile => { if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { @@ -4418,8 +4418,8 @@ module ts { // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { // If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file - hasSemanticDiagnostics = resolver.hasSemanticDiagnostics(targetSourceFile); isEmitBlocked = host.isEmitBlocked(targetSourceFile); + isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(targetSourceFile); var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); emitFile(jsFilePath, targetSourceFile); @@ -4429,8 +4429,8 @@ module ts { // Emit all, non-external-module file, into one single output file forEach(host.getSourceFiles(), sourceFile => { if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) { - hasSemanticDiagnostics = hasSemanticDiagnostics || resolver.hasSemanticDiagnostics(sourceFile); isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile); + isDeclarationEmitBlocked = isDeclarationEmitBlocked || host.isDeclarationEmitBlocked(sourceFile); } }); @@ -4441,15 +4441,14 @@ module ts { function emitFile(jsFilePath: string, sourceFile?: SourceFile) { if (!isEmitBlocked) { emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticDiagnostics && compilerOptions.declaration) { + if (!isDeclarationEmitBlocked && compilerOptions.declaration) { writeDeclarationFile(jsFilePath, sourceFile); } } } // Sort and make the unique list of diagnostics - diagnostics.sort(compareDiagnostics); - diagnostics = deduplicateSortedDiagnostics(diagnostics); + diagnostics = sortAndDeduplicateDiagnostics(diagnostics); // Update returnCode if there is any EmitterError var hasEmitterError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); @@ -4457,13 +4456,13 @@ module ts { // Check and update returnCode for syntactic and semantic var emitResultStatus: EmitReturnStatus; if (isEmitBlocked) { - emitResultStatus = EmitReturnStatus.AllOutputGenerationSkipped; + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_AllOutputsSkipped; } else if (hasEmitterError) { emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; - } else if (hasSemanticDiagnostics && compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.DeclarationGenerationSkipped; - } else if (hasSemanticDiagnostics && !compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.JSGeneratedWithSemanticErrors; + } else if (isDeclarationEmitBlocked && compilerOptions.declaration) { + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated; + } else if (isDeclarationEmitBlocked && !compilerOptions.declaration) { + emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated; } else { emitResultStatus = EmitReturnStatus.Succeeded; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4f23e2f30a7..05b5ea55505 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -357,7 +357,7 @@ module ts { forEachChild(sourceFile, walk); } - export function getSyntacticDiagnostics(sourceFile: SourceFile) { + export function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[] { if (!sourceFile.syntacticDiagnostics) { sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 85181b2aa55..e60a9e9f188 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -75,6 +75,37 @@ module ts { }; } + export function getPreEmitDiagnostics(program: Program): Diagnostic[] { + var diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + return sortAndDeduplicateDiagnostics(diagnostics); + } + + export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { + if (typeof messageText === "string") { + return messageText; + } + else { + var diagnosticChain = messageText; + var result = ""; + + var indent = 0; + while (diagnosticChain) { + if (indent) { + result += newLine; + + for (var i = 0; i < indent; i++) { + result += " "; + } + } + result += diagnosticChain.messageText; + indent++; + diagnosticChain = diagnosticChain.next; + } + + return result; + } + } + export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; @@ -97,10 +128,9 @@ module ts { getSourceFile: getSourceFile, getSourceFiles: () => files, getCompilerOptions: () => options, - getDiagnostics, + getSyntacticDiagnostics, getGlobalDiagnostics, - getTypeCheckerDiagnostics, - getTypeCheckerGlobalDiagnostics, + getSemanticDiagnostics, getDeclarationDiagnostics, getTypeChecker, getDiagnosticsProducingTypeChecker, @@ -116,7 +146,7 @@ module ts { }; return program; - function getEmitHost(writeFileCallback?: WriteFileCallback) { + function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost { return { getCanonicalFileName: host.getCanonicalFileName, getCommonSourceDirectory: program.getCommonSourceDirectory, @@ -126,17 +156,28 @@ module ts { getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, isEmitBlocked, + isDeclarationEmitBlocked, writeFile: writeFileCallback || host.writeFile, }; } + function hasPreEmitDiagnostics(sourceFile?: SourceFile): boolean { + var hasSyntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile).length > 0; + var hasSemanticDiagnostics = program.getSemanticDiagnostics(sourceFile).length > 0; - function isEmitBlocked(sourceFile?: SourceFile): boolean { - if (options.noEmitOnError) { - return getDiagnostics(sourceFile).length !== 0 || getTypeCheckerDiagnostics(sourceFile).length !== 0; + if (hasSyntacticDiagnostics || hasSemanticDiagnostics) { + return true; } - return false; + return !sourceFile && program.getGlobalDiagnostics().length > 0; + } + + function isEmitBlocked(sourceFile?: SourceFile): boolean { + return options.noEmitOnError && hasPreEmitDiagnostics(sourceFile); + } + + function isDeclarationEmitBlocked(sourceFile?: SourceFile) { + return hasPreEmitDiagnostics(sourceFile); } function getDiagnosticsProducingTypeChecker() { @@ -170,20 +211,51 @@ module ts { return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; } - function getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[] { - return getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile); + function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + if (sourceFile) { + return ts.getSyntacticDiagnostics(sourceFile); + } + + var allDiagnostics: Diagnostic[] = []; + forEach(program.getSourceFiles(), sourceFile => { + addRange(allDiagnostics, ts.getSyntacticDiagnostics(sourceFile)); + }); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } - function getTypeCheckerGlobalDiagnostics(): Diagnostic[] { - return getDiagnosticsProducingTypeChecker().getGlobalDiagnostics(); + function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + var typeChecker = getDiagnosticsProducingTypeChecker(); + + Debug.assert(!!sourceFile.bindDiagnostics); + var bindDiagnostics = sourceFile.bindDiagnostics; + var checkDiagnostics = typeChecker.getDiagnostics(sourceFile); + var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + + return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } - function getDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ - return sourceFile ? diagnostics.getDiagnostics(sourceFile.fileName) : diagnostics.getDiagnostics(); + function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + if (sourceFile) { + return sortAndDeduplicateDiagnostics(getSemanticDiagnosticsForFile(sourceFile)); + } + + var allDiagnostics: Diagnostic[] = []; + forEach(program.getSourceFiles(), sourceFile => { + addRange(allDiagnostics, getSemanticDiagnosticsForFile(sourceFile)); + }); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics(): Diagnostic[]{ - return diagnostics.getGlobalDiagnostics(); + var typeChecker = getDiagnosticsProducingTypeChecker(); + + var allDiagnostics: Diagnostic[] = []; + addRange(allDiagnostics, typeChecker.getGlobalDiagnostics()); + addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + + return sortAndDeduplicateDiagnostics(allDiagnostics); } function hasExtension(fileName: string): boolean { @@ -272,9 +344,6 @@ module ts { else { files.push(file); } - forEach(getSyntacticDiagnostics(file), e => { - diagnostics.add(e); - }); } } return file; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 15f97e028fc..541a64b6473 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -364,13 +364,19 @@ module ts { function compileProgram(): EmitReturnStatus { // First get any syntactic errors. - var errors = program.getDiagnostics(); + var errors = program.getSyntacticDiagnostics(); reportDiagnostics(errors); - // If we didn't have any syntactic errors, then also try getting the semantic errors. + // If we didn't have any syntactic errors, then also try getting the global and + // semantic errors. if (errors.length === 0) { - var errors = program.getTypeCheckerDiagnostics(); + var errors = program.getGlobalDiagnostics(); reportDiagnostics(errors); + + if (errors.length === 0) { + var errors = program.getSemanticDiagnostics(); + reportDiagnostics(errors); + } } // If the user doesn't want us to emit, then we're done at this point. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 467d9b6cc90..75cee5e7314 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -946,13 +946,10 @@ module ts { */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - // These will merge with the below diagnostics function in a followup checkin. - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; // Gets a type checker that can be used to semantically analyze source fils in the program. getTypeChecker(): TypeChecker; @@ -992,12 +989,26 @@ module ts { // Return code used by getEmitOutput function to indicate status of the function export enum EmitReturnStatus { - Succeeded = 0, // All outputs generated if requested (.js, .map, .d.ts), no errors reported - AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated - JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors - DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors - EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process - CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options, nothing generated + // All outputs generated if requested (.js, .map, .d.ts), no errors reported + Succeeded = 0, + + // No .js, .map or d.ts generated because of diagnostics and the presence of the + // -noEmitOnError optoin. + DiagnosticsPresent_AllOutputsSkipped = 1, + + // .js and .map generated. However, diagnostics were generated as well. + // No .d.ts was requested or generated. + DiagnosticsPresent_JavaScriptGenerated = 2, + + // .js, .map generated. .d.ts was requested but was not generated due to the + // presence of diagnostics. + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, + + // Emitter errors occurred during emitting process. + EmitErrorsEncountered = 4, + + // Errors occurred in parsing compiler options, nothing generated + CompilerOptionsErrors = 5, } export interface EmitResult { @@ -1137,7 +1148,6 @@ module ts { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4204acc4716..8291520da82 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -25,7 +25,9 @@ module ts { export interface EmitHost extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + isDeclarationEmitBlocked(sourceFile?: SourceFile): boolean; getCommonSourceDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -210,36 +212,10 @@ module ts { length, code: messageChain.code, category: messageChain.category, - messageText: messageChain + messageText: messageChain.next ? messageChain : messageChain.messageText }; } - export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { - if (typeof messageText === "string") { - return messageText; - } - else { - var diagnosticChain = messageText; - var result = ""; - - var indent = 0; - while (diagnosticChain) { - if (indent) { - result += newLine; - - for (var i = 0; i < indent; i++) { - result += " "; - } - } - result += diagnosticChain.messageText; - indent++; - diagnosticChain = diagnosticChain.next; - } - - return result; - } - } - export function getErrorSpanForNode(node: Node): Node { var errorSpan: Node; switch (node.kind) { @@ -1144,7 +1120,7 @@ module ts { } } - return sortAndDeplicateList(allDiagnostics); + return sortAndDeduplicateDiagnostics(allDiagnostics); } function sortAndDeduplicate() { @@ -1153,17 +1129,13 @@ module ts { } diagnosticsModified = false; - nonFileDiagnostics = sortAndDeplicateList(nonFileDiagnostics); + nonFileDiagnostics = sortAndDeduplicateDiagnostics(nonFileDiagnostics); for (var key in fileDiagnostics) { if (hasProperty(fileDiagnostics, key)) { - fileDiagnostics[key] = sortAndDeplicateList(fileDiagnostics[key]); + fileDiagnostics[key] = sortAndDeduplicateDiagnostics(fileDiagnostics[key]); } } } - - function sortAndDeplicateList(diagnostics: Diagnostic[]): Diagnostic[] { - return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)) - } } } \ No newline at end of file diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5e046c070ab..5ce3d3f37b9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1142,14 +1142,23 @@ module FourSlash { var emitOutput = this.languageService.getEmitOutput(emitFile.fileName); var emitOutputStatus = emitOutput.emitOutputStatus; // Print emitOutputStatus in readable format - resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus]; - resultString += "\n"; + resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus] + ts.sys.newLine; + + if (emitOutputStatus !== ts.EmitReturnStatus.Succeeded) { + resultString += "Diagnostics:" + ts.sys.newLine; + var diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram()); + for (var i = 0, n = diagnostics.length; i < n; i++) { + resultString += " " + diagnostics[0].messageText + ts.sys.newLine; + } + } + emitOutput.outputFiles.forEach((outputFile, idx, array) => { - var fileName = "FileName : " + outputFile.name + "\n"; + var fileName = "FileName : " + outputFile.name + ts.sys.newLine; resultString = resultString + fileName + outputFile.text; }); - resultString += "\n"; + resultString += ts.sys.newLine; }); + return resultString; }, true /* run immediately */); @@ -2215,11 +2224,11 @@ module FourSlash { ts.sys.useCaseSensitiveFileNames); // TODO (drosen): We need to enforce checking on these tests. var program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); - var checker = ts.createTypeChecker(program, /*produceDiagnostics*/ true); - var errors = program.getDiagnostics().concat(checker.getDiagnostics()); - if (errors.length > 0) { - throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); + var diagnostics = ts.getPreEmitDiagnostics(program); + if (diagnostics.length > 0) { + throw new Error('Error compiling ' + fileName + ': ' + + diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); } program.emit(); result = result || ''; // Might have an empty fourslash file diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 84aaf66be3d..866652e2e26 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1083,10 +1083,11 @@ module Harness { (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), options.target, useCaseSensitiveFileNames, currentDirectory)); + debugger; var emitResult = program.emit(); var errors: HarnessDiagnostic[] = []; - program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(emitResult.diagnostics).forEach(err => { + ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => { // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now errors.push(getMinimalDiagnostic(err)); }); diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 53ce8e507a0..0fde9a9d77c 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -127,23 +127,20 @@ class ProjectRunner extends RunnerBase { writeFile: (fileName: string, data: string, writeByteOrderMark: boolean) => void): CompileProjectFilesResult { var program = ts.createProgram(getInputFiles(), createCompilerOptions(), createCompilerHost()); - var errors = program.getDiagnostics(); - var sourceMapData: ts.SourceMapData[] = null; - if (!errors.length) { - errors = program.getTypeCheckerDiagnostics(); - var emitResult = program.emit(); - errors = ts.concatenate(errors, emitResult.diagnostics); - sourceMapData = emitResult.sourceMaps; + var errors = ts.getPreEmitDiagnostics(program); - // Clean up source map data that will be used in baselining - if (sourceMapData) { - for (var i = 0; i < sourceMapData.length; i++) { - for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) { - sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]); - } - sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL); - sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot); + var emitResult = program.emit(); + errors = ts.concatenate(errors, emitResult.diagnostics); + var sourceMapData = emitResult.sourceMaps; + + // Clean up source map data that will be used in baselining + if (sourceMapData) { + for (var i = 0; i < sourceMapData.length; i++) { + for (var j = 0; j < sourceMapData[i].sourceMapSources.length; j++) { + sourceMapData[i].sourceMapSources[j] = cleanProjectUrl(sourceMapData[i].sourceMapSources[j]); } + sourceMapData[i].jsSourceMappingURL = cleanProjectUrl(sourceMapData[i].jsSourceMappingURL); + sourceMapData[i].sourceMapSourceRoot = cleanProjectUrl(sourceMapData[i].sourceMapSourceRoot); } } diff --git a/src/services/services.ts b/src/services/services.ts index 7311e5f7596..da695920cd7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2168,7 +2168,7 @@ module ts { fileName = normalizeSlashes(fileName); - return program.getDiagnostics(getValidSourceFile(fileName)); + return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } /** @@ -2179,18 +2179,19 @@ module ts { synchronizeHostData(); fileName = normalizeSlashes(fileName) - var compilerOptions = program.getCompilerOptions(); var targetSourceFile = getValidSourceFile(fileName); // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. // Therefore only get diagnostics for given file. - var allDiagnostics = program.getTypeCheckerDiagnostics(targetSourceFile); - if (compilerOptions.declaration) { - // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface - allDiagnostics = allDiagnostics.concat(program.getDeclarationDiagnostics(targetSourceFile)); + var semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile); + if (!program.getCompilerOptions().declaration) { + return semanticDiagnostics; } - return allDiagnostics + + // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface + var declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile); + return semanticDiagnostics.concat(declarationDiagnostics); } function getCompilerOptionsDiagnostics() { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index db4f29683d2..c64da05d512 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -10,24 +10,23 @@ declare var process: any; declare var console: any; +declare var os: any; import ts = require("typescript"); export function compile(fileNames: string[], options: ts.CompilerOptions): void { var program = ts.createProgram(fileNames, options); - var result = program.emit(); + var emitResult = program.emit(); - var allDiagnostics = program.getDiagnostics() - .concat(program.getTypeCheckerDiagnostics()) - .concat(result.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); - process.exit(result.emitResultStatus); + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); + process.exit(emitResult.emitResultStatus); } compile(process.argv.slice(2), { @@ -752,11 +751,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -781,9 +779,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -888,7 +886,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1422,6 +1419,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { @@ -1923,14 +1922,14 @@ declare module "typescript" { var ts = require("typescript"); function compile(fileNames, options) { var program = ts.createProgram(fileNames, options); - var result = program.emit(); - var allDiagnostics = program.getDiagnostics().concat(program.getTypeCheckerDiagnostics()).concat(result.diagnostics); + var emitResult = program.emit(); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(function (diagnostic) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + diagnostic.messageText); + console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)); }); - console.log("Process exiting with code '" + result.emitResultStatus + "'."); - process.exit(result.emitResultStatus); + console.log("Process exiting with code '" + emitResult.emitResultStatus + "'."); + process.exit(emitResult.emitResultStatus); } exports.compile = compile; compile(process.argv.slice(2), { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 5124312b6d3..e5ac6de7c10 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -12,6 +12,9 @@ declare var process: any; declare var console: any; >console : any +declare var os: any; +>os : any + import ts = require("typescript"); >ts : typeof ts @@ -31,43 +34,33 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >fileNames : string[] >options : ts.CompilerOptions - var result = program.emit(); ->result : ts.EmitResult + var emitResult = program.emit(); +>emitResult : ts.EmitResult >program.emit() : ts.EmitResult >program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program >emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult - var allDiagnostics = program.getDiagnostics() + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); >allDiagnostics : ts.Diagnostic[] ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) .concat(result.diagnostics) : ts.Diagnostic[] ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getDiagnostics() .concat(program.getTypeCheckerDiagnostics()) : ts.Diagnostic[] ->program.getDiagnostics() .concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getDiagnostics() : ts.Diagnostic[] ->program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program).concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>ts.getPreEmitDiagnostics(program) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] +>ts : typeof ts +>getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] >program : ts.Program ->getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - .concat(program.getTypeCheckerDiagnostics()) >concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] ->program : ts.Program ->getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - .concat(result.diagnostics); ->concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } ->result.diagnostics : ts.Diagnostic[] ->result : ts.EmitResult +>emitResult.diagnostics : ts.Diagnostic[] +>emitResult : ts.EmitResult >diagnostics : ts.Diagnostic[] allDiagnostics.forEach(diagnostic => { ->allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); }) : void +>allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }) : void >allDiagnostics.forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void >allDiagnostics : ts.Diagnostic[] >forEach : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => void, thisArg?: any) => void ->diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); } : (diagnostic: ts.Diagnostic) => void +>diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); } : (diagnostic: ts.Diagnostic) => void >diagnostic : ts.Diagnostic var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); @@ -82,8 +75,8 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >diagnostic : ts.Diagnostic >start : number - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); ->console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`) : any + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); +>console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`) : any >console.log : any >console : any >log : any @@ -98,28 +91,35 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void >lineChar.character : number >lineChar : ts.LineAndCharacter >character : number +>ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL) : string +>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string +>ts : typeof ts +>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string >diagnostic.messageText : string | ts.DiagnosticMessageChain >diagnostic : ts.Diagnostic >messageText : string | ts.DiagnosticMessageChain +>os.EOL : any +>os : any +>EOL : any }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); ->console.log(`Process exiting with code '${result.emitResultStatus}'.`) : any + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); +>console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`) : any >console.log : any >console : any >log : any ->result.emitResultStatus : ts.EmitReturnStatus ->result : ts.EmitResult +>emitResult.emitResultStatus : ts.EmitReturnStatus +>emitResult : ts.EmitResult >emitResultStatus : ts.EmitReturnStatus - process.exit(result.emitResultStatus); ->process.exit(result.emitResultStatus) : any + process.exit(emitResult.emitResultStatus); +>process.exit(emitResult.emitResultStatus) : any >process.exit : any >process : any >exit : any ->result.emitResultStatus : ts.EmitReturnStatus ->result : ts.EmitResult +>emitResult.emitResultStatus : ts.EmitReturnStatus +>emitResult : ts.EmitResult >emitResultStatus : ts.EmitReturnStatus } @@ -2268,18 +2268,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2288,8 +2278,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2359,14 +2355,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2852,11 +2848,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4556,6 +4547,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 646d0e47a4e..b84bcdb33fd 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -783,11 +783,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -812,9 +811,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -919,7 +918,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1453,6 +1451,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 1e917893832..798d41e70ee 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2415,18 +2415,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2435,8 +2425,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2506,14 +2502,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2999,11 +2995,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4703,6 +4694,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 280c5202db3..4b235f25df3 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -12,6 +12,7 @@ declare var process: any; declare var console: any; declare var fs: any; declare var path: any; +declare var os: any; import ts = require("typescript"); @@ -45,17 +46,17 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + + errors = errors.concat(emitResult.diagnostics); + return { outputs: outputs, - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); + }) }; } @@ -783,11 +784,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -812,9 +812,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -919,7 +919,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1453,6 +1452,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { @@ -1978,18 +1979,13 @@ function transform(contents, compilerOptions) { // Create a program from inputs var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + errors = errors.concat(emitResult.diagnostics); return { outputs: outputs, errors: errors.map(function (e) { - return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) }; } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index c8b7e10fa89..6a149ddbae3 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -18,6 +18,9 @@ declare var fs: any; declare var path: any; >path : any +declare var os: any; +>os : any + import ts = require("typescript"); >ts : typeof ts @@ -147,52 +150,50 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >compilerHost : { getSourceFile: (fileName: any, target: any) => ts.SourceFile; writeFile: (name: any, text: any, writeByteOrderMark: any) => void; getDefaultLibFileName: () => string; useCaseSensitiveFileNames: () => boolean; getCanonicalFileName: (fileName: any) => any; getCurrentDirectory: () => string; getNewLine: () => string; } // Query for early errors - var errors = program.getDiagnostics(); + var errors = ts.getPreEmitDiagnostics(program); >errors : ts.Diagnostic[] ->program.getDiagnostics() : ts.Diagnostic[] ->program.getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] +>ts.getPreEmitDiagnostics(program) : ts.Diagnostic[] +>ts.getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] +>ts : typeof ts +>getPreEmitDiagnostics : (program: ts.Program) => ts.Diagnostic[] >program : ts.Program ->getDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - // Do not generate code in the presence of early errors - if (!errors.length) { ->!errors.length : boolean ->errors.length : number ->errors : ts.Diagnostic[] ->length : number - - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); ->errors = program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->errors : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics() : ts.Diagnostic[] ->program.getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] ->program : ts.Program ->getTypeCheckerDiagnostics : (sourceFile?: ts.SourceFile) => ts.Diagnostic[] - - // Generate output - program.emit(); + var emitResult = program.emit(); +>emitResult : ts.EmitResult >program.emit() : ts.EmitResult >program.emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult >program : ts.Program >emit : (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback) => ts.EmitResult - } + + errors = errors.concat(emitResult.diagnostics); +>errors = errors.concat(emitResult.diagnostics) : ts.Diagnostic[] +>errors : ts.Diagnostic[] +>errors.concat(emitResult.diagnostics) : ts.Diagnostic[] +>errors.concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>errors : ts.Diagnostic[] +>concat : { (...items: U[]): ts.Diagnostic[]; (...items: ts.Diagnostic[]): ts.Diagnostic[]; } +>emitResult.diagnostics : ts.Diagnostic[] +>emitResult : ts.EmitResult +>diagnostics : ts.Diagnostic[] + return { ->{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) } : { outputs: any[]; errors: string[]; } +>{ outputs: outputs, errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) } : { outputs: any[]; errors: string[]; } outputs: outputs, >outputs : any[] >outputs : any[] - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { >errors : string[] ->errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) : string[] +>errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); }) : string[] >errors.map : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[] >errors : ts.Diagnostic[] >map : (callbackfn: (value: ts.Diagnostic, index: number, array: ts.Diagnostic[]) => U, thisArg?: any) => U[] ->function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; } : (e: ts.Diagnostic) => string +>function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); } : (e: ts.Diagnostic) => string >e : ts.Diagnostic ->e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText : string + + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " +>e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string >e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " : string >e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line : string >e.file.fileName + "(" : string @@ -212,10 +213,20 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >e : ts.Diagnostic >start : number >line : number + + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); +>ts.flattenDiagnosticMessageText(e.messageText, os.EOL) : string +>ts.flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string +>ts : typeof ts +>flattenDiagnosticMessageText : (messageText: string | ts.DiagnosticMessageChain, newLine: string) => string >e.messageText : string | ts.DiagnosticMessageChain >e : ts.Diagnostic >messageText : string | ts.DiagnosticMessageChain +>os.EOL : any +>os : any +>EOL : any + }) }; } @@ -2356,18 +2367,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2376,8 +2377,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2447,14 +2454,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -2940,11 +2947,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4644,6 +4646,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 89f3bc43d37..8c53f252843 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -821,11 +821,10 @@ declare module "typescript" { * will be invoked when writing the javascript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } @@ -850,9 +849,9 @@ declare module "typescript" { } enum EmitReturnStatus { Succeeded = 0, - AllOutputGenerationSkipped = 1, - JSGeneratedWithSemanticErrors = 2, - DeclarationGenerationSkipped = 3, + DiagnosticsPresent_AllOutputsSkipped = 1, + DiagnosticsPresent_JavaScriptGenerated = 2, + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, EmitErrorsEncountered = 4, CompilerOptionsErrors = 5, } @@ -957,7 +956,6 @@ declare module "typescript" { isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1491,6 +1489,8 @@ declare module "typescript" { } declare module "typescript" { function createCompilerHost(options: CompilerOptions): CompilerHost; + function getPreEmitDiagnostics(program: Program): Diagnostic[]; + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index f286fe18eb2..8a1f4aa259d 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2541,18 +2541,8 @@ declare module "typescript" { >WriteFileCallback : WriteFileCallback >EmitResult : EmitResult - getTypeCheckerDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getTypeCheckerDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] ->sourceFile : SourceFile ->SourceFile : SourceFile ->Diagnostic : Diagnostic - - getTypeCheckerGlobalDiagnostics(): Diagnostic[]; ->getTypeCheckerGlobalDiagnostics : () => Diagnostic[] ->Diagnostic : Diagnostic - - getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; ->getDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2561,8 +2551,14 @@ declare module "typescript" { >getGlobalDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic - getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[]; ->getDeclarationDiagnostics : (sourceFile: SourceFile) => Diagnostic[] + getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getSemanticDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; +>getDeclarationDiagnostics : (sourceFile?: SourceFile) => Diagnostic[] >sourceFile : SourceFile >SourceFile : SourceFile >Diagnostic : Diagnostic @@ -2632,14 +2628,14 @@ declare module "typescript" { Succeeded = 0, >Succeeded : EmitReturnStatus - AllOutputGenerationSkipped = 1, ->AllOutputGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_AllOutputsSkipped = 1, +>DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus - JSGeneratedWithSemanticErrors = 2, ->JSGeneratedWithSemanticErrors : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated = 2, +>DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - DeclarationGenerationSkipped = 3, ->DeclarationGenerationSkipped : EmitReturnStatus + DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, +>DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : EmitReturnStatus EmitErrorsEncountered = 4, >EmitErrorsEncountered : EmitReturnStatus @@ -3125,11 +3121,6 @@ declare module "typescript" { >node : EnumMember >EnumMember : EnumMember - hasSemanticDiagnostics(sourceFile?: SourceFile): boolean; ->hasSemanticDiagnostics : (sourceFile?: SourceFile) => boolean ->sourceFile : SourceFile ->SourceFile : SourceFile - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -4829,6 +4820,18 @@ declare module "typescript" { >CompilerOptions : CompilerOptions >CompilerHost : CompilerHost + function getPreEmitDiagnostics(program: Program): Diagnostic[]; +>getPreEmitDiagnostics : (program: Program) => Diagnostic[] +>program : Program +>Program : Program +>Diagnostic : Diagnostic + + function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; +>flattenDiagnosticMessageText : (messageText: string | DiagnosticMessageChain, newLine: string) => string +>messageText : string | DiagnosticMessageChain +>DiagnosticMessageChain : DiagnosticMessageChain +>newLine : string + function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; >createProgram : (rootNames: string[], options: CompilerOptions, host?: CompilerHost) => Program >rootNames : string[] diff --git a/tests/baselines/reference/declarationEmit_invalidReference2.js b/tests/baselines/reference/declarationEmit_invalidReference2.js index 78fb232cca7..0f8d5d4c07d 100644 --- a/tests/baselines/reference/declarationEmit_invalidReference2.js +++ b/tests/baselines/reference/declarationEmit_invalidReference2.js @@ -5,7 +5,3 @@ var x = 0; //// [declarationEmit_invalidReference2.js] /// var x = 0; - - -//// [declarationEmit_invalidReference2.d.ts] -declare var x: number; diff --git a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline index 111448faa61..a8b6f8a9cd4 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline @@ -1,30 +1,30 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js var x = 5; var Bar = (function () { function Bar() { } return Bar; })(); -FileName : tests/cases/fourslash/inputFile1.d.ts +FileName : tests/cases/fourslash/inputFile1.d.ts declare var x: number; declare class Bar { x: string; y: number; } - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; })(); -FileName : tests/cases/fourslash/inputFile2.d.ts +FileName : tests/cases/fourslash/inputFile2.d.ts declare var x1: string; declare class Foo { x: string; y: number; } - + diff --git a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline index a54108eb379..131b6cd98ed 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { @@ -12,7 +12,7 @@ var Foo = (function () { } return Foo; })(); -FileName : declSingleFile.d.ts +FileName : declSingleFile.d.ts declare var x: number; declare class Bar { x: string; @@ -23,4 +23,4 @@ declare class Foo { x: string; y: number; } - + diff --git a/tests/baselines/reference/getEmitOutputExternalModule.baseline b/tests/baselines/reference/getEmitOutputExternalModule.baseline index 6c1b0552a49..dcfd9bd89cc 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { } return Bar; })(); - + diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 5613592b414..5ec634d37a5 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,5 +1,8 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : declSingleFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. + Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. +FileName : declSingleFile.js var x = 5; var Bar = (function () { function Bar() { @@ -12,4 +15,4 @@ var Bar2 = (function () { } return Bar2; })(); - + diff --git a/tests/baselines/reference/getEmitOutputMapRoots.baseline b/tests/baselines/reference/getEmitOutputMapRoots.baseline index 733897879df..91cb853bdf0 100644 --- a/tests/baselines/reference/getEmitOutputMapRoots.baseline +++ b/tests/baselines/reference/getEmitOutputMapRoots.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : declSingleFile.js.map -{"version":3,"file":"declSingleFile.js","sourceRoot":"","sources":["../tests/cases/fourslash/inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : declSingleFile.js +EmitOutputStatus : Succeeded +FileName : declSingleFile.js.map +{"version":3,"file":"declSingleFile.js","sourceRoot":"","sources":["../tests/cases/fourslash/inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : declSingleFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=mapRootDir/declSingleFile.js.map +//# sourceMappingURL=mapRootDir/declSingleFile.js.map diff --git a/tests/baselines/reference/getEmitOutputNoErrors.baseline b/tests/baselines/reference/getEmitOutputNoErrors.baseline index b8eddab6a9c..7fb0ca2eee5 100644 --- a/tests/baselines/reference/getEmitOutputNoErrors.baseline +++ b/tests/baselines/reference/getEmitOutputNoErrors.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js var x; var M = (function () { function M() { } return M; })(); - + diff --git a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline index 6be2d3e1d04..775cbf195c6 100644 --- a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline +++ b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline @@ -1,9 +1,9 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x; var Foo = (function () { function Foo() { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputSingleFile.baseline b/tests/baselines/reference/getEmitOutputSingleFile.baseline index b5fc4214d7c..81ceb3f4357 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : outputDir/singleFile.js +EmitOutputStatus : Succeeded +FileName : outputDir/singleFile.js var x; var Bar = (function () { function Bar() { @@ -12,4 +12,4 @@ var Foo = (function () { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputSingleFile2.baseline b/tests/baselines/reference/getEmitOutputSingleFile2.baseline index fcbd145361d..0f5fad8505d 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile2.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile2.baseline @@ -1,8 +1,8 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile3.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile3.js exports.foo = 10; exports.bar = "hello world"; -FileName : tests/cases/fourslash/inputFile3.d.ts +FileName : tests/cases/fourslash/inputFile3.d.ts export declare var foo: number; export declare var bar: string; - + diff --git a/tests/baselines/reference/getEmitOutputSourceMap.baseline b/tests/baselines/reference/getEmitOutputSourceMap.baseline index c095c2f7542..553936bd91b 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile.js.map +//# sourceMappingURL=inputFile.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceMap2.baseline b/tests/baselines/reference/getEmitOutputSourceMap2.baseline index 021b3918712..838a9a985eb 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap2.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap2.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : sample/outDir/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : sample/outDir/inputFile1.js +EmitOutputStatus : Succeeded +FileName : sample/outDir/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : sample/outDir/inputFile1.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,12 +8,12 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded -FileName : sample/outDir/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,KAAK,GAAG,aAAa,CAAC;AAC1B,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,CAAC;AACd,CAAC"}FileName : sample/outDir/inputFile2.js +//# sourceMappingURL=inputFile1.js.map +EmitOutputStatus : Succeeded +FileName : sample/outDir/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["../../tests/cases/fourslash/inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,KAAK,GAAG,aAAa,CAAC;AAC1B,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,CAAC;AACd,CAAC"}FileName : sample/outDir/inputFile2.js var intro = "hello world"; if (intro !== undefined) { var k = 10; } -//# sourceMappingURL=inputFile2.js.map +//# sourceMappingURL=inputFile2.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceRoot.baseline b/tests/baselines/reference/getEmitOutputSourceRoot.baseline index 38621490fe7..880ad48ded3 100644 --- a/tests/baselines/reference/getEmitOutputSourceRoot.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRoot.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,4 +8,4 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile.js.map +//# sourceMappingURL=inputFile.js.map diff --git a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline index 46e8a782a97..20ed671e8cf 100644 --- a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":["M","M.constructor"],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js var x = 109; var foo = "hello world"; var M = (function () { @@ -8,14 +8,14 @@ var M = (function () { } return M; })(); -//# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":["C","C.constructor"],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile2.js +//# sourceMappingURL=inputFile1.js.map +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":["C","C.constructor"],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAGPC,CAACA;IAADD,QAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile2.js var bar = "hello world Typescript"; var C = (function () { function C() { } return C; })(); -//# sourceMappingURL=inputFile2.js.map +//# sourceMappingURL=inputFile2.js.map diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline index 51ea0ffba1a..0d9c3c16f55 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline @@ -1,11 +1,11 @@ -EmitOutputStatus : Succeeded - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; })(); - + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline index c42cf8974cb..03b466d4dde 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline @@ -1,15 +1,15 @@ -EmitOutputStatus : Succeeded - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile2.js +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile2.js var Foo = (function () { function Foo() { } return Foo; })(); exports.Foo = Foo; - -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile3.js + +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile3.js var x = "hello"; - + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline index 83837faece8..972d164af42 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline @@ -1,5 +1,5 @@ -EmitOutputStatus : Succeeded -FileName : declSingle.js +EmitOutputStatus : Succeeded +FileName : declSingle.js var x = "hello"; var x1 = 1000; - + diff --git a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline index e38f6a2021c..e9622faf16b 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,5 +1,8 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + 'const' declarations are only available when targeting ECMAScript 6 and higher. + 'const' declarations are only available when targeting ECMAScript 6 and higher. +FileName : tests/cases/fourslash/inputFile1.js // File contains early errors. All outputs should be skipped. const uninitialized_const_error; - + diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline index 359faef5fc1..d5bf626085e 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline @@ -1,5 +1,6 @@ -EmitOutputStatus : EmitErrorsEncountered -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : EmitErrorsEncountered +Diagnostics: +FileName : tests/cases/fourslash/inputFile.js var M; (function (M) { var C = (function () { @@ -9,4 +10,4 @@ var M; })(); M.foo = new C(); })(M || (M = {})); - + diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index 2465f832b37..98df927aa4b 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -1,5 +1,6 @@ -EmitOutputStatus : EmitErrorsEncountered -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : EmitErrorsEncountered +Diagnostics: +FileName : tests/cases/fourslash/inputFile.js define(["require", "exports"], function (require, exports) { var C = (function () { function C() { @@ -11,4 +12,4 @@ define(["require", "exports"], function (require, exports) { M.foo = new C(); })(M = exports.M || (exports.M = {})); }); - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline index a1a721704a3..9143fe51318 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : JSGeneratedWithSemanticErrors -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Type 'string' is not assignable to type 'number'. +FileName : tests/cases/fourslash/inputFile.js var x = "hello world"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline index d9cf2b1eedd..7a251e5aca4 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : DeclarationGenerationSkipped -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated +Diagnostics: + Type 'string' is not assignable to type 'number'. +FileName : tests/cases/fourslash/inputFile.js var x = "hello world"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline index 91865045420..2a0b26f47c8 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline @@ -1,8 +1,8 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js // File to emit, does not contain semantic errors // expected to be emitted correctelly regardless of the semantic errors in the other file var noErrors = true; -FileName : tests/cases/fourslash/inputFile1.d.ts +FileName : tests/cases/fourslash/inputFile1.d.ts declare var noErrors: boolean; - + diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline index 8b3a8ce8526..fde530fd483 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline @@ -1,8 +1,10 @@ -EmitOutputStatus : DeclarationGenerationSkipped -FileName : out.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated +Diagnostics: + Type 'string' is not assignable to type 'boolean'. +FileName : out.js // File to emit, does not contain semantic errors, but --out is passed // expected to not generate declarations because of the semantic errors in the other file var noErrors = true; // File not emitted, and contains semantic errors var semanticError = "string"; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline index 0edb4e3bb61..224742eea3c 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile1.js +EmitOutputStatus : Succeeded +FileName : tests/cases/fourslash/inputFile1.js // File to emit, does not contain syntactic errors // expected to be emitted correctelly regardless of the syntactic errors in the other file var noErrors = true; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline index 21f60cf9eeb..8b68a9d8ad9 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline @@ -1,8 +1,10 @@ -EmitOutputStatus : Succeeded -FileName : out.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + '=' expected. +FileName : out.js // File to emit, does not contain syntactic errors, but --out is passed // expected to not generate outputs because of the syntactic errors in the other file. var noErrors = true; // File not emitted, and contains syntactic errors var syntactic = Error; - + diff --git a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline index 53c09d5fe28..6e6c38f4531 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline @@ -1,4 +1,6 @@ -EmitOutputStatus : Succeeded -FileName : tests/cases/fourslash/inputFile.js +EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated +Diagnostics: + Type expected. +FileName : tests/cases/fourslash/inputFile.js var x; - + diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json index 9aefd24fb37..03bc2e44e0c 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.json @@ -11,5 +11,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json index 9aefd24fb37..03bc2e44e0c 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.json @@ -11,5 +11,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json index f9d00318f8c..b4ff3c201d8 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json index f9d00318f8c..b4ff3c201d8 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json index 7cf066f15c4..be0075d1500 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json index 7cf066f15c4..be0075d1500 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.json @@ -10,5 +10,8 @@ "m1.ts", "test.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "m1.js", + "test.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json index 5fb6100024f..6ba257bd4ac 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/amd/visibilityOfTypeUsedAcrossModules2.json @@ -8,5 +8,7 @@ "lib.d.ts", "main.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "main.js" + ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json index 5fb6100024f..6ba257bd4ac 100644 --- a/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json +++ b/tests/baselines/reference/project/visibilityOfTypeUsedAcrossModules2/node/visibilityOfTypeUsedAcrossModules2.json @@ -8,5 +8,7 @@ "lib.d.ts", "main.ts" ], - "emittedFiles": [] + "emittedFiles": [ + "main.js" + ] } \ No newline at end of file diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 4731f856e2a..25f9fe6e145 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -10,24 +10,23 @@ declare var process: any; declare var console: any; +declare var os: any; import ts = require("typescript"); export function compile(fileNames: string[], options: ts.CompilerOptions): void { var program = ts.createProgram(fileNames, options); - var result = program.emit(); + var emitResult = program.emit(); - var allDiagnostics = program.getDiagnostics() - .concat(program.getTypeCheckerDiagnostics()) - .concat(result.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); allDiagnostics.forEach(diagnostic => { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${diagnostic.messageText}`); + console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${result.emitResultStatus}'.`); - process.exit(result.emitResultStatus); + console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); + process.exit(emitResult.emitResultStatus); } compile(process.argv.slice(2), { diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index eccdb1ccecc..e9d9a46d286 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -12,6 +12,7 @@ declare var process: any; declare var console: any; declare var fs: any; declare var path: any; +declare var os: any; import ts = require("typescript"); @@ -45,17 +46,17 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { var program = ts.createProgram(["file.ts"], compilerOptions, compilerHost); // Query for early errors - var errors = program.getDiagnostics(); - // Do not generate code in the presence of early errors - if (!errors.length) { - // Type check and get semantic errors - errors = program.getTypeCheckerDiagnostics(); - // Generate output - program.emit(); - } + var errors = ts.getPreEmitDiagnostics(program); + var emitResult = program.emit(); + + errors = errors.concat(emitResult.diagnostics); + return { outputs: outputs, - errors: errors.map(function (e) { return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + e.messageText; }) + errors: errors.map(function (e) { + return e.file.fileName + "(" + e.file.getLineAndCharacterFromPosition(e.start).line + "): " + + ts.flattenDiagnosticMessageText(e.messageText, os.EOL); + }) }; } diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts index e363d6b53fd..266edaf23e1 100644 --- a/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts @@ -18,5 +18,5 @@ // @Filename: inputFile5.js //// var x2 = 1000; - +debugger; verify.baselineGetEmitOutput(); \ No newline at end of file diff --git a/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts b/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts index 5cfacc36715..69f8b8a8b41 100644 --- a/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts +++ b/tests/cases/fourslash/getEmitOutputWithSemanticErrorsForMultipleFiles.ts @@ -12,5 +12,5 @@ // @Filename: inputFile2.ts //// // File not emitted, and contains semantic errors //// var semanticError: boolean = "string"; - +debugger; verify.baselineGetEmitOutput(); \ No newline at end of file From 493327af346f71d4661fd875e935641b6eddfcc5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 02:10:36 -0800 Subject: [PATCH 15/26] Fix language service handling of diagnostics. --- src/services/shims.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 8b7a48d03f3..5b5216813fe 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -368,7 +368,12 @@ module ts { }); } - private realizeDiagnostic(diagnostic: Diagnostic, newLine?: string): { 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: flattenDiagnosticMessageText(diagnostic.messageText, newLine), start: diagnostic.start, @@ -405,8 +410,8 @@ module ts { return this.forwardJSONCall( "getSyntacticDiagnostics('" + fileName + "')", () => { - var errors = this.languageService.getSyntacticDiagnostics(fileName); - return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()); + var diagnostics = this.languageService.getSyntacticDiagnostics(fileName); + return this.realizeDiagnostics(diagnostics); }); } @@ -414,8 +419,8 @@ module ts { return this.forwardJSONCall( "getSemanticDiagnostics('" + fileName + "')", () => { - var errors = this.languageService.getSemanticDiagnostics(fileName); - return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()); + var diagnostics = this.languageService.getSemanticDiagnostics(fileName); + return this.realizeDiagnostics(diagnostics); }); } @@ -423,8 +428,8 @@ module ts { return this.forwardJSONCall( "getCompilerOptionsDiagnostics()", () => { - var errors = this.languageService.getCompilerOptionsDiagnostics(); - return errors.map(e => this.realizeDiagnostic(e), this.getNewLine()) + var diagnostics = this.languageService.getCompilerOptionsDiagnostics(); + return this.realizeDiagnostics(diagnostics); }); } From c1dfdaa436f85665b6bc5f73ba0d55a217eaf68c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 02:15:38 -0800 Subject: [PATCH 16/26] Simplify code for getting diagnostics in the Program. --- src/compiler/program.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e60a9e9f188..ee41e9c4ba7 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -211,19 +211,27 @@ module ts { return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; } - function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] { if (sourceFile) { - return ts.getSyntacticDiagnostics(sourceFile); + return getDiagnostics(sourceFile); } var allDiagnostics: Diagnostic[] = []; forEach(program.getSourceFiles(), sourceFile => { - addRange(allDiagnostics, ts.getSyntacticDiagnostics(sourceFile)); + addRange(allDiagnostics, getDiagnostics(sourceFile)); }); return sortAndDeduplicateDiagnostics(allDiagnostics); } + function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ + return getDiagnosticsHelper(sourceFile, ts.getSyntacticDiagnostics); + } + + function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ + return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile); + } + function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { var typeChecker = getDiagnosticsProducingTypeChecker(); @@ -235,19 +243,6 @@ module ts { return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } - function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { - if (sourceFile) { - return sortAndDeduplicateDiagnostics(getSemanticDiagnosticsForFile(sourceFile)); - } - - var allDiagnostics: Diagnostic[] = []; - forEach(program.getSourceFiles(), sourceFile => { - addRange(allDiagnostics, getSemanticDiagnosticsForFile(sourceFile)); - }); - - return sortAndDeduplicateDiagnostics(allDiagnostics); - } - function getGlobalDiagnostics(): Diagnostic[]{ var typeChecker = getDiagnosticsProducingTypeChecker(); From f20fbb9726004a9003bbdc4021b2606abcd3bd41 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 13:14:41 -0800 Subject: [PATCH 17/26] Remove what looks like copy/paste errors in the parser. --- src/compiler/parser.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 05b5ea55505..0b17d95ac2b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -876,7 +876,10 @@ module ts { var sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0); - sourceFile.pos = sourceFile.end = 0; + sourceFile.pos = 0; + sourceFile.end = sourceText.length; + sourceFile.text = sourceText; + sourceFile.referenceDiagnostics = []; sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; @@ -961,13 +964,6 @@ module ts { // attached to the EOF token. var parseErrorBeforeNextFinishedNode: boolean = false; - sourceFile.syntacticDiagnostics = undefined; - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.bindDiagnostics = []; - 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(); From ea4e3de91ce45350297afec9d6bca05c325f7df0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 13:38:11 -0800 Subject: [PATCH 18/26] Remove unnecessary diagnostics split on SourceFile. --- src/compiler/parser.ts | 13 ++----------- src/compiler/program.ts | 6 +++++- src/compiler/types.ts | 11 ++--------- src/harness/fourslash.ts | 4 ++-- src/services/services.ts | 5 ----- tests/baselines/reference/APISample_compile.js | 2 -- tests/baselines/reference/APISample_compile.types | 10 ---------- tests/baselines/reference/APISample_linter.js | 2 -- tests/baselines/reference/APISample_linter.types | 10 ---------- tests/baselines/reference/APISample_transform.js | 2 -- tests/baselines/reference/APISample_transform.types | 10 ---------- tests/baselines/reference/APISample_watcher.js | 2 -- tests/baselines/reference/APISample_watcher.types | 10 ---------- tests/cases/unittests/incrementalParser.ts | 4 ++-- 14 files changed, 13 insertions(+), 78 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0b17d95ac2b..cd08e592be8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -357,14 +357,6 @@ module ts { forEachChild(sourceFile, walk); } - export function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[] { - if (!sourceFile.syntacticDiagnostics) { - sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); - } - - return sourceFile.syntacticDiagnostics; - } - function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) { if (element.length) { visitArray(element); @@ -880,7 +872,6 @@ module ts { sourceFile.end = sourceText.length; sourceFile.text = sourceText; - sourceFile.referenceDiagnostics = []; sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; @@ -4698,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 { @@ -4706,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 ee41e9c4ba7..588ac3ac789 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -225,13 +225,17 @@ module ts { } function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ - return getDiagnosticsHelper(sourceFile, ts.getSyntacticDiagnostics); + 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(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 75cee5e7314..8a5822f3266 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -902,20 +902,13 @@ module ts { /* @internal */ identifierCount: number; /* @internal */ symbolCount: number; - // Diagnostics reported about the "///(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; @@ -1473,7 +1472,6 @@ declare module "typescript" { getLineAndCharacterFromPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionFromLineAndCharacter(line: number, character: number): number; - getSyntacticDiagnostics(): Diagnostic[]; update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index e5ac6de7c10..e5d69bbcfd2 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -4493,12 +4493,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 @@ -4755,10 +4749,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 diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b84bcdb33fd..6edb6399bf9 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1439,7 +1439,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; @@ -1505,7 +1504,6 @@ declare module "typescript" { getLineAndCharacterFromPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionFromLineAndCharacter(line: number, character: number): number; - getSyntacticDiagnostics(): Diagnostic[]; update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 798d41e70ee..4ce2c4d92db 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4640,12 +4640,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 @@ -4902,10 +4896,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 diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 4b235f25df3..023e3c5fa06 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1440,7 +1440,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; @@ -1506,7 +1505,6 @@ declare module "typescript" { getLineAndCharacterFromPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionFromLineAndCharacter(line: number, character: number): number; - getSyntacticDiagnostics(): Diagnostic[]; update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 6a149ddbae3..445cd50a205 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -4592,12 +4592,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 @@ -4854,10 +4848,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 diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 8c53f252843..9bdd3d71d07 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1477,7 +1477,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; @@ -1543,7 +1542,6 @@ declare module "typescript" { getLineAndCharacterFromPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionFromLineAndCharacter(line: number, character: number): number; - getSyntacticDiagnostics(): Diagnostic[]; update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 8a1f4aa259d..1c4efc7b5db 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4766,12 +4766,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 @@ -5028,10 +5022,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 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++) { From b0061c14200f21f60b699c668a0724378d81ec6b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 14:41:04 -0800 Subject: [PATCH 19/26] Emit both javascript and declarations in the presence of errors (*unless* -noEmitOnError is specified). --- src/compiler/checker.ts | 9 +- src/compiler/emitter.ts | 82 ++--- src/compiler/program.ts | 42 +-- src/compiler/types.ts | 4 +- src/compiler/utilities.ts | 3 - src/harness/compilerRunner.ts | 1 + tests/baselines/reference/classdecl.js | 62 ++++ .../computedPropertyNamesDeclarationEmit3.js | 5 + .../computedPropertyNamesDeclarationEmit4.js | 5 + .../declFileObjectLiteralWithAccessors.js | 12 + .../declFileObjectLiteralWithOnlyGetter.js | 10 + .../declFileObjectLiteralWithOnlySetter.js | 11 + .../reference/declFilePrivateStatic.js | 13 + tests/baselines/reference/declInput.js | 14 + .../declarationEmit_invalidReference2.js | 4 + .../getEmitOutputExternalModule2.baseline | 5 +- ...mitOutputWithEarlySyntacticErrors.baseline | 5 +- .../getEmitOutputWithSemanticErrors.baseline | 4 +- .../getEmitOutputWithSemanticErrors2.baseline | 6 +- ...thSemanticErrorsForMultipleFiles2.baseline | 7 +- ...hSyntacticErrorsForMultipleFiles2.baseline | 4 +- .../getEmitOutputWithSyntaxErrors.baseline | 4 +- tests/baselines/reference/giant.js | 304 ++++++++++++++++++ .../baselines/reference/intrinsics.errors.txt | 5 +- tests/baselines/reference/moduledecl.js | 134 ++++++++ .../privacyGloImportParseErrors.errors.txt | 8 +- tests/baselines/reference/widenedTypes.js | 14 + tests/baselines/reference/withExportDecl.js | 28 ++ 28 files changed, 690 insertions(+), 115 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7eb13e52a29..d1821d6067c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -55,7 +55,7 @@ module ts { getSignatureFromDeclaration, isImplementationOfOverload, getAliasedSymbol: resolveImport, - getEmitResolver: () => emitResolver, + getEmitResolver, }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -123,6 +123,13 @@ module ts { } }; + 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) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 467bef144fe..12b8d720ad6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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; } } @@ -1576,6 +1578,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 @@ -2638,7 +2659,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)) { @@ -4237,7 +4257,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) { @@ -4355,24 +4374,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) { @@ -4395,14 +4396,7 @@ module ts { } } - var isEmitBlocked = false; - var isDeclarationEmitBlocked = false; - if (targetSourceFile === undefined) { - // No targetSourceFile is specified (e.g. calling emitter from batch compiler) - isEmitBlocked = host.isEmitBlocked(); - isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(); - forEach(host.getSourceFiles(), sourceFile => { if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { var jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js"); @@ -4417,33 +4411,19 @@ module ts { 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 - isEmitBlocked = host.isEmitBlocked(targetSourceFile); - isDeclarationEmitBlocked = host.isDeclarationEmitBlocked(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)) { - isEmitBlocked = isEmitBlocked || host.isEmitBlocked(sourceFile); - isDeclarationEmitBlocked = isDeclarationEmitBlocked || host.isDeclarationEmitBlocked(sourceFile); - } - }); - emitFile(compilerOptions.out); } } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - if (!isEmitBlocked) { - emitJavaScript(jsFilePath, sourceFile); - if (!isDeclarationEmitBlocked && compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); - } + emitJavaScript(jsFilePath, sourceFile); + + if (compilerOptions.declaration) { + writeDeclarationFile(jsFilePath, sourceFile); } } @@ -4455,14 +4435,8 @@ module ts { // Check and update returnCode for syntactic and semantic var emitResultStatus: EmitReturnStatus; - if (isEmitBlocked) { - emitResultStatus = EmitReturnStatus.DiagnosticsPresent_AllOutputsSkipped; - } else if (hasEmitterError) { + if (hasEmitterError) { emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; - } else if (isDeclarationEmitBlocked && compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated; - } else if (isDeclarationEmitBlocked && !compilerOptions.declaration) { - emitResultStatus = EmitReturnStatus.DiagnosticsPresent_JavaScriptGenerated; } else { emitResultStatus = EmitReturnStatus.Succeeded; } @@ -4470,7 +4444,7 @@ module ts { return { emitResultStatus, diagnostics, - sourceMaps: isEmitBlocked ? undefined : sourceMapDataList + sourceMaps: sourceMapDataList }; } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 588ac3ac789..1c919de9c69 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -136,9 +136,7 @@ module ts { getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, emit, - isEmitBlocked, getCurrentDirectory: host.getCurrentDirectory, - getEmitResolver: () => getDiagnosticsProducingTypeChecker().getEmitResolver(), getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(), getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(), getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), @@ -155,31 +153,10 @@ module ts { getNewLine: host.getNewLine, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - isEmitBlocked, - isDeclarationEmitBlocked, writeFile: writeFileCallback || host.writeFile, }; } - function hasPreEmitDiagnostics(sourceFile?: SourceFile): boolean { - var hasSyntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile).length > 0; - var hasSemanticDiagnostics = program.getSemanticDiagnostics(sourceFile).length > 0; - - if (hasSyntacticDiagnostics || hasSemanticDiagnostics) { - return true; - } - - return !sourceFile && program.getGlobalDiagnostics().length > 0; - } - - function isEmitBlocked(sourceFile?: SourceFile): boolean { - return options.noEmitOnError && hasPreEmitDiagnostics(sourceFile); - } - - function isDeclarationEmitBlocked(sourceFile?: SourceFile) { - return hasPreEmitDiagnostics(sourceFile); - } - function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true)); } @@ -189,18 +166,23 @@ module ts { } function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[]{ - var typeChecker = getDiagnosticsProducingTypeChecker(); - typeChecker.getDiagnostics(targetSourceFile); - var resolver = typeChecker.getEmitResolver(); + var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile); return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); } - function emit(targetSourceFile?: SourceFile, writeFileCallback?: WriteFileCallback) { + 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, emitResultStatus: EmitReturnStatus.DiagnosticsPresent_AllOutputsSkipped }; + } + var start = new Date().getTime(); - var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(); - var host = getEmitHost(writeFileCallback); - var result = emitFiles(resolver, host, targetSourceFile); + var result = emitFiles( + getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), + getEmitHost(writeFileCallback), + sourceFile); emitTime += new Date().getTime() - start; return result; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8a5822f3266..7bb1ff1a738 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -984,7 +984,7 @@ module ts { export enum EmitReturnStatus { // All outputs generated if requested (.js, .map, .d.ts), no errors reported Succeeded = 0, - + // No .js, .map or d.ts generated because of diagnostics and the presence of the // -noEmitOnError optoin. DiagnosticsPresent_AllOutputsSkipped = 1, @@ -1050,7 +1050,7 @@ module ts { // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; /* @internal */ getGlobalDiagnostics(): Diagnostic[]; - /* @internal */ getEmitResolver(): EmitResolver; + /* @internal */ getEmitResolver(sourceFile?: SourceFile): EmitResolver; /* @internal */ getNodeCount(): number; /* @internal */ getIdentifierCount(): number; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8291520da82..ce8b5547f00 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -26,9 +26,6 @@ module ts { export interface EmitHost extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - isEmitBlocked(sourceFile?: SourceFile): boolean; - isDeclarationEmitBlocked(sourceFile?: SourceFile): boolean; - getCommonSourceDirectory(): string; getCanonicalFileName(fileName: string): string; getNewLine(): string; diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index e4979f7a3c4..250cd54e764 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -149,6 +149,7 @@ class CompilerBaselineRunner extends RunnerBase { // check errors it('Correct errors for ' + fileName, () => { + debugger; if (this.errors) { Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => { if (result.errors.length === 0) return null; 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/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/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/declarationEmit_invalidReference2.js b/tests/baselines/reference/declarationEmit_invalidReference2.js index 0f8d5d4c07d..78fb232cca7 100644 --- a/tests/baselines/reference/declarationEmit_invalidReference2.js +++ b/tests/baselines/reference/declarationEmit_invalidReference2.js @@ -5,3 +5,7 @@ var x = 0; //// [declarationEmit_invalidReference2.js] /// var x = 0; + + +//// [declarationEmit_invalidReference2.d.ts] +declare var x: number; diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 5ec634d37a5..205b2f1b303 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,7 +1,4 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated -Diagnostics: - Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. - Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. +EmitOutputStatus : Succeeded FileName : declSingleFile.js var x = 5; var Bar = (function () { diff --git a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline index e9622faf16b..5404e2e05e2 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,7 +1,4 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated -Diagnostics: - 'const' declarations are only available when targeting ECMAScript 6 and higher. - 'const' declarations are only available when targeting ECMAScript 6 and higher. +EmitOutputStatus : Succeeded 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/getEmitOutputWithSemanticErrors.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline index 9143fe51318..6c263064ae3 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline @@ -1,6 +1,4 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated -Diagnostics: - Type 'string' is not assignable to type 'number'. +EmitOutputStatus : Succeeded 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 7a251e5aca4..78c279add04 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated -Diagnostics: - Type 'string' is not assignable to type 'number'. +EmitOutputStatus : Succeeded 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/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline index fde530fd483..7a6d61855ae 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline @@ -1,10 +1,11 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated -Diagnostics: - Type 'string' is not assignable to type 'boolean'. +EmitOutputStatus : Succeeded 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/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline index 8b68a9d8ad9..967f792fb06 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline @@ -1,6 +1,4 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated -Diagnostics: - '=' expected. +EmitOutputStatus : Succeeded 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. diff --git a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline index 6e6c38f4531..b6b40c5352c 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline @@ -1,6 +1,4 @@ -EmitOutputStatus : DiagnosticsPresent_JavaScriptGenerated -Diagnostics: - Type expected. +EmitOutputStatus : Succeeded 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/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/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/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; From e7f6693eda5580d2a335566e2cdc4c6af2ac299d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 14:46:50 -0800 Subject: [PATCH 20/26] Move code for emitting above helper functions. --- src/compiler/emitter.ts | 86 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 12b8d720ad6..c2f03cc8aa3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1515,6 +1515,49 @@ module ts { 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); + + // 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 (hasEmitterError) { + emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; + } else { + emitResultStatus = EmitReturnStatus.Succeeded; + } + + return { + emitResultStatus, + diagnostics, + sourceMaps: sourceMapDataList + }; + function emitJavaScript(jsFilePath: string, root?: SourceFile) { var writer = createTextWriter(newLine); var write = writer.write; @@ -4395,29 +4438,6 @@ module ts { writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } - - 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); - } - } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { emitJavaScript(jsFilePath, sourceFile); @@ -4426,25 +4446,5 @@ module ts { writeDeclarationFile(jsFilePath, sourceFile); } } - - // Sort and make the unique list of diagnostics - diagnostics = sortAndDeduplicateDiagnostics(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 (hasEmitterError) { - emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; - } else { - emitResultStatus = EmitReturnStatus.Succeeded; - } - - return { - emitResultStatus, - diagnostics, - sourceMaps: sourceMapDataList - }; } } From 66a363f449dd565a43fb78363612ff007073ebc4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 15:50:18 -0800 Subject: [PATCH 21/26] Simplify the API for emitting and reporting exit statuses to callers. --- src/compiler/emitter.ts | 16 +---- src/compiler/program.ts | 8 +-- src/compiler/tsc.ts | 55 ++++++++++------- src/compiler/types.ts | 30 ++++------ src/harness/fourslash.ts | 5 +- src/services/services.ts | 4 +- .../baselines/reference/APISample_compile.js | 25 ++++---- .../reference/APISample_compile.types | 58 ++++++++---------- tests/baselines/reference/APISample_linter.js | 15 ++--- .../reference/APISample_linter.types | 35 ++++------- .../reference/APISample_transform.js | 15 ++--- .../reference/APISample_transform.types | 35 ++++------- .../baselines/reference/APISample_watcher.js | 23 ++++--- .../reference/APISample_watcher.types | 60 ++++++++----------- ...etEmitOutputDeclarationMultiFiles.baseline | 4 +- ...etEmitOutputDeclarationSingleFile.baseline | 2 +- .../getEmitOutputExternalModule.baseline | 2 +- .../getEmitOutputExternalModule2.baseline | 2 +- .../reference/getEmitOutputMapRoots.baseline | 2 +- .../reference/getEmitOutputNoErrors.baseline | 2 +- .../getEmitOutputOnlyOneFile.baseline | 2 +- .../getEmitOutputSingleFile.baseline | 2 +- .../getEmitOutputSingleFile2.baseline | 2 +- .../reference/getEmitOutputSourceMap.baseline | 2 +- .../getEmitOutputSourceMap2.baseline | 4 +- .../getEmitOutputSourceRoot.baseline | 2 +- ...getEmitOutputSourceRootMultiFiles.baseline | 4 +- .../getEmitOutputWithDeclarationFile.baseline | 4 +- ...getEmitOutputWithDeclarationFile2.baseline | 6 +- ...getEmitOutputWithDeclarationFile3.baseline | 2 +- ...mitOutputWithEarlySyntacticErrors.baseline | 2 +- .../getEmitOutputWithEmitterErrors.baseline | 3 +- .../getEmitOutputWithEmitterErrors2.baseline | 3 +- .../getEmitOutputWithSemanticErrors.baseline | 2 +- .../getEmitOutputWithSemanticErrors2.baseline | 2 +- ...ithSemanticErrorsForMultipleFiles.baseline | 2 +- ...thSemanticErrorsForMultipleFiles2.baseline | 2 +- ...thSyntacticErrorsForMultipleFiles.baseline | 2 +- ...hSyntacticErrorsForMultipleFiles2.baseline | 2 +- .../getEmitOutputWithSyntaxErrors.baseline | 2 +- tests/cases/compiler/APISample_compile.ts | 5 +- tests/cases/compiler/APISample_watcher.ts | 4 +- 42 files changed, 199 insertions(+), 260 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c2f03cc8aa3..3b3351ada69 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1508,7 +1508,8 @@ module ts { // @internal // 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 { + 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; @@ -1541,19 +1542,8 @@ module ts { // Sort and make the unique list of diagnostics diagnostics = sortAndDeduplicateDiagnostics(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 (hasEmitterError) { - emitResultStatus = EmitReturnStatus.EmitErrorsEncountered; - } else { - emitResultStatus = EmitReturnStatus.Succeeded; - } - return { - emitResultStatus, + emitSkipped: false, diagnostics, sourceMaps: sourceMapDataList }; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1c919de9c69..e933c54bc1e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -174,20 +174,20 @@ module ts { // 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, emitResultStatus: EmitReturnStatus.DiagnosticsPresent_AllOutputsSkipped }; + return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; } var start = new Date().getTime(); - var result = emitFiles( + var emitResult = emitFiles( getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), getEmitHost(writeFileCallback), sourceFile); emitTime += new Date().getTime() - start; - return result; + return emitResult; } - + function getSourceFile(fileName: string) { fileName = host.getCanonicalFileName(fileName); return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 541a64b6473..4bcd0856ca8 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -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); @@ -362,33 +362,46 @@ module ts { return { program, exitStatus }; - function compileProgram(): EmitReturnStatus { + function compileProgram(): ExitStatus { // First get any syntactic errors. - var errors = program.getSyntacticDiagnostics(); - reportDiagnostics(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 (errors.length === 0) { - var errors = program.getGlobalDiagnostics(); - reportDiagnostics(errors); + if (diagnostics.length === 0) { + var diagnostics = program.getGlobalDiagnostics(); + reportDiagnostics(diagnostics); - if (errors.length === 0) { - var errors = program.getSemanticDiagnostics(); - reportDiagnostics(errors); + 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 EmitReturnStatus.Succeeded; + return diagnostics.length + ? ExitStatus.DiagnosticsPresent_OutputsSkipped + : ExitStatus.Success; } // Otherwise, emit and report any errors we ran into. var emitOutput = program.emit(); reportDiagnostics(emitOutput.diagnostics); - return emitOutput.emitResultStatus; + // 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; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7bb1ff1a738..23da074815a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -981,31 +981,21 @@ module ts { } // Return code used by getEmitOutput function to indicate status of the function - export enum EmitReturnStatus { - // All outputs generated if requested (.js, .map, .d.ts), no errors reported - Succeeded = 0, + 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, - // No .js, .map or d.ts generated because of diagnostics and the presence of the - // -noEmitOnError optoin. - DiagnosticsPresent_AllOutputsSkipped = 1, + // Diagnostics were produced and because of them no code was generated. + DiagnosticsPresent_OutputsSkipped = 1, - // .js and .map generated. However, diagnostics were generated as well. - // No .d.ts was requested or generated. - DiagnosticsPresent_JavaScriptGenerated = 2, - - // .js, .map generated. .d.ts was requested but was not generated due to the - // presence of diagnostics. - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, - - // Emitter errors occurred during emitting process. - EmitErrorsEncountered = 4, - - // Errors occurred in parsing compiler options, nothing generated - CompilerOptionsErrors = 5, + // 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 } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a5a34aaa4c3..cd9d4288cdd 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1140,11 +1140,10 @@ 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] + ts.sys.newLine; + resultString += "EmitSkipped: " + emitOutput.emitSkipped + ts.sys.newLine; - if (emitOutputStatus !== ts.EmitReturnStatus.Succeeded) { + 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++) { diff --git a/src/services/services.ts b/src/services/services.ts index 7e01f4798a5..cd69a4f2117 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1122,7 +1122,7 @@ module ts { export interface EmitOutput { outputFiles: OutputFile[]; - emitOutputStatus: EmitReturnStatus; + emitSkipped: boolean; } export const enum OutputFileType { @@ -4664,7 +4664,7 @@ module ts { return { outputFiles, - emitOutputStatus: emitOutput.emitResultStatus + emitSkipped: emitOutput.emitSkipped }; } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 1d893639576..26a59c433b9 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -25,8 +25,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); - process.exit(emitResult.emitResultStatus); + var exitCode = emitResult.emitSkipped ? 1 : 0; + console.log(`Process exiting with code '${exitCode}'.`); + process.exit(exitCode); } compile(process.argv.slice(2), { @@ -777,16 +778,13 @@ declare module "typescript" { sourceMapMappings: string; sourceMapDecodedMappings: SourceMapSpan[]; } - enum EmitReturnStatus { - Succeeded = 0, - DiagnosticsPresent_AllOutputsSkipped = 1, - DiagnosticsPresent_JavaScriptGenerated = 2, - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 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[]; } @@ -1723,7 +1721,7 @@ declare module "typescript" { } interface EmitOutput { outputFiles: OutputFile[]; - emitOutputStatus: EmitReturnStatus; + emitSkipped: boolean; } const enum OutputFileType { JavaScript = 0, @@ -1926,8 +1924,9 @@ function compile(fileNames, options) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); console.log(diagnostic.file.fileName + " (" + lineChar.line + "," + lineChar.character + "): " + ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)); }); - console.log("Process exiting with code '" + emitResult.emitResultStatus + "'."); - process.exit(emitResult.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 e5d69bbcfd2..43b79049e8b 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -104,23 +104,26 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void }); - console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); ->console.log(`Process exiting with code '${emitResult.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 ->emitResult.emitResultStatus : ts.EmitReturnStatus ->emitResult : ts.EmitResult ->emitResultStatus : ts.EmitReturnStatus +>exitCode : number - process.exit(emitResult.emitResultStatus); ->process.exit(emitResult.emitResultStatus) : any + process.exit(exitCode); +>process.exit(exitCode) : any >process.exit : any >process : any >exit : any ->emitResult.emitResultStatus : ts.EmitReturnStatus ->emitResult : ts.EmitResult ->emitResultStatus : ts.EmitReturnStatus +>exitCode : number } compile(process.argv.slice(2), { @@ -2349,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 - DiagnosticsPresent_AllOutputsSkipped = 1, ->DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus + DiagnosticsPresent_OutputsSkipped = 1, +>DiagnosticsPresent_OutputsSkipped : ExitStatus - DiagnosticsPresent_JavaScriptGenerated = 2, ->DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, ->DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : 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[] @@ -5496,9 +5489,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 6edb6399bf9..89e9aed992c 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -809,16 +809,13 @@ declare module "typescript" { sourceMapMappings: string; sourceMapDecodedMappings: SourceMapSpan[]; } - enum EmitReturnStatus { - Succeeded = 0, - DiagnosticsPresent_AllOutputsSkipped = 1, - DiagnosticsPresent_JavaScriptGenerated = 2, - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 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[]; } @@ -1755,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 4ce2c4d92db..846781e64ad 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2496,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 - DiagnosticsPresent_AllOutputsSkipped = 1, ->DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus + DiagnosticsPresent_OutputsSkipped = 1, +>DiagnosticsPresent_OutputsSkipped : ExitStatus - DiagnosticsPresent_JavaScriptGenerated = 2, ->DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, ->DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : 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[] @@ -5643,9 +5633,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 023e3c5fa06..a4b102d8efb 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -810,16 +810,13 @@ declare module "typescript" { sourceMapMappings: string; sourceMapDecodedMappings: SourceMapSpan[]; } - enum EmitReturnStatus { - Succeeded = 0, - DiagnosticsPresent_AllOutputsSkipped = 1, - DiagnosticsPresent_JavaScriptGenerated = 2, - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 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[]; } @@ -1756,7 +1753,7 @@ declare module "typescript" { } interface EmitOutput { outputFiles: OutputFile[]; - emitOutputStatus: EmitReturnStatus; + emitSkipped: boolean; } const enum OutputFileType { JavaScript = 0, diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 445cd50a205..5f1859b13e7 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2448,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 - DiagnosticsPresent_AllOutputsSkipped = 1, ->DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus + DiagnosticsPresent_OutputsSkipped = 1, +>DiagnosticsPresent_OutputsSkipped : ExitStatus - DiagnosticsPresent_JavaScriptGenerated = 2, ->DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, ->DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : 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[] @@ -5595,9 +5585,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 9bdd3d71d07..4f3fb5cdc47 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}`); @@ -847,16 +847,13 @@ declare module "typescript" { sourceMapMappings: string; sourceMapDecodedMappings: SourceMapSpan[]; } - enum EmitReturnStatus { - Succeeded = 0, - DiagnosticsPresent_AllOutputsSkipped = 1, - DiagnosticsPresent_JavaScriptGenerated = 2, - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 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[]; } @@ -1793,7 +1790,7 @@ declare module "typescript" { } interface EmitOutput { outputFiles: OutputFile[]; - emitOutputStatus: EmitReturnStatus; + emitSkipped: boolean; } const enum OutputFileType { JavaScript = 0, @@ -2028,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 { @@ -2044,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 1c4efc7b5db..e990ec362ea 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,6 +357,10 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) { >lineChar.character : number >lineChar : ts.LineAndCharacter >character : number +>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 | ts.DiagnosticMessageChain @@ -2622,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 - DiagnosticsPresent_AllOutputsSkipped = 1, ->DiagnosticsPresent_AllOutputsSkipped : EmitReturnStatus + DiagnosticsPresent_OutputsSkipped = 1, +>DiagnosticsPresent_OutputsSkipped : ExitStatus - DiagnosticsPresent_JavaScriptGenerated = 2, ->DiagnosticsPresent_JavaScriptGenerated : EmitReturnStatus - - DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated = 3, ->DiagnosticsPresent_JavaScriptGenerated_DeclarationNotGenerated : 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[] @@ -5769,9 +5758,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/getEmitOutputDeclarationMultiFiles.baseline b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline index a8b6f8a9cd4..5552851dec4 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile1.js var x = 5; var Bar = (function () { @@ -13,7 +13,7 @@ declare class Bar { y: number; } -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { diff --git a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline index 131b6cd98ed..4abc99b05c2 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationSingleFile.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : declSingleFile.js var x = 5; var Bar = (function () { diff --git a/tests/baselines/reference/getEmitOutputExternalModule.baseline b/tests/baselines/reference/getEmitOutputExternalModule.baseline index dcfd9bd89cc..ac2f7cb3dac 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : declSingleFile.js var x = 5; var Bar = (function () { diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 205b2f1b303..c32472d318f 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : declSingleFile.js var x = 5; var Bar = (function () { diff --git a/tests/baselines/reference/getEmitOutputMapRoots.baseline b/tests/baselines/reference/getEmitOutputMapRoots.baseline index 91cb853bdf0..16f39169e23 100644 --- a/tests/baselines/reference/getEmitOutputMapRoots.baseline +++ b/tests/baselines/reference/getEmitOutputMapRoots.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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; diff --git a/tests/baselines/reference/getEmitOutputNoErrors.baseline b/tests/baselines/reference/getEmitOutputNoErrors.baseline index 7fb0ca2eee5..a1efeecd321 100644 --- a/tests/baselines/reference/getEmitOutputNoErrors.baseline +++ b/tests/baselines/reference/getEmitOutputNoErrors.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile.js var x; var M = (function () { diff --git a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline index 775cbf195c6..981b4710e41 100644 --- a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline +++ b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile2.js var x; var Foo = (function () { diff --git a/tests/baselines/reference/getEmitOutputSingleFile.baseline b/tests/baselines/reference/getEmitOutputSingleFile.baseline index 81ceb3f4357..4a71299dcc0 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : outputDir/singleFile.js var x; var Bar = (function () { diff --git a/tests/baselines/reference/getEmitOutputSingleFile2.baseline b/tests/baselines/reference/getEmitOutputSingleFile2.baseline index 0f5fad8505d..c9409c5ca8c 100644 --- a/tests/baselines/reference/getEmitOutputSingleFile2.baseline +++ b/tests/baselines/reference/getEmitOutputSingleFile2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile3.js exports.foo = 10; exports.bar = "hello world"; diff --git a/tests/baselines/reference/getEmitOutputSourceMap.baseline b/tests/baselines/reference/getEmitOutputSourceMap.baseline index 553936bd91b..39cff967d89 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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; diff --git a/tests/baselines/reference/getEmitOutputSourceMap2.baseline b/tests/baselines/reference/getEmitOutputSourceMap2.baseline index 838a9a985eb..713aa4f3c08 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap2.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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; @@ -9,7 +9,7 @@ var M = (function () { return M; })(); //# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded +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"; diff --git a/tests/baselines/reference/getEmitOutputSourceRoot.baseline b/tests/baselines/reference/getEmitOutputSourceRoot.baseline index 880ad48ded3..5424def98ee 100644 --- a/tests/baselines/reference/getEmitOutputSourceRoot.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRoot.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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; diff --git a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline index 20ed671e8cf..7948ad99673 100644 --- a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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; @@ -9,7 +9,7 @@ var M = (function () { return M; })(); //# sourceMappingURL=inputFile1.js.map -EmitOutputStatus : Succeeded +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"; diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline index 0d9c3c16f55..4fda32ad7c4 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline index 03b466d4dde..4582af47f5a 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline @@ -1,6 +1,6 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile2.js var Foo = (function () { function Foo() { @@ -9,7 +9,7 @@ var Foo = (function () { })(); exports.Foo = Foo; -EmitOutputStatus : Succeeded +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 972d164af42..1ce3d9f33c3 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 5404e2e05e2..8dc9355bca2 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 d5bf626085e..f854a619a47 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline @@ -1,5 +1,4 @@ -EmitOutputStatus : EmitErrorsEncountered -Diagnostics: +EmitSkipped: false FileName : tests/cases/fourslash/inputFile.js var M; (function (M) { diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index 98df927aa4b..463dfe6899a 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -1,5 +1,4 @@ -EmitOutputStatus : EmitErrorsEncountered -Diagnostics: +EmitSkipped: false FileName : tests/cases/fourslash/inputFile.js define(["require", "exports"], function (require, exports) { var C = (function () { diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline index 6c263064ae3..b6249822131 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 78c279add04..396e220bdb6 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile.js var x = "hello world"; FileName : tests/cases/fourslash/inputFile.d.ts diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline index 2a0b26f47c8..7f012b6a546 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline index 7a6d61855ae..6a58015c1b3 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline index 224742eea3c..701b275eb31 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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 diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline index 967f792fb06..b66f83dc6b6 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +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. diff --git a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline index b6b40c5352c..2c341821fb0 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline @@ -1,4 +1,4 @@ -EmitOutputStatus : Succeeded +EmitSkipped: false FileName : tests/cases/fourslash/inputFile.js var x; diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 25f9fe6e145..50ec02ab6f3 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -25,8 +25,9 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void console.log(`${diagnostic.file.fileName} (${lineChar.line},${lineChar.character}): ${ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL)}`); }); - console.log(`Process exiting with code '${emitResult.emitResultStatus}'.`); - process.exit(emitResult.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_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}`); From f9d3b489f2eb5488824f03c8199018c66d83dfff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 17:11:06 -0800 Subject: [PATCH 22/26] Put curly on the right line. --- src/compiler/emitter.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3b3351ada69..103519c87e3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1508,8 +1508,7 @@ module ts { // @internal // 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 - { + 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; From c77f7327622181553667ac3e36892317c1060587 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 17:24:46 -0800 Subject: [PATCH 23/26] CR feedback. --- src/compiler/checker.ts | 6 +++--- src/compiler/core.ts | 12 ++++++------ src/compiler/program.ts | 8 ++++---- src/compiler/types.ts | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d1821d6067c..f8826da9614 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9598,7 +9598,7 @@ module ts { return diagnostics.getDiagnostics(); } - function getGlobalDiagnostics(): Diagnostic[]{ + function getGlobalDiagnostics(): Diagnostic[] { throwIfNonDiagnosticsProducing(); return diagnostics.getGlobalDiagnostics(); } @@ -9624,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) { @@ -10010,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; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index b82ca2f07af..d527b62005e 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -342,16 +342,16 @@ 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) || compareMessageText(d1.messageText, d2.messageText) || - 0; + Comparison.EqualTo; } - function compareMessageText(text1: string | DiagnosticMessageChain, text2: string | DiagnosticMessageChain): number { + 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; @@ -368,14 +368,14 @@ module ts { if (!text1 && !text2) { // if the chains are done, then these messages are the same. - return 0; + return Comparison.EqualTo; } // We still have one chain remaining. The shorter chain should come first. - return text1 ? 1 : -1; + return text1 ? Comparison.GreaterThan : Comparison.LessThan; } - export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] { + export function sortAndDeduplicateDiagnostics(diagnostics: Diagnostic[]): Diagnostic[]{ return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics)); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e933c54bc1e..954c443a77c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -165,7 +165,7 @@ module ts { return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false)); } - function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[]{ + function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] { var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile); return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); } @@ -206,11 +206,11 @@ module ts { return sortAndDeduplicateDiagnostics(allDiagnostics); } - function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ + function getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile); } - function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]{ + function getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[] { return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile); } @@ -229,7 +229,7 @@ module ts { return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } - function getGlobalDiagnostics(): Diagnostic[]{ + function getGlobalDiagnostics(): Diagnostic[] { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics: Diagnostic[] = []; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 23da074815a..fd675597ccd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1688,7 +1688,7 @@ module ts { // @internal export interface DiagnosticCollection { // Adds a diagnostic to this diagnostic collection. - add(diagnostic?: Diagnostic): void; + add(diagnostic: Diagnostic): void; // Gets all the diagnostics that aren't associated with a file. getGlobalDiagnostics(): Diagnostic[]; @@ -1697,7 +1697,7 @@ module ts { // Otherwise, returns all the diagnostics (global and file associated) in this colletion. getDiagnostics(fileName?: string): Diagnostic[]; - // Gets a count of how many times this collectoin has been modified. This value changes + // 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 From 6ed9741a7a2d9c34e27fcb9992aef50cf0130275 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 18:11:21 -0800 Subject: [PATCH 24/26] Extract common function. --- src/compiler/utilities.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ce8b5547f00..5a50e2799dc 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1109,11 +1109,15 @@ module ts { } var allDiagnostics: Diagnostic[] = []; - forEach(nonFileDiagnostics, d => { allDiagnostics.push(d) }); + function pushDiagnostic(d: Diagnostic) { + allDiagnostics.push(d); + } + + forEach(nonFileDiagnostics, pushDiagnostic); for (var key in fileDiagnostics) { if (hasProperty(fileDiagnostics, key)) { - forEach(fileDiagnostics[key], d => { allDiagnostics.push(d) }); + forEach(fileDiagnostics[key], pushDiagnostic); } } From 5c0b38b2032c8316ae1201ca72656809d656824e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 18:26:56 -0800 Subject: [PATCH 25/26] Remove getEnumMemberValue, it is now subsumed into getConstantValue. --- src/compiler/checker.ts | 9 ++++++--- src/compiler/emitter.ts | 6 +++--- src/compiler/types.ts | 6 ++---- src/services/services.ts | 2 +- .../baselines/reference/APISample_compile.js | 5 ++--- .../reference/APISample_compile.types | 20 +++++++++---------- tests/baselines/reference/APISample_linter.js | 5 ++--- .../reference/APISample_linter.types | 20 +++++++++---------- .../reference/APISample_transform.js | 5 ++--- .../reference/APISample_transform.types | 20 +++++++++---------- .../baselines/reference/APISample_watcher.js | 5 ++--- .../reference/APISample_watcher.types | 20 +++++++++---------- 12 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8826da9614..7c43b8bb233 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -50,7 +50,7 @@ module ts { getContextualType, getFullyQualifiedName, getResolvedSignature, - getEnumMemberValue, + getConstantValue, isValidPropertyAccess, getSignatureFromDeclaration, isImplementationOfOverload, @@ -10171,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; @@ -10210,7 +10214,6 @@ module ts { getExportAssignmentName, isReferencedImportDeclaration, getNodeCheckFlags, - getEnumMemberValue, isTopLevelValueImportWithEntityName, isDeclarationVisible, isImplementationOfOverload, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 103519c87e3..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()); @@ -1507,7 +1507,7 @@ module ts { } // @internal - // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature + // 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; @@ -3809,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; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fd675597ccd..1c79ef169e9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1032,8 +1032,7 @@ 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; @@ -1130,7 +1129,6 @@ module ts { isReferencedImportDeclaration(node: ImportDeclaration): boolean; isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; - getEnumMemberValue(node: EnumMember): number; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; @@ -1138,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; } diff --git a/src/services/services.ts b/src/services/services.ts index a39f59155f7..fad7632843a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3061,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)); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 23106996f12..6840f079972 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -817,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; } @@ -883,14 +883,13 @@ declare module "typescript" { isReferencedImportDeclaration(node: ImportDeclaration): boolean; isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; - getEnumMemberValue(node: EnumMember): number; 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 { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 18ca83b2114..d70172377ca 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2546,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 @@ -2836,11 +2838,6 @@ declare module "typescript" { >Node : Node >NodeCheckFlags : NodeCheckFlags - getEnumMemberValue(node: EnumMember): number; ->getEnumMemberValue : (node: EnumMember) => number ->node : EnumMember ->EnumMember : EnumMember - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -2892,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 diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 8f0dde9a9fa..c8bec722309 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -848,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; } @@ -914,14 +914,13 @@ declare module "typescript" { isReferencedImportDeclaration(node: ImportDeclaration): boolean; isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; - getEnumMemberValue(node: EnumMember): number; 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 { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index a0c2bc590ed..26254c69d54 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2690,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 @@ -2980,11 +2982,6 @@ declare module "typescript" { >Node : Node >NodeCheckFlags : NodeCheckFlags - getEnumMemberValue(node: EnumMember): number; ->getEnumMemberValue : (node: EnumMember) => number ->node : EnumMember ->EnumMember : EnumMember - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -3036,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 diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 542c79cb011..ad66d289eb7 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -849,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; } @@ -915,14 +915,13 @@ declare module "typescript" { isReferencedImportDeclaration(node: ImportDeclaration): boolean; isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; - getEnumMemberValue(node: EnumMember): number; 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 { diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 85fdfbe9c9d..c6d74cc811d 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2642,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 @@ -2932,11 +2934,6 @@ declare module "typescript" { >Node : Node >NodeCheckFlags : NodeCheckFlags - getEnumMemberValue(node: EnumMember): number; ->getEnumMemberValue : (node: EnumMember) => number ->node : EnumMember ->EnumMember : EnumMember - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -2988,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 diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index e932573e415..2add8dfd45e 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -886,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; } @@ -952,14 +952,13 @@ declare module "typescript" { isReferencedImportDeclaration(node: ImportDeclaration): boolean; isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; - getEnumMemberValue(node: EnumMember): number; 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 { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 12776adac5f..3af8537fdb7 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2815,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 @@ -3105,11 +3107,6 @@ declare module "typescript" { >Node : Node >NodeCheckFlags : NodeCheckFlags - getEnumMemberValue(node: EnumMember): number; ->getEnumMemberValue : (node: EnumMember) => number ->node : EnumMember ->EnumMember : EnumMember - isDeclarationVisible(node: Declaration): boolean; >isDeclarationVisible : (node: Declaration) => boolean >node : Declaration @@ -3161,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 From d20d20aa9c9b9ba4d7e4c6ff75c5351015c12969 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 5 Feb 2015 18:43:02 -0800 Subject: [PATCH 26/26] Remove "debugger;" calls. --- src/harness/compilerRunner.ts | 1 - src/harness/harness.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 250cd54e764..e4979f7a3c4 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -149,7 +149,6 @@ class CompilerBaselineRunner extends RunnerBase { // check errors it('Correct errors for ' + fileName, () => { - debugger; if (this.errors) { Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => { if (result.errors.length === 0) return null; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 866652e2e26..8002b019551 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -923,7 +923,6 @@ module Harness { // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file currentDirectory?: string) { - debugger; options = options || { noResolve: false }; options.target = options.target || ts.ScriptTarget.ES3; options.module = options.module || ts.ModuleKind.None; @@ -1083,7 +1082,6 @@ module Harness { (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), options.target, useCaseSensitiveFileNames, currentDirectory)); - debugger; var emitResult = program.emit(); var errors: HarnessDiagnostic[] = [];