From ca5d243ca7afdad7c51cb9378ccf44b1663fcd06 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 17 Dec 2014 15:49:00 -0800 Subject: [PATCH 01/11] Added test from original issue. --- ...leWithPriorUninstantiatedModule.errors.txt | 21 ++++++++++++ .../cloduleWithPriorUninstantiatedModule.js | 33 +++++++++++++++++++ .../cloduleWithPriorUninstantiatedModule.ts | 15 +++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt create mode 100644 tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js create mode 100644 tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt new file mode 100644 index 00000000000..cae69212f2f --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts(2,8): error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + + +==== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts (1 errors) ==== + // Ambient/uninstantiated module. + module Moclodule { + ~~~~~~~~~ +!!! error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + export interface Someinterface { + foo(): void; + } + } + + class Moclodule { + } + + // Instantiated module. + module Moclodule { + export class Manager { + } + } \ No newline at end of file diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js new file mode 100644 index 00000000000..37bfb617375 --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js @@ -0,0 +1,33 @@ +//// [cloduleWithPriorUninstantiatedModule.ts] +// Ambient/uninstantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} + +//// [cloduleWithPriorUninstantiatedModule.js] +var Moclodule = (function () { + function Moclodule() { + } + return Moclodule; +})(); +// Instantiated module. +var Moclodule; +(function (Moclodule) { + var Manager = (function () { + function Manager() { + } + return Manager; + })(); + Moclodule.Manager = Manager; +})(Moclodule || (Moclodule = {})); diff --git a/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts new file mode 100644 index 00000000000..8c9c646b687 --- /dev/null +++ b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts @@ -0,0 +1,15 @@ +// Ambient/uninstantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} \ No newline at end of file From fac52017653a97a2c95013b76c8d62a55bf228a7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 17 Dec 2014 17:00:42 -0800 Subject: [PATCH 02/11] Only error on non-ambient instantiated modules preceding clodules. --- src/compiler/checker.ts | 9 ++++++- src/compiler/emitter.ts | 4 +-- src/compiler/utilities.ts | 6 +++++ ...leWithPriorUninstantiatedModule.errors.txt | 21 ---------------- ...cloduleWithPriorUninstantiatedModule.types | 25 +++++++++++++++++++ 5 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt create mode 100644 tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ccc67ba3881..e5334c454d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9003,7 +9003,12 @@ module ts { checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node)) { + + // The following checks only apply on a non-ambient instantiated module declaration. + if (symbol.flags & SymbolFlags.ValueModule + && symbol.declarations.length > 1 + && !isInAmbientContext(node) + && isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) { @@ -9014,6 +9019,8 @@ module ts { } } } + + // Checks for ambient external modules. if (node.name.kind === SyntaxKind.StringLiteral) { if (!isGlobalSourceFile(node.parent)) { error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b713fddf676..005c7aa5f15 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3680,8 +3680,8 @@ module ts { } function emitModuleDeclaration(node: ModuleDeclaration) { - var shouldEmit = getModuleInstanceState(node) === ModuleInstanceState.Instantiated || - (getModuleInstanceState(node) === ModuleInstanceState.ConstEnumOnly && compilerOptions.preserveConstEnums); + // Emit only if this module is non-ambient. + var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bbe4d7dbf35..114e1dae1b3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -525,6 +525,12 @@ module ts { return false; } + export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { + var moduleState = getModuleInstanceState(node) + return moduleState === ModuleInstanceState.Instantiated || + (preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly); + } + export function isExternalModuleImportDeclaration(node: Node) { return node.kind === SyntaxKind.ImportDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference; } diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt deleted file mode 100644 index cae69212f2f..00000000000 --- a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts(2,8): error TS2434: A module declaration cannot be located prior to a class or function with which it is merged - - -==== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts (1 errors) ==== - // Ambient/uninstantiated module. - module Moclodule { - ~~~~~~~~~ -!!! error TS2434: A module declaration cannot be located prior to a class or function with which it is merged - export interface Someinterface { - foo(): void; - } - } - - class Moclodule { - } - - // Instantiated module. - module Moclodule { - export class Manager { - } - } \ No newline at end of file diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types new file mode 100644 index 00000000000..1ab286b5964 --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts === +// Ambient/uninstantiated module. +module Moclodule { +>Moclodule : typeof Moclodule + + export interface Someinterface { +>Someinterface : Someinterface + + foo(): void; +>foo : () => void + } +} + +class Moclodule { +>Moclodule : Moclodule +} + +// Instantiated module. +module Moclodule { +>Moclodule : typeof Moclodule + + export class Manager { +>Manager : Manager + } +} From 46cd90daf080b2f8e3bd88cb7eda4193e4a05fc9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 17 Dec 2014 17:05:05 -0800 Subject: [PATCH 03/11] Added test, modified test, updated baselines. --- ...duleWithPriorInstantiatedModule.errors.txt | 22 +++++++++++ .../cloduleWithPriorInstantiatedModule.js | 39 +++++++++++++++++++ .../cloduleWithPriorUninstantiatedModule.js | 2 +- ...cloduleWithPriorUninstantiatedModule.types | 2 +- .../cloduleWithPriorInstantiatedModule.ts | 16 ++++++++ .../cloduleWithPriorUninstantiatedModule.ts | 2 +- 6 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt create mode 100644 tests/baselines/reference/cloduleWithPriorInstantiatedModule.js create mode 100644 tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts diff --git a/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt new file mode 100644 index 00000000000..1b0d9cf13ca --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts(2,8): error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + + +==== tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts (1 errors) ==== + // Non-ambient & instantiated module. + module Moclodule { + ~~~~~~~~~ +!!! error TS2434: A module declaration cannot be located prior to a class or function with which it is merged + export interface Someinterface { + foo(): void; + } + var x = 10; + } + + class Moclodule { + } + + // Instantiated module. + module Moclodule { + export class Manager { + } + } \ No newline at end of file diff --git a/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js new file mode 100644 index 00000000000..601ab0a7536 --- /dev/null +++ b/tests/baselines/reference/cloduleWithPriorInstantiatedModule.js @@ -0,0 +1,39 @@ +//// [cloduleWithPriorInstantiatedModule.ts] +// Non-ambient & instantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } + var x = 10; +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} + +//// [cloduleWithPriorInstantiatedModule.js] +// Non-ambient & instantiated module. +var Moclodule; +(function (Moclodule) { + var x = 10; +})(Moclodule || (Moclodule = {})); +var Moclodule = (function () { + function Moclodule() { + } + return Moclodule; +})(); +// Instantiated module. +var Moclodule; +(function (Moclodule) { + var Manager = (function () { + function Manager() { + } + return Manager; + })(); + Moclodule.Manager = Manager; +})(Moclodule || (Moclodule = {})); diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js index 37bfb617375..cf06f1134fb 100644 --- a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.js @@ -1,5 +1,5 @@ //// [cloduleWithPriorUninstantiatedModule.ts] -// Ambient/uninstantiated module. +// Non-ambient & uninstantiated module. module Moclodule { export interface Someinterface { foo(): void; diff --git a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types index 1ab286b5964..8dc14646a6b 100644 --- a/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types +++ b/tests/baselines/reference/cloduleWithPriorUninstantiatedModule.types @@ -1,5 +1,5 @@ === tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts === -// Ambient/uninstantiated module. +// Non-ambient & uninstantiated module. module Moclodule { >Moclodule : typeof Moclodule diff --git a/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts b/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts new file mode 100644 index 00000000000..c6423ce41a7 --- /dev/null +++ b/tests/cases/compiler/cloduleWithPriorInstantiatedModule.ts @@ -0,0 +1,16 @@ +// Non-ambient & instantiated module. +module Moclodule { + export interface Someinterface { + foo(): void; + } + var x = 10; +} + +class Moclodule { +} + +// Instantiated module. +module Moclodule { + export class Manager { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts index 8c9c646b687..0c603b71a4d 100644 --- a/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts +++ b/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts @@ -1,4 +1,4 @@ -// Ambient/uninstantiated module. +// Non-ambient & uninstantiated module. module Moclodule { export interface Someinterface { foo(): void; From d907f99693aac97f714fef0c72af433326ad681a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 22 Dec 2014 13:58:14 -0800 Subject: [PATCH 04/11] Moved EmitHost to types.ts so that utilities can be edited as a standalone file through dependency resolution. --- src/compiler/emitter.ts | 13 +------------ src/compiler/types.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 237f3ab509a..1065a1e0e60 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1461,18 +1461,7 @@ module ts { referencePathsOutput, } } - - export interface EmitHost extends ScriptReferenceHost { - getSourceFiles(): SourceFile[]; - isEmitBlocked(sourceFile?: SourceFile): boolean; - - getCommonSourceDirectory(): string; - getCanonicalFileName(fileName: string): string; - getNewLine(): string; - - writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; - } - + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { var diagnostics: Diagnostic[] = []; var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cc1b37aef5d..f95200c4cb3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -951,6 +951,18 @@ module ts { isEmitBlocked(sourceFile?: SourceFile): boolean; } + export interface EmitHost extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + + getCommonSourceDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + + writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } + + export interface SourceMapSpan { emittedLine: number; // Line number in the .js file emittedColumn: number; // Column number in the .js file From 8aefbe9a86999654a0b4858ecf6db9a13cd37ac0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 22 Dec 2014 14:02:40 -0800 Subject: [PATCH 05/11] Removed newline. --- src/compiler/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f95200c4cb3..dbdd71ed363 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -962,7 +962,6 @@ module ts { writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; } - export interface SourceMapSpan { emittedLine: number; // Line number in the .js file emittedColumn: number; // Column number in the .js file From 363587163b4e83d6e6abdf92ce3f96653fca1e65 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 2 Jan 2015 12:14:02 -0800 Subject: [PATCH 06/11] extract map copying logic to a separate function --- src/compiler/checker.ts | 4 +--- src/compiler/core.ts | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8c4caa9630..351f5188748 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3651,9 +3651,7 @@ module ts { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1]; - for (var p in maybeCache) { - destinationCache[p] = maybeCache[p]; - } + copyMap(maybeCache, destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 4ba93729c36..2e5a471bb27 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -208,6 +208,12 @@ module ts { return result; } + export function copyMap(source: Map, target: Map): void { + for (var p in source) { + target[p] = source[p]; + } + } + /** * Creates a map from the elements of an array. * From 06258b8c106385924077c4a17d908114612dea0b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 5 Jan 2015 11:48:46 -0800 Subject: [PATCH 07/11] added parameter names to 'copymap' call site --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 351f5188748..2911322052d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3651,7 +3651,7 @@ module ts { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1]; - copyMap(maybeCache, destinationCache); + copyMap(/*source*/maybeCache, /*target*/destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it From b442d14e440cd3db7a797016e9b11de2b3f12cb3 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Tue, 6 Jan 2015 15:28:06 -0800 Subject: [PATCH 08/11] Don't emit an empty template head literal if there's a template span with a non-empty literal. Fixes #1570 --- src/compiler/emitter.ts | 43 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f3e45a85b6a..ba32e46065e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2068,9 +2068,15 @@ module ts { write("("); } - emitLiteral(node.head); + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + + for (var i = 0; i < node.templateSpans.length; i++) { + var templateSpan = node.templateSpans[i]; - forEach(node.templateSpans, templateSpan => { // Check if the expression has operands and binds its operands less closely than binary '+'. // If it does, we need to wrap the expression in parentheses. Otherwise, something like // `abc${ 1 << 2 }` @@ -2082,7 +2088,14 @@ module ts { // "abc" + (1 << 2) + "" var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenthesizedExpression && comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; - write(" + "); + + if (i > 0 || headEmitted) { + // If this is the first span and the head was not emitted, then this templateSpan's + // expression will be the first to be emitted. Don't emit the preceding ' + ' in that + // case. + write(" + "); + } + emitParenthesized(templateSpan.expression, needsParens); // Only emit if the literal is non-empty. // The binary '+' operator is left-associative, so the first string concatenation @@ -2092,12 +2105,34 @@ module ts { write(" + ") emitLiteral(templateSpan.literal); } - }); + } if (emitOuterParens) { write(")"); } + function shouldEmitTemplateHead() { + // If this expression has an empty head literal and the first template span has a non-empty + // literal, then emitting the empty head literal is not necessary. + // `${ foo } and ${ bar }` + // can be emitted as + // foo + " and " + bar + // This is because it is only required that one of the first two operands in the emit + // output must be a string literal, so that the other operand and all following operands + // are forced into strings. + // + // If the first template span has an empty literal, then the head must still be emitted. + // `${ foo }${ bar }` + // must still be emitted as + // "" + foo + bar + + // There is always atleast one templateSpan in this code path, since + // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() + Debug.assert(node.templateSpans.length !== 0); + + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template: TemplateExpression, parent: Expression) { switch (parent.kind) { case SyntaxKind.CallExpression: From d07151f87c81247a45d3844c8b079d9c30472884 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Tue, 6 Jan 2015 15:28:06 -0800 Subject: [PATCH 09/11] Update tests and baselines. --- .../templateStringBinaryOperations.js | 24 +++++----- .../templateStringBinaryOperationsInvalid.js | 48 +++++++++---------- .../templateStringWithEmptyLiteralPortions.js | 12 +++-- ...mplateStringWithEmptyLiteralPortions.types | 5 +- ...mplateStringWithEmptyLiteralPortionsES6.js | 8 +++- ...ateStringWithEmptyLiteralPortionsES6.types | 5 +- .../templateStringWithEmptyLiteralPortions.ts | 4 +- ...mplateStringWithEmptyLiteralPortionsES6.ts | 4 +- 8 files changed, 64 insertions(+), 46 deletions(-) diff --git a/tests/baselines/reference/templateStringBinaryOperations.js b/tests/baselines/reference/templateStringBinaryOperations.js index d155ba9eedd..691dad41f77 100644 --- a/tests/baselines/reference/templateStringBinaryOperations.js +++ b/tests/baselines/reference/templateStringBinaryOperations.js @@ -55,49 +55,49 @@ var l4 = 1 + `2${ 3 & 4 }5` + 6; //// [templateStringBinaryOperations.js] var a = 1 + ("" + 3); var b = 1 + ("2" + 3); -var c = 1 + ("" + 3 + "4"); +var c = 1 + (3 + "4"); var d = 1 + ("2" + 3 + "4"); var e = ("" + 3) + 5; var f = ("2" + 3) + 5; -var g = ("" + 3 + "4") + 5; +var g = (3 + "4") + 5; var h = ("2" + 3 + "4") + 5; var i = 1 + ("" + 3) + 5; var j = 1 + ("2" + 3) + 5; -var k = 1 + ("" + 3 + "4") + 5; +var k = 1 + (3 + "4") + 5; var l = 1 + ("2" + 3 + "4") + 5; var a2 = 1 + ("" + (3 - 4)); var b2 = 1 + ("2" + (3 - 4)); -var c2 = 1 + ("" + (3 - 4) + "5"); +var c2 = 1 + ((3 - 4) + "5"); var d2 = 1 + ("2" + (3 - 4) + "5"); var e2 = ("" + (3 - 4)) + 6; var f2 = ("2" + (3 - 4)) + 6; -var g2 = ("" + (3 - 4) + "5") + 6; +var g2 = ((3 - 4) + "5") + 6; var h2 = ("2" + (3 - 4) + "5") + 6; var i2 = 1 + ("" + (3 - 4)) + 6; var j2 = 1 + ("2" + (3 - 4)) + 6; -var k2 = 1 + ("" + (3 - 4) + "5") + 6; +var k2 = 1 + ((3 - 4) + "5") + 6; var l2 = 1 + ("2" + (3 - 4) + "5") + 6; var a3 = 1 + ("" + 3 * 4); var b3 = 1 + ("2" + 3 * 4); -var c3 = 1 + ("" + 3 * 4 + "5"); +var c3 = 1 + (3 * 4 + "5"); var d3 = 1 + ("2" + 3 * 4 + "5"); var e3 = ("" + 3 * 4) + 6; var f3 = ("2" + 3 * 4) + 6; -var g3 = ("" + 3 * 4 + "5") + 6; +var g3 = (3 * 4 + "5") + 6; var h3 = ("2" + 3 * 4 + "5") + 6; var i3 = 1 + ("" + 3 * 4) + 6; var j3 = 1 + ("2" + 3 * 4) + 6; -var k3 = 1 + ("" + 3 * 4 + "5") + 6; +var k3 = 1 + (3 * 4 + "5") + 6; var l3 = 1 + ("2" + 3 * 4 + "5") + 6; var a4 = 1 + ("" + (3 & 4)); var b4 = 1 + ("2" + (3 & 4)); -var c4 = 1 + ("" + (3 & 4) + "5"); +var c4 = 1 + ((3 & 4) + "5"); var d4 = 1 + ("2" + (3 & 4) + "5"); var e4 = ("" + (3 & 4)) + 6; var f4 = ("2" + (3 & 4)) + 6; -var g4 = ("" + (3 & 4) + "5") + 6; +var g4 = ((3 & 4) + "5") + 6; var h4 = ("2" + (3 & 4) + "5") + 6; var i4 = 1 + ("" + (3 & 4)) + 6; var j4 = 1 + ("2" + (3 & 4)) + 6; -var k4 = 1 + ("" + (3 & 4) + "5") + 6; +var k4 = 1 + ((3 & 4) + "5") + 6; var l4 = 1 + ("2" + (3 & 4) + "5") + 6; diff --git a/tests/baselines/reference/templateStringBinaryOperationsInvalid.js b/tests/baselines/reference/templateStringBinaryOperationsInvalid.js index 1edf1d3a563..f8c0344f44b 100644 --- a/tests/baselines/reference/templateStringBinaryOperationsInvalid.js +++ b/tests/baselines/reference/templateStringBinaryOperationsInvalid.js @@ -111,97 +111,97 @@ var hc = `2${ 3 & 4 }5` & 6; //// [templateStringBinaryOperationsInvalid.js] var a = 1 - ("" + 3); var b = 1 - ("2" + 3); -var c = 1 - ("" + 3 + "4"); +var c = 1 - (3 + "4"); var d = 1 - ("2" + 3 + "4"); var e = ("" + 3) - 5; var f = ("2" + 3) - 5; -var g = ("" + 3 + "4") - 5; +var g = (3 + "4") - 5; var h = ("2" + 3 + "4") - 5; var a2 = 1 * ("" + 3); var b2 = 1 * ("2" + 3); -var c2 = 1 * ("" + 3 + "4"); +var c2 = 1 * (3 + "4"); var d2 = 1 * ("2" + 3 + "4"); var e2 = ("" + 3) * 5; var f2 = ("2" + 3) * 5; -var g2 = ("" + 3 + "4") * 5; +var g2 = (3 + "4") * 5; var h2 = ("2" + 3 + "4") * 5; var a3 = 1 & "" + 3; var b3 = 1 & "2" + 3; -var c3 = 1 & "" + 3 + "4"; +var c3 = 1 & 3 + "4"; var d3 = 1 & "2" + 3 + "4"; var e3 = "" + 3 & 5; var f3 = "2" + 3 & 5; -var g3 = "" + 3 + "4" & 5; +var g3 = 3 + "4" & 5; var h3 = "2" + 3 + "4" & 5; var a4 = 1 - ("" + (3 - 4)); var b4 = 1 - ("2" + (3 - 4)); -var c4 = 1 - ("" + (3 - 4) + "5"); +var c4 = 1 - ((3 - 4) + "5"); var d4 = 1 - ("2" + (3 - 4) + "5"); var e4 = ("" + (3 - 4)) - 6; var f4 = ("2" + (3 - 4)) - 6; -var g4 = ("" + (3 - 4) + "5") - 6; +var g4 = ((3 - 4) + "5") - 6; var h4 = ("2" + (3 - 4) + "5") - 6; var a5 = 1 - ("" + 3 * 4); var b5 = 1 - ("2" + 3 * 4); -var c5 = 1 - ("" + 3 * 4 + "5"); +var c5 = 1 - (3 * 4 + "5"); var d5 = 1 - ("2" + 3 * 4 + "5"); var e5 = ("" + 3 * 4) - 6; var f5 = ("2" + 3 * 4) - 6; -var g5 = ("" + 3 * 4 + "5") - 6; +var g5 = (3 * 4 + "5") - 6; var h5 = ("2" + 3 * 4 + "5") - 6; var a6 = 1 - ("" + (3 & 4)); var b6 = 1 - ("2" + (3 & 4)); -var c6 = 1 - ("" + (3 & 4) + "5"); +var c6 = 1 - ((3 & 4) + "5"); var d6 = 1 - ("2" + (3 & 4) + "5"); var e6 = ("" + (3 & 4)) - 6; var f6 = ("2" + (3 & 4)) - 6; -var g6 = ("" + (3 & 4) + "5") - 6; +var g6 = ((3 & 4) + "5") - 6; var h6 = ("2" + (3 & 4) + "5") - 6; var a7 = 1 * ("" + (3 - 4)); var b7 = 1 * ("2" + (3 - 4)); -var c7 = 1 * ("" + (3 - 4) + "5"); +var c7 = 1 * ((3 - 4) + "5"); var d7 = 1 * ("2" + (3 - 4) + "5"); var e7 = ("" + (3 - 4)) * 6; var f7 = ("2" + (3 - 4)) * 6; -var g7 = ("" + (3 - 4) + "5") * 6; +var g7 = ((3 - 4) + "5") * 6; var h7 = ("2" + (3 - 4) + "5") * 6; var a8 = 1 * ("" + 3 * 4); var b8 = 1 * ("2" + 3 * 4); -var c8 = 1 * ("" + 3 * 4 + "5"); +var c8 = 1 * (3 * 4 + "5"); var d8 = 1 * ("2" + 3 * 4 + "5"); var e8 = ("" + 3 * 4) * 6; var f8 = ("2" + 3 * 4) * 6; -var g8 = ("" + 3 * 4 + "5") * 6; +var g8 = (3 * 4 + "5") * 6; var h8 = ("2" + 3 * 4 + "5") * 6; var a9 = 1 * ("" + (3 & 4)); var b9 = 1 * ("2" + (3 & 4)); -var c9 = 1 * ("" + (3 & 4) + "5"); +var c9 = 1 * ((3 & 4) + "5"); var d9 = 1 * ("2" + (3 & 4) + "5"); var e9 = ("" + (3 & 4)) * 6; var f9 = ("2" + (3 & 4)) * 6; -var g9 = ("" + (3 & 4) + "5") * 6; +var g9 = ((3 & 4) + "5") * 6; var h9 = ("2" + (3 & 4) + "5") * 6; var aa = 1 & "" + (3 - 4); var ba = 1 & "2" + (3 - 4); -var ca = 1 & "" + (3 - 4) + "5"; +var ca = 1 & (3 - 4) + "5"; var da = 1 & "2" + (3 - 4) + "5"; var ea = "" + (3 - 4) & 6; var fa = "2" + (3 - 4) & 6; -var ga = "" + (3 - 4) + "5" & 6; +var ga = (3 - 4) + "5" & 6; var ha = "2" + (3 - 4) + "5" & 6; var ab = 1 & "" + 3 * 4; var bb = 1 & "2" + 3 * 4; -var cb = 1 & "" + 3 * 4 + "5"; +var cb = 1 & 3 * 4 + "5"; var db = 1 & "2" + 3 * 4 + "5"; var eb = "" + 3 * 4 & 6; var fb = "2" + 3 * 4 & 6; -var gb = "" + 3 * 4 + "5" & 6; +var gb = 3 * 4 + "5" & 6; var hb = "2" + 3 * 4 + "5" & 6; var ac = 1 & "" + (3 & 4); var bc = 1 & "2" + (3 & 4); -var cc = 1 & "" + (3 & 4) + "5"; +var cc = 1 & (3 & 4) + "5"; var dc = 1 & "2" + (3 & 4) + "5"; var ec = "" + (3 & 4) & 6; var fc = "2" + (3 & 4) & 6; -var gc = "" + (3 & 4) + "5" & 6; +var gc = (3 & 4) + "5" & 6; var hc = "2" + (3 & 4) + "5" & 6; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js index 8bc6e2c4206..e7a35d76f45 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js @@ -21,18 +21,22 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; + //// [templateStringWithEmptyLiteralPortions.js] var a = ""; var b = "" + 0; var c = "1" + 0; -var d = "" + 0 + "2"; +var d = 0 + "2"; var e = "1" + 0 + "2"; var f = "" + 0 + 0; var g = "1" + 0 + 0; -var h = "" + 0 + "2" + 0; +var h = 0 + "2" + 0; var i = "1" + 0 + "2" + 0; var j = "" + 0 + 0 + "3"; var k = "1" + 0 + 0 + "3"; -var l = "1" + 0 + "2" + 0 + "3"; +var l = 0 + "2" + 0 + "3"; +var m = "1" + 0 + "2" + 0 + "3"; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types index a44bab8fe44..c901d674306 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types @@ -32,6 +32,9 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; >k : string -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; >l : string +var m = `1${ 0 }2${ 0 }3`; +>m : string + diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js index f0e827cde63..fe1bce291f0 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js @@ -21,7 +21,10 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; + //// [templateStringWithEmptyLiteralPortionsES6.js] var a = ``; @@ -35,4 +38,5 @@ var h = `${0}2${0}`; var i = `1${0}2${0}`; var j = `${0}${0}3`; var k = `1${0}${0}3`; -var l = `1${0}2${0}3`; +var l = `${0}2${0}3`; +var m = `1${0}2${0}3`; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types index 4074831d410..d70dd29e4da 100644 --- a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types @@ -32,6 +32,9 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; >k : string -var l = `1${ 0 }2${ 0 }3`; +var l = `${ 0 }2${ 0 }3`; >l : string +var m = `1${ 0 }2${ 0 }3`; +>m : string + diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts index 11dca4caf77..9191ca1934c 100644 --- a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts @@ -20,4 +20,6 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts index 183da57dd45..ff178d22432 100644 --- a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts @@ -21,4 +21,6 @@ var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; -var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file +var l = `${ 0 }2${ 0 }3`; + +var m = `1${ 0 }2${ 0 }3`; From 01218f86ffe2ed6002016a1f3bf3b91bb118830f Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 6 Jan 2015 17:55:54 -0800 Subject: [PATCH 10/11] consider type parameters always visible --- src/compiler/checker.ts | 5 ++-- .../reference/visibilityOfTypeParameters.js | 24 +++++++++++++++++++ .../visibilityOfTypeParameters.types | 16 +++++++++++++ .../compiler/visibilityOfTypeParameters.ts | 8 +++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/visibilityOfTypeParameters.js create mode 100644 tests/baselines/reference/visibilityOfTypeParameters.types create mode 100644 tests/cases/compiler/visibilityOfTypeParameters.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e07c0eb237e..9849e740e9d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1575,7 +1575,6 @@ module ts { case SyntaxKind.IndexSignature: case SyntaxKind.Parameter: case SyntaxKind.ModuleBlock: - case SyntaxKind.TypeParameter: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.TypeLiteral: @@ -1585,7 +1584,9 @@ module ts { case SyntaxKind.UnionType: case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); - + + // Type parameters are always visible + case SyntaxKind.TypeParameter: // Source file is always visible case SyntaxKind.SourceFile: return true; diff --git a/tests/baselines/reference/visibilityOfTypeParameters.js b/tests/baselines/reference/visibilityOfTypeParameters.js new file mode 100644 index 00000000000..2cb006737b2 --- /dev/null +++ b/tests/baselines/reference/visibilityOfTypeParameters.js @@ -0,0 +1,24 @@ +//// [visibilityOfTypeParameters.ts] + +export class MyClass { + protected myMethod(val: T): T { + return val; + } +} + +//// [visibilityOfTypeParameters.js] +var MyClass = (function () { + function MyClass() { + } + MyClass.prototype.myMethod = function (val) { + return val; + }; + return MyClass; +})(); +exports.MyClass = MyClass; + + +//// [visibilityOfTypeParameters.d.ts] +export declare class MyClass { + protected myMethod(val: T): T; +} diff --git a/tests/baselines/reference/visibilityOfTypeParameters.types b/tests/baselines/reference/visibilityOfTypeParameters.types new file mode 100644 index 00000000000..60a9330eb7e --- /dev/null +++ b/tests/baselines/reference/visibilityOfTypeParameters.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/visibilityOfTypeParameters.ts === + +export class MyClass { +>MyClass : MyClass + + protected myMethod(val: T): T { +>myMethod : (val: T) => T +>T : T +>val : T +>T : T +>T : T + + return val; +>val : T + } +} diff --git a/tests/cases/compiler/visibilityOfTypeParameters.ts b/tests/cases/compiler/visibilityOfTypeParameters.ts new file mode 100644 index 00000000000..386d0bb9cb4 --- /dev/null +++ b/tests/cases/compiler/visibilityOfTypeParameters.ts @@ -0,0 +1,8 @@ +// @module:commonjs +//@declaration: true + +export class MyClass { + protected myMethod(val: T): T { + return val; + } +} \ No newline at end of file From 06d65c797d91816d4c7b5bfe4f25ee1c01dd9691 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 7 Jan 2015 12:37:46 -0800 Subject: [PATCH 11/11] Moved EmitHost to utilities.ts --- src/compiler/types.ts | 11 ----------- src/compiler/utilities.ts | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dbdd71ed363..cc1b37aef5d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -951,17 +951,6 @@ module ts { isEmitBlocked(sourceFile?: SourceFile): boolean; } - export interface EmitHost extends ScriptReferenceHost { - getSourceFiles(): SourceFile[]; - isEmitBlocked(sourceFile?: SourceFile): boolean; - - getCommonSourceDirectory(): string; - getCanonicalFileName(fileName: string): string; - getNewLine(): string; - - writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; - } - export interface SourceMapSpan { emittedLine: number; // Line number in the .js file emittedColumn: number; // Column number in the .js file diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index edd8bf156cf..9686622decb 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -23,6 +23,17 @@ module ts { string(): string; } + export interface EmitHost extends ScriptReferenceHost { + getSourceFiles(): SourceFile[]; + isEmitBlocked(sourceFile?: SourceFile): boolean; + + getCommonSourceDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + + writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; + } + // Pool writers to avoid needing to allocate them for every symbol we write. var stringWriters: StringSymbolWriter[] = []; export function getSingleLineStringWriter(): StringSymbolWriter {