From 42d61b5098ac5847b5e09117cf92092c6dc9f284 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 8 Aug 2016 11:55:59 -0700 Subject: [PATCH 01/56] Call checkExpression eventhough there is no appropriate type from destructuring of array --- src/compiler/checker.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ead19f7c48..74a1e17bd6b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4447,9 +4447,14 @@ namespace ts { return property; } - // Return the symbol for the property with the given name in the given type. Creates synthetic union properties when - // necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from - // Object and Function as appropriate. + /** + * Return the symbol for the property with the given name in the given type. Creates synthetic union properties when + * necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from + * Object and Function as appropriate. + * + * @param type a type to look up property from + * @param name a name of property to look up in a given type + */ function getPropertyOfType(type: Type, name: string): Symbol { type = getApparentType(type); if (type.flags & TypeFlags.ObjectType) { @@ -12856,6 +12861,9 @@ namespace ts { return checkDestructuringAssignment(element, type, contextualMapper); } else { + // We still need to check element expression here because we may need to set appropriate flag on the expression + // such as NodeCheckFlags.LexicalThis on "this"expression. + checkExpression(element); if (isTupleType(sourceType)) { error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), (sourceType).elementTypes.length, elements.length); } From 9a18429184a42f6a34a963908acdc141245d1ade Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 8 Aug 2016 11:56:20 -0700 Subject: [PATCH 02/56] Add tests and baselines --- ...turingThisInTupleDestructuring1.errors.txt | 13 +++++++++++ .../emitCapturingThisInTupleDestructuring1.js | 11 +++++++++ ...turingThisInTupleDestructuring2.errors.txt | 16 +++++++++++++ .../emitCapturingThisInTupleDestructuring2.js | 23 +++++++++++++++++++ .../emitCapturingThisInTupleDestructuring1.ts | 4 ++++ .../emitCapturingThisInTupleDestructuring2.ts | 10 ++++++++ 6 files changed, 77 insertions(+) create mode 100644 tests/baselines/reference/emitCapturingThisInTupleDestructuring1.errors.txt create mode 100644 tests/baselines/reference/emitCapturingThisInTupleDestructuring1.js create mode 100644 tests/baselines/reference/emitCapturingThisInTupleDestructuring2.errors.txt create mode 100644 tests/baselines/reference/emitCapturingThisInTupleDestructuring2.js create mode 100644 tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts create mode 100644 tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.errors.txt b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.errors.txt new file mode 100644 index 00000000000..d0f11d056ca --- /dev/null +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts(3,17): error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'. +tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts(3,29): error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'. + + +==== tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts (2 errors) ==== + declare function wrapper(x: any); + wrapper((array: [any]) => { + [this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this" + ~~~~~~~~~~ +!!! error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'. + ~~~~~~~~~~ +!!! error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'. + }); \ No newline at end of file diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.js b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.js new file mode 100644 index 00000000000..9dd7453ba4f --- /dev/null +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.js @@ -0,0 +1,11 @@ +//// [emitCapturingThisInTupleDestructuring1.ts] +declare function wrapper(x: any); +wrapper((array: [any]) => { + [this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this" +}); + +//// [emitCapturingThisInTupleDestructuring1.js] +var _this = this; +wrapper(function (array) { + _this.test = array[0], _this.test1 = array[1], _this.test2 = array[2]; // even though there is a compiler error, we should still emit lexical capture for "this" +}); diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.errors.txt b/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.errors.txt new file mode 100644 index 00000000000..25207e28c79 --- /dev/null +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts(8,39): error TS2493: Tuple type '[number, number]' with length '2' cannot be assigned to tuple with length '3'. + + +==== tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts (1 errors) ==== + var array1: [number, number] = [1, 2]; + + class B { + test: number; + test1: any; + test2: any; + method() { + () => [this.test, this.test1, this.test2] = array1; // even though there is a compiler error, we should still emit lexical capture for "this" + ~~~~~~~~~~ +!!! error TS2493: Tuple type '[number, number]' with length '2' cannot be assigned to tuple with length '3'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.js b/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.js new file mode 100644 index 00000000000..f999cfe70f0 --- /dev/null +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring2.js @@ -0,0 +1,23 @@ +//// [emitCapturingThisInTupleDestructuring2.ts] +var array1: [number, number] = [1, 2]; + +class B { + test: number; + test1: any; + test2: any; + method() { + () => [this.test, this.test1, this.test2] = array1; // even though there is a compiler error, we should still emit lexical capture for "this" + } +} + +//// [emitCapturingThisInTupleDestructuring2.js] +var array1 = [1, 2]; +var B = (function () { + function B() { + } + B.prototype.method = function () { + var _this = this; + (function () { return (_this.test = array1[0], _this.test1 = array1[1], _this.test2 = array1[2], array1); }); // even though there is a compiler error, we should still emit lexical capture for "this" + }; + return B; +}()); diff --git a/tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts b/tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts new file mode 100644 index 00000000000..e369cd9fb50 --- /dev/null +++ b/tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts @@ -0,0 +1,4 @@ +declare function wrapper(x: any); +wrapper((array: [any]) => { + [this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this" +}); \ No newline at end of file diff --git a/tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts b/tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts new file mode 100644 index 00000000000..2bb931c4f4f --- /dev/null +++ b/tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts @@ -0,0 +1,10 @@ +var array1: [number, number] = [1, 2]; + +class B { + test: number; + test1: any; + test2: any; + method() { + () => [this.test, this.test1, this.test2] = array1; // even though there is a compiler error, we should still emit lexical capture for "this" + } +} \ No newline at end of file From f16d599f79457fee725b942d1e0ca13176950d05 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 9 Aug 2016 15:54:44 -0700 Subject: [PATCH 03/56] Issues an error when there are more than one export default --- src/compiler/binder.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8d8666a67ab..1eedc4535dc 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -337,8 +337,18 @@ namespace ts { ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; + // If the current node has NodeFlags.Default (e.g. if the node is class declaration or function declaration) + // and there is already another default export (i.e. symbol.declarations is not empty), we need to report such error + if (isDefaultExport && symbol.declarations) { + message = Diagnostics.A_module_cannot_have_multiple_default_exports; + } + forEach(symbol.declarations, declaration => { - if (declaration.flags & NodeFlags.Default) { + // Error on multiple export default in the following case: + // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default + // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) + if ((declaration.flags & NodeFlags.Default) || + (declaration.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; } }); @@ -1898,7 +1908,9 @@ namespace ts { } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); + // We want to exclude both class and function here, this is necessary to issue an error when there are both + // default export-assignment and default export function and class declaration. + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.Class | SymbolFlags.Function | SymbolFlags.Property); } } From 7c3f27434c13264582e71d7b3580083a847a0fcf Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 9 Aug 2016 15:55:26 -0700 Subject: [PATCH 04/56] Add tests and baselines --- .../multipleExportDefault1.errors.txt | 19 ++++++++++++++++ .../reference/multipleExportDefault1.js | 20 +++++++++++++++++ .../multipleExportDefault2.errors.txt | 18 +++++++++++++++ .../reference/multipleExportDefault2.js | 18 +++++++++++++++ .../multipleExportDefault3.errors.txt | 18 +++++++++++++++ .../reference/multipleExportDefault3.js | 22 +++++++++++++++++++ .../multipleExportDefault4.errors.txt | 16 ++++++++++++++ .../reference/multipleExportDefault4.js | 20 +++++++++++++++++ .../multipleExportDefault5.errors.txt | 11 ++++++++++ .../reference/multipleExportDefault5.js | 16 ++++++++++++++ .../multipleExportDefault6.errors.txt | 20 +++++++++++++++++ .../reference/multipleExportDefault6.js | 19 ++++++++++++++++ .../externalModules/multipleExportDefault1.ts | 7 ++++++ .../externalModules/multipleExportDefault2.ts | 6 +++++ .../externalModules/multipleExportDefault3.ts | 6 +++++ .../externalModules/multipleExportDefault4.ts | 5 +++++ .../externalModules/multipleExportDefault5.ts | 2 ++ .../externalModules/multipleExportDefault6.ts | 7 ++++++ 18 files changed, 250 insertions(+) create mode 100644 tests/baselines/reference/multipleExportDefault1.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault1.js create mode 100644 tests/baselines/reference/multipleExportDefault2.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault2.js create mode 100644 tests/baselines/reference/multipleExportDefault3.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault3.js create mode 100644 tests/baselines/reference/multipleExportDefault4.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault4.js create mode 100644 tests/baselines/reference/multipleExportDefault5.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault5.js create mode 100644 tests/baselines/reference/multipleExportDefault6.errors.txt create mode 100644 tests/baselines/reference/multipleExportDefault6.js create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault1.ts create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault2.ts create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault3.ts create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault4.ts create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault5.ts create mode 100644 tests/cases/conformance/externalModules/multipleExportDefault6.ts diff --git a/tests/baselines/reference/multipleExportDefault1.errors.txt b/tests/baselines/reference/multipleExportDefault1.errors.txt new file mode 100644 index 00000000000..3da6afc41e0 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault1.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/externalModules/multipleExportDefault1.ts(1,25): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault1.ts(5,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault1.ts (2 errors) ==== + export default function Foo (){ + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + + } + + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault1.js b/tests/baselines/reference/multipleExportDefault1.js new file mode 100644 index 00000000000..bec4fb48969 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault1.js @@ -0,0 +1,20 @@ +//// [multipleExportDefault1.ts] +export default function Foo (){ + +} + +export default { + uhoh: "another default", +}; + + +//// [multipleExportDefault1.js] +"use strict"; +function Foo() { +} +exports.__esModule = true; +exports["default"] = Foo; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; diff --git a/tests/baselines/reference/multipleExportDefault2.errors.txt b/tests/baselines/reference/multipleExportDefault2.errors.txt new file mode 100644 index 00000000000..0543e25a163 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/externalModules/multipleExportDefault2.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault2.ts(5,25): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault2.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + + export default function Foo() { } + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault2.js b/tests/baselines/reference/multipleExportDefault2.js new file mode 100644 index 00000000000..dc82500a1d9 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault2.js @@ -0,0 +1,18 @@ +//// [multipleExportDefault2.ts] +export default { + uhoh: "another default", +}; + +export default function Foo() { } + + + +//// [multipleExportDefault2.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; +function Foo() { } +exports.__esModule = true; +exports["default"] = Foo; diff --git a/tests/baselines/reference/multipleExportDefault3.errors.txt b/tests/baselines/reference/multipleExportDefault3.errors.txt new file mode 100644 index 00000000000..f1e55da9112 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault3.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/externalModules/multipleExportDefault3.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault3.ts(5,22): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault3.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + + export default class C { } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault3.js b/tests/baselines/reference/multipleExportDefault3.js new file mode 100644 index 00000000000..5d7ad48e0ca --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault3.js @@ -0,0 +1,22 @@ +//// [multipleExportDefault3.ts] +export default { + uhoh: "another default", +}; + +export default class C { } + + + +//// [multipleExportDefault3.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; diff --git a/tests/baselines/reference/multipleExportDefault4.errors.txt b/tests/baselines/reference/multipleExportDefault4.errors.txt new file mode 100644 index 00000000000..bba15527d00 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault4.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/externalModules/multipleExportDefault4.ts(1,22): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault4.ts(3,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault4.ts (2 errors) ==== + export default class C { } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault4.js b/tests/baselines/reference/multipleExportDefault4.js new file mode 100644 index 00000000000..1199fa91c9c --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault4.js @@ -0,0 +1,20 @@ +//// [multipleExportDefault4.ts] +export default class C { } + +export default { + uhoh: "another default", +}; + +//// [multipleExportDefault4.js] +"use strict"; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; diff --git a/tests/baselines/reference/multipleExportDefault5.errors.txt b/tests/baselines/reference/multipleExportDefault5.errors.txt new file mode 100644 index 00000000000..30c87339ff2 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/externalModules/multipleExportDefault5.ts(1,25): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault5.ts(2,22): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault5.ts (2 errors) ==== + export default function bar() { } + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + export default class C {} + ~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault5.js b/tests/baselines/reference/multipleExportDefault5.js new file mode 100644 index 00000000000..7ae33aee9f4 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault5.js @@ -0,0 +1,16 @@ +//// [multipleExportDefault5.ts] +export default function bar() { } +export default class C {} + +//// [multipleExportDefault5.js] +"use strict"; +function bar() { } +exports.__esModule = true; +exports["default"] = bar; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; diff --git a/tests/baselines/reference/multipleExportDefault6.errors.txt b/tests/baselines/reference/multipleExportDefault6.errors.txt new file mode 100644 index 00000000000..a8bf80e8df0 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/externalModules/multipleExportDefault6.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault6.ts(5,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault6.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + lol: 1 + ~~~~~~~~~~ + } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + export default { + ~~~~~~~~~~~~~~~~ + lol: 2 + ~~~~~~~~~~ + } + ~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault6.js b/tests/baselines/reference/multipleExportDefault6.js new file mode 100644 index 00000000000..a8b93459e4e --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault6.js @@ -0,0 +1,19 @@ +//// [multipleExportDefault6.ts] +export default { + lol: 1 +} + +export default { + lol: 2 +} + +//// [multipleExportDefault6.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + lol: 1 +}; +exports.__esModule = true; +exports["default"] = { + lol: 2 +}; diff --git a/tests/cases/conformance/externalModules/multipleExportDefault1.ts b/tests/cases/conformance/externalModules/multipleExportDefault1.ts new file mode 100644 index 00000000000..623cc2acc20 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault1.ts @@ -0,0 +1,7 @@ +export default function Foo (){ + +} + +export default { + uhoh: "another default", +}; diff --git a/tests/cases/conformance/externalModules/multipleExportDefault2.ts b/tests/cases/conformance/externalModules/multipleExportDefault2.ts new file mode 100644 index 00000000000..0e14b570aa1 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault2.ts @@ -0,0 +1,6 @@ +export default { + uhoh: "another default", +}; + +export default function Foo() { } + diff --git a/tests/cases/conformance/externalModules/multipleExportDefault3.ts b/tests/cases/conformance/externalModules/multipleExportDefault3.ts new file mode 100644 index 00000000000..3b5460e8141 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault3.ts @@ -0,0 +1,6 @@ +export default { + uhoh: "another default", +}; + +export default class C { } + diff --git a/tests/cases/conformance/externalModules/multipleExportDefault4.ts b/tests/cases/conformance/externalModules/multipleExportDefault4.ts new file mode 100644 index 00000000000..6181c360798 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault4.ts @@ -0,0 +1,5 @@ +export default class C { } + +export default { + uhoh: "another default", +}; \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/multipleExportDefault5.ts b/tests/cases/conformance/externalModules/multipleExportDefault5.ts new file mode 100644 index 00000000000..d2b67fce46f --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault5.ts @@ -0,0 +1,2 @@ +export default function bar() { } +export default class C {} \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/multipleExportDefault6.ts b/tests/cases/conformance/externalModules/multipleExportDefault6.ts new file mode 100644 index 00000000000..889ae64376b --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault6.ts @@ -0,0 +1,7 @@ +export default { + lol: 1 +} + +export default { + lol: 2 +} \ No newline at end of file From 042da569f71b40b0723b92259dc8a197c64580a5 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 11 Aug 2016 10:04:22 -0700 Subject: [PATCH 05/56] Address PR: add comment --- src/compiler/binder.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1eedc4535dc..2547dd2cd5a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -337,21 +337,24 @@ namespace ts { ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; - // If the current node has NodeFlags.Default (e.g. if the node is class declaration or function declaration) - // and there is already another default export (i.e. symbol.declarations is not empty), we need to report such error + // If the current node is a default export of some sort, then check if + // there are any other default exports that we need to error on. + // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport && symbol.declarations) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; } - - forEach(symbol.declarations, declaration => { - // Error on multiple export default in the following case: - // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default - // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) - if ((declaration.flags & NodeFlags.Default) || - (declaration.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { - message = Diagnostics.A_module_cannot_have_multiple_default_exports; - } - }); + else { + // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. + forEach(symbol.declarations, declaration => { + // Error on multiple export default in the following case: + // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default + // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) + if ((declaration.flags & NodeFlags.Default) || + (declaration.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { + message = Diagnostics.A_module_cannot_have_multiple_default_exports; + } + }); + } forEach(symbol.declarations, declaration => { file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); From 821348b75d60f095f4e88a036fd4928a51527b99 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 11 Aug 2016 10:48:43 -0700 Subject: [PATCH 06/56] Update baseline --- ...sFileCompilationBindMultipleDefaultExports.errors.txt | 8 +++++++- .../reference/multipleDefaultExports01.errors.txt | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt index 4c1d237aa47..05fecf03d30 100644 --- a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt @@ -1,9 +1,15 @@ +tests/cases/compiler/a.js(1,22): error TS2528: A module cannot have multiple default exports. +tests/cases/compiler/a.js(3,1): error TS2528: A module cannot have multiple default exports. tests/cases/compiler/a.js(3,16): error TS1109: Expression expected. -==== tests/cases/compiler/a.js (1 errors) ==== +==== tests/cases/compiler/a.js (3 errors) ==== export default class a { + ~ +!!! error TS2528: A module cannot have multiple default exports. } export default var a = 10; + ~~~~~~~~~~~~~~ +!!! error TS2528: A module cannot have multiple default exports. ~~~ !!! error TS1109: Expression expected. \ No newline at end of file diff --git a/tests/baselines/reference/multipleDefaultExports01.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt index b3e7d757289..16aa3b2f7b1 100644 --- a/tests/baselines/reference/multipleDefaultExports01.errors.txt +++ b/tests/baselines/reference/multipleDefaultExports01.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2323: Cannot redeclare exported variable 'default'. tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2528: A module cannot have multiple default exports. -tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2323: Cannot redeclare exported variable 'default'. +tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? -==== tests/cases/conformance/es6/modules/m1.ts (4 errors) ==== +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== export default class foo { ~~~ -!!! error TS2323: Cannot redeclare exported variable 'default'. - ~~~ !!! error TS2528: A module cannot have multiple default exports. } @@ -24,7 +21,7 @@ tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typ var x = 10; export default x; ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Cannot redeclare exported variable 'default'. +!!! error TS2528: A module cannot have multiple default exports. ==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== import Entity from "./m1" From 3479f4bcbe233adcd0dd500686de3bf18b8efd57 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 11 Aug 2016 10:49:36 -0700 Subject: [PATCH 07/56] fix linting --- src/compiler/binder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 573bd0b7e35..c3dab267d02 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1913,7 +1913,7 @@ namespace ts { ? SymbolFlags.Alias // An export default clause with any other expression exports a value : SymbolFlags.Property; - declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function); //SymbolFlags.Class | SymbolFlags.Function | SymbolFlags.Property); + declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function); } } From 7b525ea99fb6befa87032741de972dfc0a8f650e Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 17 Aug 2016 16:06:13 -0700 Subject: [PATCH 08/56] Use for..of instead --- src/compiler/binder.ts | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 45dbab15732..5e065a00d2f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -349,23 +349,26 @@ namespace ts { ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; - // If the current node is a default export of some sort, then check if - // there are any other default exports that we need to error on. - // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. - if (isDefaultExport && symbol.declarations) { - message = Diagnostics.A_module_cannot_have_multiple_default_exports; - } - else { - // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. - forEach(symbol.declarations, declaration => { - // Error on multiple export default in the following case: - // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default - // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) - if ((declaration.flags & NodeFlags.Default) || - (declaration.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { - message = Diagnostics.A_module_cannot_have_multiple_default_exports; + if (symbol.declarations && symbol.declarations.length) { + // If the current node is a default export of some sort, then check if + // there are any other default exports that we need to error on. + // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. + if (isDefaultExport) { + message = Diagnostics.A_module_cannot_have_multiple_default_exports; + } + else { + // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. + for (const declaration of symbol.declarations) { + // Error on multiple export default in the following case: + // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default + // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) + if ((declaration.flags & NodeFlags.Default) || + (declaration.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { + message = Diagnostics.A_module_cannot_have_multiple_default_exports; + break; + } } - }); + } } forEach(symbol.declarations, declaration => { From 38d16bb4be50c797e81d07cf931e5c09a92ee475 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 20 Sep 2016 13:22:43 -0700 Subject: [PATCH 09/56] Improve handling of ++ and -- in control flow analysis --- src/compiler/checker.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bef1b0bcb9b..aaa800a391e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8426,8 +8426,11 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression; - return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ? + if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + const flowType = getTypeAtFlowNode(flow.antecedent); + return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); + } + return declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : declaredType; } From 7df7bb2bf37db177138a9930b7b212fcd049d183 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 20 Sep 2016 13:23:51 -0700 Subject: [PATCH 10/56] Accept new baselines --- tests/baselines/reference/controlFlowIIFE.types | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index 6173e79dbbb..7cf4337b53b 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -118,7 +118,7 @@ maybeNumber++; if (maybeNumber !== undefined) { >maybeNumber !== undefined : boolean ->maybeNumber : number | undefined +>maybeNumber : number >undefined : undefined maybeNumber++; From 864ee1cfc550d3887554461c1d1c4059e9927faa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 21 Sep 2016 14:17:09 -0700 Subject: [PATCH 11/56] Use control flow analysis for let/var with no type annotation or initializer --- src/compiler/checker.ts | 31 ++++++++++++++++++++++------ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aaa800a391e..ea1b98d2eb6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -119,6 +119,7 @@ namespace ts { const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); + const autoType = createIntrinsicType(TypeFlags.Any, "any"); const unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined"); @@ -3086,6 +3087,13 @@ namespace ts { return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } + // Use control flow type inference for non-ambient, non-exported var or let variables with no initializer + if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && + !(getCombinedNodeFlags(declaration) & NodeFlags.Const) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && + !declaration.initializer && !isInAmbientContext(declaration)) { + return autoType; + } + if (declaration.kind === SyntaxKind.Parameter) { const func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present @@ -8352,7 +8360,9 @@ namespace ts { if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { return declaredType; } - const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined); + const initialType = assumeInitialized ? declaredType : + declaredType === autoType ? undefinedType : + includeFalsyTypes(declaredType, TypeFlags.Undefined); const visitedFlowStart = visitedFlowCount; const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode)); visitedFlowCount = visitedFlowStart; @@ -8430,8 +8440,8 @@ namespace ts { const flowType = getTypeAtFlowNode(flow.antecedent); return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); } - return declaredType.flags & TypeFlags.Union ? - getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : + return declaredType === autoType ? getBaseTypeOfLiteralType(getInitialOrAssignedType(node)) : + declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : declaredType; } // We didn't have a direct match. However, if the reference is a dotted name, this @@ -9042,13 +9052,22 @@ namespace ts { // We only look for uninitialized variables in strict null checking mode, and only when we can analyze // the entire control flow graph from the variable's declaration (i.e. when the flow container and // declaration container are the same). - const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter || - isOuterVariable || isInAmbientContext(declaration); + const assumeInitialized = isParameter || isOuterVariable || + type !== autoType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) || + isInAmbientContext(declaration); const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the // control flow based type does include undefined. - if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { + if (type === autoType) { + if (flowType === autoType) { + if (compilerOptions.noImplicitAny) { + error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_and_is_referenced_in_a_nested_function, symbolToString(symbol)); + } + return anyType; + } + } + else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0f3e90405a6..9aa2cb9a6d3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2945,6 +2945,10 @@ "category": "Error", "code": 7033 }, + "Variable '{0}' implicitly has type 'any' and is referenced in a nested function.": { + "category": "Error", + "code": 7034 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 From dda8aac72765bc6e2cb25051a8f53d5ddcf8f6bc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 21 Sep 2016 16:03:31 -0700 Subject: [PATCH 12/56] Unify anyType and autoType when checking for identical declarations --- src/compiler/checker.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea1b98d2eb6..25cbedc1c1f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15806,6 +15806,10 @@ namespace ts { } } + function convertAutoToAny(type: Type) { + return type === autoType ? anyType : type; + } + // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkDecorators(node); @@ -15856,7 +15860,7 @@ namespace ts { return; } const symbol = getSymbolOfNode(node); - const type = getTypeOfVariableOrParameterOrProperty(symbol); + const type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error @@ -15868,7 +15872,7 @@ namespace ts { else { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node - const declarationType = getWidenedTypeForVariableLikeDeclaration(node); + const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node)); if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } From b14b24a96e7d69b692c220ad68f62ff559ae7d4d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 21 Sep 2016 16:03:51 -0700 Subject: [PATCH 13/56] Update tests --- tests/cases/compiler/anyPlusAny1.ts | 2 +- .../es5-asyncFunctionTryStatements.ts | 24 +++++++++---------- tests/cases/compiler/expr.ts | 2 +- ...itAnyDeclareVariablesWithoutTypeAndInit.ts | 7 +++--- .../conformance/Symbols/ES5SymbolProperty2.ts | 2 +- .../conformance/Symbols/ES5SymbolProperty3.ts | 2 +- .../es6/for-ofStatements/for-of3.ts | 2 +- ...dExponentiationAssignmentLHSIsReference.ts | 2 +- ...poundExponentiationAssignmentLHSIsValue.ts | 2 +- .../exponentiationOperatorSyntaxError2.ts | 2 +- .../assignmentLHSIsReference.ts | 2 +- .../assignmentLHSIsValue.ts | 2 +- .../compoundAssignmentLHSIsValue.ts | 2 +- .../decrementOperatorWithAnyOtherType.ts | 2 +- ...eratorWithAnyOtherTypeInvalidOperations.ts | 4 ++-- .../incrementOperatorWithAnyOtherType.ts | 2 +- ...eratorWithAnyOtherTypeInvalidOperations.ts | 4 ++-- .../negateOperatorWithAnyOtherType.ts | 4 ++-- .../jsx/tsxGenericArrowFunctionParsing.tsx | 2 +- .../RegressionTests/parser537152.ts | 2 -- .../for-inStatements/for-inStatements.ts | 2 +- 21 files changed, 37 insertions(+), 38 deletions(-) delete mode 100644 tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts diff --git a/tests/cases/compiler/anyPlusAny1.ts b/tests/cases/compiler/anyPlusAny1.ts index 084dcc02be3..c1bee9b97b0 100644 --- a/tests/cases/compiler/anyPlusAny1.ts +++ b/tests/cases/compiler/anyPlusAny1.ts @@ -1,3 +1,3 @@ -var x; +var x: any; x.name = "hello"; var z = x + x; \ No newline at end of file diff --git a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts index 11459295f47..0d14b5f4242 100644 --- a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts +++ b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts @@ -1,10 +1,10 @@ // @lib: es5,es2015.promise // @noEmitHelpers: true // @target: ES5 -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -14,7 +14,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -24,7 +24,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -34,7 +34,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -43,7 +43,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -53,7 +53,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -63,7 +63,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -73,7 +73,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -86,7 +86,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -99,7 +99,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -112,7 +112,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/cases/compiler/expr.ts b/tests/cases/compiler/expr.ts index b76aba88103..8d6f7beed7e 100644 --- a/tests/cases/compiler/expr.ts +++ b/tests/cases/compiler/expr.ts @@ -6,7 +6,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts index 88812001c9e..a84ab03f4b3 100644 --- a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts +++ b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts @@ -1,8 +1,9 @@ // @noimplicitany: true // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts index 07c95eb27d9..6bfce5fc58d 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts @@ -1,6 +1,6 @@ //@target: ES5 module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts index 262e47557f8..a6eecc72124 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts @@ -1,5 +1,5 @@ //@target: ES5 -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts index 7eb1e1fd220..850daee8368 100644 --- a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts +++ b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts @@ -1,3 +1,3 @@ //@target: ES6 -var v; +var v: any; for (v++ of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts index 02e6acfa685..7339704fc65 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts index 0eac581bfe4..176c2043344 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts index e5118d18551..13f5ce14e7d 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts @@ -1,7 +1,7 @@ // @target: es5 // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts index de5dbf6d747..91db91a3a9b 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts index 467a750b418..30b8df4268a 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts index 62311ee75c9..8eb50d2f64a 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts @@ -1,7 +1,7 @@ // @allowUnusedLabels: true // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts index 4ca37129f60..f8efeb81ecb 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts index 10dc05a4a33..d5dd62de442 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts index f1fa058745f..09f272442e1 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts index 2e6b14d7727..397024d45d6 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts index 189f1f000d8..d29b1a845eb 100644 --- a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -12,7 +12,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx index b3d3d34020a..deb7ba57b5d 100644 --- a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx +++ b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx @@ -4,7 +4,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts b/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts deleted file mode 100644 index d418f92b7ec..00000000000 --- a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts +++ /dev/null @@ -1,2 +0,0 @@ -var t; -var y = t.e1; diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts index 1ff19b3e412..89cc0314d36 100644 --- a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts @@ -14,7 +14,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } From c37b790ff386ec845c8ea70d224658b7355e6a09 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 21 Sep 2016 16:04:36 -0700 Subject: [PATCH 14/56] Accept new baselines --- .../reference/ES5SymbolProperty2.errors.txt | 2 +- .../baselines/reference/ES5SymbolProperty2.js | 2 +- .../reference/ES5SymbolProperty3.errors.txt | 2 +- .../baselines/reference/ES5SymbolProperty3.js | 2 +- tests/baselines/reference/anyPlusAny1.js | 2 +- tests/baselines/reference/anyPlusAny1.symbols | 2 +- tests/baselines/reference/anyPlusAny1.types | 2 +- .../asiPreventsParsingAsTypeAlias01.types | 6 +- .../reference/assignmentLHSIsReference.js | 2 +- .../assignmentLHSIsReference.symbols | 2 +- .../reference/assignmentLHSIsReference.types | 2 +- .../reference/assignmentLHSIsValue.errors.txt | 2 +- .../reference/assignmentLHSIsValue.js | 2 +- .../reference/capturedLetConstInLoop9.types | 2 +- .../capturedLetConstInLoop9_ES6.types | 2 +- .../commentsArgumentsOfCallExpression2.types | 6 +- .../compoundAssignmentLHSIsReference.types | 36 ++--- .../compoundAssignmentLHSIsValue.errors.txt | 2 +- .../reference/compoundAssignmentLHSIsValue.js | 2 +- ...dExponentiationAssignmentLHSIsReference.js | 2 +- ...nentiationAssignmentLHSIsReference.symbols | 2 +- ...ponentiationAssignmentLHSIsReference.types | 2 +- ...onentiationAssignmentLHSIsValue.errors.txt | 2 +- ...poundExponentiationAssignmentLHSIsValue.js | 2 +- .../constraintSatisfactionWithAny.types | 30 ++-- .../reference/controlFlowCaching.errors.txt | 128 ++++++++++++++++++ .../decrementOperatorWithAnyOtherType.js | 2 +- .../decrementOperatorWithAnyOtherType.symbols | 2 +- .../decrementOperatorWithAnyOtherType.types | 2 +- ...thAnyOtherTypeInvalidOperations.errors.txt | 4 +- ...eratorWithAnyOtherTypeInvalidOperations.js | 4 +- .../reference/downlevelLetConst14.types | 10 +- .../reference/downlevelLetConst15.types | 10 +- .../es5-asyncFunctionTryStatements.js | 24 ++-- .../es5-asyncFunctionTryStatements.symbols | 94 ++++++------- .../es5-asyncFunctionTryStatements.types | 24 ++-- ...onentiationOperatorSyntaxError2.errors.txt | 2 +- .../exponentiationOperatorSyntaxError2.js | 2 +- tests/baselines/reference/expr.errors.txt | 2 +- tests/baselines/reference/expr.js | 2 +- .../reference/for-inStatements.errors.txt | 2 +- tests/baselines/reference/for-inStatements.js | 2 +- tests/baselines/reference/for-of3.errors.txt | 2 +- tests/baselines/reference/for-of3.js | 2 +- ...lareVariablesWithoutTypeAndInit.errors.txt | 15 +- ...itAnyDeclareVariablesWithoutTypeAndInit.js | 14 +- .../incrementOperatorWithAnyOtherType.js | 2 +- .../incrementOperatorWithAnyOtherType.symbols | 2 +- .../incrementOperatorWithAnyOtherType.types | 2 +- ...thAnyOtherTypeInvalidOperations.errors.txt | 4 +- ...eratorWithAnyOtherTypeInvalidOperations.js | 4 +- .../initializePropertiesWithRenamedLet.types | 14 +- .../negateOperatorWithAnyOtherType.errors.txt | 4 +- .../negateOperatorWithAnyOtherType.js | 4 +- .../nestedBlockScopedBindings3.types | 40 +++--- .../nestedBlockScopedBindings4.types | 56 ++++---- .../nestedBlockScopedBindings6.types | 24 ++-- ...tAnyDestructuringVarDeclaration.errors.txt | 8 +- .../reference/noImplicitAnyForIn.errors.txt | 5 +- .../objectLiteralShorthandProperties.types | 18 +-- .../objectLiteralShorthandPropertiesES6.types | 18 +-- .../parserAmbiguityWithBinaryOperator1.types | 12 +- .../parserAmbiguityWithBinaryOperator2.types | 12 +- .../parserAmbiguityWithBinaryOperator3.types | 12 +- tests/baselines/reference/tsxEmit1.types | 16 +-- tests/baselines/reference/tsxEmit2.types | 28 ++-- .../tsxGenericArrowFunctionParsing.js | 2 +- .../tsxGenericArrowFunctionParsing.symbols | 6 +- .../tsxGenericArrowFunctionParsing.types | 2 +- tests/baselines/reference/tsxReactEmit1.types | 16 +-- tests/baselines/reference/tsxReactEmit2.types | 28 ++-- tests/baselines/reference/tsxReactEmit5.types | 2 +- tests/baselines/reference/tsxReactEmit6.types | 2 +- .../reference/unusedSwitchStatment.errors.txt | 5 +- 74 files changed, 471 insertions(+), 346 deletions(-) create mode 100644 tests/baselines/reference/controlFlowCaching.errors.txt diff --git a/tests/baselines/reference/ES5SymbolProperty2.errors.txt b/tests/baselines/reference/ES5SymbolProperty2.errors.txt index 9a6526a2f86..97579a4f27a 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty2.errors.txt @@ -4,7 +4,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(10,11): error TS2304: Cann ==== tests/cases/conformance/Symbols/ES5SymbolProperty2.ts (2 errors) ==== module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty2.js b/tests/baselines/reference/ES5SymbolProperty2.js index f04a4671d3f..0cfe717ae56 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.js +++ b/tests/baselines/reference/ES5SymbolProperty2.js @@ -1,6 +1,6 @@ //// [ES5SymbolProperty2.ts] module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.errors.txt b/tests/baselines/reference/ES5SymbolProperty3.errors.txt index 7c6cc5a9cd7..2953ed6ac6a 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,6): error TS2471: A comp ==== tests/cases/conformance/Symbols/ES5SymbolProperty3.ts (1 errors) ==== - var Symbol; + var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.js b/tests/baselines/reference/ES5SymbolProperty3.js index 6589858625c..084f79bd077 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.js +++ b/tests/baselines/reference/ES5SymbolProperty3.js @@ -1,5 +1,5 @@ //// [ES5SymbolProperty3.ts] -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/anyPlusAny1.js b/tests/baselines/reference/anyPlusAny1.js index 457688933d7..4b28a1d22e2 100644 --- a/tests/baselines/reference/anyPlusAny1.js +++ b/tests/baselines/reference/anyPlusAny1.js @@ -1,5 +1,5 @@ //// [anyPlusAny1.ts] -var x; +var x: any; x.name = "hello"; var z = x + x; diff --git a/tests/baselines/reference/anyPlusAny1.symbols b/tests/baselines/reference/anyPlusAny1.symbols index e0552e4541f..3b33a11987e 100644 --- a/tests/baselines/reference/anyPlusAny1.symbols +++ b/tests/baselines/reference/anyPlusAny1.symbols @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : Symbol(x, Decl(anyPlusAny1.ts, 0, 3)) x.name = "hello"; diff --git a/tests/baselines/reference/anyPlusAny1.types b/tests/baselines/reference/anyPlusAny1.types index f6ca9c4996e..67323a10fd6 100644 --- a/tests/baselines/reference/anyPlusAny1.types +++ b/tests/baselines/reference/anyPlusAny1.types @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : any x.name = "hello"; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index 7492a698e3a..c2d9213ca60 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,10 +10,10 @@ var Foo; >Foo : any type ->type : any +>type : undefined Foo = string; ->Foo = string : any +>Foo = string : undefined >Foo : any ->string : any +>string : undefined diff --git a/tests/baselines/reference/assignmentLHSIsReference.js b/tests/baselines/reference/assignmentLHSIsReference.js index f0af56ebc3b..85d2aab2c46 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.js +++ b/tests/baselines/reference/assignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [assignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/assignmentLHSIsReference.symbols b/tests/baselines/reference/assignmentLHSIsReference.symbols index b551557708f..417ba3c07ea 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.symbols +++ b/tests/baselines/reference/assignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(assignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsReference.types b/tests/baselines/reference/assignmentLHSIsReference.types index dfb3b236c0a..2a7fa2982aa 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.types +++ b/tests/baselines/reference/assignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index bf253df5e70..f97ae2bcfa5 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 ==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== // expected error for all the LHS of assignments - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/assignmentLHSIsValue.js b/tests/baselines/reference/assignmentLHSIsValue.js index 8a3b4b35d0b..8f2014ff211 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.js +++ b/tests/baselines/reference/assignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [assignmentLHSIsValue.ts] // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 486697b8d84..453176a40c9 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -39,7 +39,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types index be4457315ee..df118279f30 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types @@ -40,7 +40,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types index 7ec29aa9124..bc6bf5baa90 100644 --- a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types +++ b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types @@ -17,7 +17,7 @@ foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b); >1 : 1 >2 : 2 >a + b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); @@ -26,7 +26,7 @@ foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); >function () { } : () => void >() => { } : () => void >a + /*e3*/ b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); @@ -36,7 +36,7 @@ foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); >() => { } : () => void >(a + b) : any >a + b : any ->a : any +>a : undefined >b : any foo( diff --git a/tests/baselines/reference/compoundAssignmentLHSIsReference.types b/tests/baselines/reference/compoundAssignmentLHSIsReference.types index 4816307f508..a82eb17426d 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsReference.types @@ -9,12 +9,12 @@ var x1: number; x1 *= value; >x1 *= value : number >x1 : number ->value : any +>value : undefined x1 += value; ->x1 += value : any +>x1 += value : number >x1 : number ->value : any +>value : undefined function fn1(x2: number) { >fn1 : (x2: number) => void @@ -41,41 +41,41 @@ x3.a *= value; >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3.a += value; ->x3.a += value : any +>x3.a += value : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3['a'] *= value; >x3['a'] *= value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined x3['a'] += value; ->x3['a'] += value : any +>x3['a'] += value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined // parentheses, the contained expression is reference (x1) *= value; >(x1) *= value : number >(x1) : number >x1 : number ->value : any +>value : undefined (x1) += value; ->(x1) += value : any +>(x1) += value : number >(x1) : number >x1 : number ->value : any +>value : undefined function fn2(x4: number) { >fn2 : (x4: number) => void @@ -100,15 +100,15 @@ function fn2(x4: number) { >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3.a) += value; ->(x3.a) += value : any +>(x3.a) += value : number >(x3.a) : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3['a']) *= value; >(x3['a']) *= value : number @@ -116,13 +116,13 @@ function fn2(x4: number) { >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined (x3['a']) += value; ->(x3['a']) += value : any +>(x3['a']) += value : number >(x3['a']) : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 392e1781dd5..61f893ba88f 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -77,7 +77,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa ==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.js b/tests/baselines/reference/compoundAssignmentLHSIsValue.js index a55c068d4a4..618daea339e 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.js @@ -1,7 +1,7 @@ //// [compoundAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js index dfee41fad81..d5104f1dbdc 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [compoundExponentiationAssignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols index 775d43b0c58..b69c1afdb9b 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types index 55b90382d7b..32230f7f8ef 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index 23720468bb7..0d9bab910ef 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -40,7 +40,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm ==== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts (38 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js index 16500b823b8..f9e58817ece 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [compoundExponentiationAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/constraintSatisfactionWithAny.types b/tests/baselines/reference/constraintSatisfactionWithAny.types index f3363fe1a90..2f9c7553288 100644 --- a/tests/baselines/reference/constraintSatisfactionWithAny.types +++ b/tests/baselines/reference/constraintSatisfactionWithAny.types @@ -35,20 +35,20 @@ var a; >a : any foo(a); ->foo(a) : any +>foo(a) : undefined >foo : (x: T) => T ->a : any +>a : undefined foo2(a); ->foo2(a) : any +>foo2(a) : undefined >foo2 : (x: T) => T ->a : any +>a : undefined //foo3(a); foo4(a); ->foo4(a) : any +>foo4(a) : undefined >foo4 : (x: T) => void>(x: T) => T ->a : any +>a : undefined var b: number; >b : number @@ -84,10 +84,10 @@ class C { } var c1 = new C(a); ->c1 : C ->new C(a) : C +>c1 : C +>new C(a) : C >C : typeof C ->a : any +>a : undefined var c2 = new C(b); >c2 : C @@ -106,10 +106,10 @@ class C2 { } var c3 = new C2(a); ->c3 : C2 ->new C2(a) : C2 +>c3 : C2 +>new C2(a) : C2 >C2 : typeof C2 ->a : any +>a : undefined var c4 = new C2(b); >c4 : C2 @@ -138,10 +138,10 @@ class C4(x:T) => T> { } var c7 = new C4(a); ->c7 : C4 ->new C4(a) : C4 +>c7 : C4 +>new C4(a) : C4 >C4 : typeof C4 ->a : any +>a : undefined var c8 = new C4(b); >c8 : C4 diff --git a/tests/baselines/reference/controlFlowCaching.errors.txt b/tests/baselines/reference/controlFlowCaching.errors.txt new file mode 100644 index 00000000000..1086695313e --- /dev/null +++ b/tests/baselines/reference/controlFlowCaching.errors.txt @@ -0,0 +1,128 @@ +tests/cases/compiler/controlFlowCaching.ts(38,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(38,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(40,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(40,29): error TS2339: Property 'x' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(42,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(42,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(44,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(44,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(46,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(46,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(48,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(48,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(53,5): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(53,14): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(55,14): error TS2678: Type '"start"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(58,14): error TS2678: Type '"end"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(61,14): error TS2678: Type '"middle"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,13): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,25): error TS2339: Property 'y' does not exist on type 'never'. + + +==== tests/cases/compiler/controlFlowCaching.ts (19 errors) ==== + + // Repro for #8401 + + function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { + var isRtl = this._isRtl(); // chart mirroring + // prepare variable + var o = this.opt, ta = this.chart.theme.axis, position = o.position, + leftBottom = position !== "rightOrTop", rotation = o.rotation % 360, + start, stop, titlePos, titleRotation = 0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign, + labelGap = this.chart.theme.axis.tick.labelGap, + taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), + taTitleFont = o.titleFont || (ta.title && ta.title.font), + taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black", + taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black", + taTitleGap = (o.titleGap == 0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15, + taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis", + taMajorTick = this.chart.theme.getTick("major", o), + taMinorTick = this.chart.theme.getTick("minor", o), + taMicroTick = this.chart.theme.getTick("micro", o), + + taStroke = "stroke" in o ? o.stroke : ta.stroke, + size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0, + cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), + sinr = Math.abs(Math.sin(rotation * Math.PI / 180)), + tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0; + if (rotation < 0) { + rotation += 360; + } + var cachedLabelW = this._getMaxLabelSize(); + cachedLabelW = cachedLabelW && cachedLabelW.majLabelW; + titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length > 0 ? taMajorTick.length : 0, + taMinorTick.length > 0 ? taMinorTick.length : 0) + + tsize + taTitleGap; + axisVector = { x: isRtl ? -1 : 1, y: 0 }; // chart mirroring + switch (rotation) { + default: + if (rotation < (90 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (90 + centerAnchorLimit)) { + labelOffset.x = -size * 0.4; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'x' does not exist on type 'never'. + } else if (rotation < 180) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 + centerAnchorLimit)) { + labelOffset.y = leftBottom ? size * 0.4 : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } + } + + titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0; + titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize); + ~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + switch (labelAlign) { + case "start": + ~~~~~~~ +!!! error TS2678: Type '"start"' is not comparable to type 'undefined'. + labelAlign = "end"; + break; + case "end": + ~~~~~ +!!! error TS2678: Type '"end"' is not comparable to type 'undefined'. + labelAlign = "start"; + break; + case "middle": + ~~~~~~~~ +!!! error TS2678: Type '"middle"' is not comparable to type 'undefined'. + labelOffset.y -= size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + break; + } + + let _ = rotation; + } + \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js index 51015cf44ed..f3ff58b80ca 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols index cbef7442578..8d1b023c97a 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(decrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(decrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types index c8b8852e4d2..74fbd0012d1 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 46e5515633a..2e1d594164d 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -52,7 +52,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (50 errors) ==== // -- operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -63,7 +63,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js index 94f5c942bfc..88d045ab378 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [decrementOperatorWithAnyOtherTypeInvalidOperations.ts] // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/downlevelLetConst14.types b/tests/baselines/reference/downlevelLetConst14.types index 29c87e76cce..493c17b97cd 100644 --- a/tests/baselines/reference/downlevelLetConst14.types +++ b/tests/baselines/reference/downlevelLetConst14.types @@ -77,22 +77,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -149,7 +149,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/downlevelLetConst15.types b/tests/baselines/reference/downlevelLetConst15.types index 9e58c648821..6d224b6310d 100644 --- a/tests/baselines/reference/downlevelLetConst15.types +++ b/tests/baselines/reference/downlevelLetConst15.types @@ -83,22 +83,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -155,7 +155,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.js b/tests/baselines/reference/es5-asyncFunctionTryStatements.js index c9c5507afa7..513420dd6f4 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.js +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.js @@ -1,8 +1,8 @@ //// [es5-asyncFunctionTryStatements.ts] -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -12,7 +12,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -22,7 +22,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -32,7 +32,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -41,7 +41,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -51,7 +51,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -61,7 +61,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -71,7 +71,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -84,7 +84,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -97,7 +97,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -110,7 +110,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols index ecf8fbc505b..52a4ec8df76 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols @@ -1,18 +1,18 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 0, 11)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 14)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 17)) ->a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 20)) ->b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 23)) ->c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 26)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 19)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 27)) +>a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 35)) +>b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 43)) +>c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 51)) async function tryCatch0() { ->tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 29)) +>tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 59)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 3, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) try { x; @@ -22,16 +22,16 @@ async function tryCatch0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 7, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) } } async function tryCatch1() { >tryCatch1 : Symbol(tryCatch1, Decl(es5-asyncFunctionTryStatements.ts, 10, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 13, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) try { await x; @@ -41,16 +41,16 @@ async function tryCatch1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 17, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) } } async function tryCatch2() { >tryCatch2 : Symbol(tryCatch2, Decl(es5-asyncFunctionTryStatements.ts, 20, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 23, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) try { x; @@ -60,7 +60,7 @@ async function tryCatch2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 27, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) } } @@ -69,9 +69,9 @@ async function tryCatch3(): Promise { >Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 33, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 15)) try { await x; @@ -87,9 +87,9 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : Symbol(tryFinally0, Decl(es5-asyncFunctionTryStatements.ts, 40, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 42, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) try { x; @@ -97,16 +97,16 @@ async function tryFinally0() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) } } async function tryFinally1() { >tryFinally1 : Symbol(tryFinally1, Decl(es5-asyncFunctionTryStatements.ts, 49, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 52, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) try { await x; @@ -114,16 +114,16 @@ async function tryFinally1() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) } } async function tryFinally2() { >tryFinally2 : Symbol(tryFinally2, Decl(es5-asyncFunctionTryStatements.ts, 59, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 62, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) try { x; @@ -131,17 +131,17 @@ async function tryFinally2() { } finally { await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) } } async function tryCatchFinally0() { >tryCatchFinally0 : Symbol(tryCatchFinally0, Decl(es5-asyncFunctionTryStatements.ts, 69, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 72, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) try { x; @@ -151,21 +151,21 @@ async function tryCatchFinally0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 76, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) } } async function tryCatchFinally1() { >tryCatchFinally1 : Symbol(tryCatchFinally1, Decl(es5-asyncFunctionTryStatements.ts, 82, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 85, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) try { await x; @@ -175,21 +175,21 @@ async function tryCatchFinally1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 89, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) } } async function tryCatchFinally2() { >tryCatchFinally2 : Symbol(tryCatchFinally2, Decl(es5-asyncFunctionTryStatements.ts, 95, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 98, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) try { x; @@ -199,21 +199,21 @@ async function tryCatchFinally2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 102, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) } } async function tryCatchFinally3() { >tryCatchFinally3 : Symbol(tryCatchFinally3, Decl(es5-asyncFunctionTryStatements.ts, 108, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 111, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) try { x; @@ -223,10 +223,10 @@ async function tryCatchFinally3() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 115, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) } finally { await z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) } } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.types b/tests/baselines/reference/es5-asyncFunctionTryStatements.types index ab1cd845616..f4c4536c6fc 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.types +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.types @@ -1,5 +1,5 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : any >y : any >z : any @@ -10,7 +10,7 @@ declare var x, y, z, a, b, c; async function tryCatch0() { >tryCatch0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -29,7 +29,7 @@ async function tryCatch0() { async function tryCatch1() { >tryCatch1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -49,7 +49,7 @@ async function tryCatch1() { async function tryCatch2() { >tryCatch2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -71,7 +71,7 @@ async function tryCatch3(): Promise { >Promise : Promise >Function : Function - var x, y; + var x: any, y: any; >x : any >y : any @@ -91,7 +91,7 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -108,7 +108,7 @@ async function tryFinally0() { async function tryFinally1() { >tryFinally1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -126,7 +126,7 @@ async function tryFinally1() { async function tryFinally2() { >tryFinally2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -144,7 +144,7 @@ async function tryFinally2() { async function tryCatchFinally0() { >tryCatchFinally0 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -168,7 +168,7 @@ async function tryCatchFinally0() { async function tryCatchFinally1() { >tryCatchFinally1 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -193,7 +193,7 @@ async function tryCatchFinally1() { async function tryCatchFinally2() { >tryCatchFinally2 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -218,7 +218,7 @@ async function tryCatchFinally2() { async function tryCatchFinally3() { >tryCatchFinally3 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt index af17a7ddf7a..134a883540e 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt @@ -84,7 +84,7 @@ tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxE ==== tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts (81 errors) ==== // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () - var temp; + var temp: any; delete --temp ** 3; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js index 9e07273522f..e443b756575 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js @@ -1,7 +1,7 @@ //// [exponentiationOperatorSyntaxError2.ts] // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/baselines/reference/expr.errors.txt b/tests/baselines/reference/expr.errors.txt index 17e39cc80be..23215cac6ba 100644 --- a/tests/baselines/reference/expr.errors.txt +++ b/tests/baselines/reference/expr.errors.txt @@ -78,7 +78,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/expr.js b/tests/baselines/reference/expr.js index 9baf55084c1..689ff1e27dc 100644 --- a/tests/baselines/reference/expr.js +++ b/tests/baselines/reference/expr.js @@ -7,7 +7,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 7e20b8ca316..f0e6c950ebb 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -18,7 +18,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in /[a-z]/) { } for (var x in new Date()) { } - var c, d, e; + var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 5c097a68ccc..7aabf414758 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -15,7 +15,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt index ba8e3e4a5c6..99ed3098a63 100644 --- a/tests/baselines/reference/for-of3.errors.txt +++ b/tests/baselines/reference/for-of3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Inva ==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== - var v; + var v: any; for (v++ of []) { } ~~~ !!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.js b/tests/baselines/reference/for-of3.js index 7ef27187702..15918223e6b 100644 --- a/tests/baselines/reference/for-of3.js +++ b/tests/baselines/reference/for-of3.js @@ -1,5 +1,5 @@ //// [for-of3.ts] -var v; +var v: any; for (v++ of []) { } //// [for-of3.js] diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt index 3acb6e47e10..4f77bae4b8d 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt @@ -1,17 +1,18 @@ -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,13): error TS7005: Variable 'foo' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,15): error TS7006: Parameter 'k' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,5): error TS7034: Variable 'y' implicitly has type 'any' and is referenced in a nested function. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,13): error TS7005: Variable 'foo' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,15): error TS7006: Parameter 'k' implicitly has an 'any' type. ==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (3 errors) ==== // this should be an error - var x; // error at "x" + var x; // no error, control flow typed + var y; // error because captured ~ -!!! error TS7005: Variable 'x' implicitly has an 'any' type. - declare var foo; // error at "foo" +!!! error TS7034: Variable 'y' implicitly has type 'any' and is referenced in a nested function. + declare var foo; // error at "foo" ~~~ !!! error TS7005: Variable 'foo' implicitly has an 'any' type. - function func(k) { }; //error at "k" + function func(k) { y }; // error at "k" ~ !!! error TS7006: Parameter 'k' implicitly has an 'any' type. func(x); diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js index e3c44e9b783..5770050d449 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js @@ -1,8 +1,9 @@ //// [implicitAnyDeclareVariablesWithoutTypeAndInit.ts] // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error @@ -13,9 +14,10 @@ var x1: any; var y1 = new x1; //// [implicitAnyDeclareVariablesWithoutTypeAndInit.js] // this should be an error -var x; // error at "x" -function func(k) { } -; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +function func(k) { y; } +; // error at "k" func(x); // this shouldn't be an error var bar = 3; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js index e99340a53e2..989d4d900d3 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols index 338ab905064..2eceb1a2431 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(incrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(incrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types index 715de620bff..13a39410df7 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 92e639df21e..4aae7f5b51e 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -47,7 +47,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (45 errors) ==== // ++ operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js index 636ca74ba08..be2726f083b 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [incrementOperatorWithAnyOtherTypeInvalidOperations.ts] // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types index 65ea68059a7..d6937da8983 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.types +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -10,15 +10,15 @@ if (true) { >x0 : any var obj1 = { x0: x0 }; ->obj1 : { x0: any; } ->{ x0: x0 } : { x0: any; } ->x0 : any ->x0 : any +>obj1 : { x0: undefined; } +>{ x0: x0 } : { x0: undefined; } +>x0 : undefined +>x0 : undefined var obj2 = { x0 }; ->obj2 : { x0: any; } ->{ x0 } : { x0: any; } ->x0 : any +>obj2 : { x0: undefined; } +>{ x0 } : { x0: undefined; } +>x0 : undefined } var x, y, z; diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt index f008b4698ed..03e596aca41 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator // - operator on any type var ANY: any; - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -16,7 +16,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.js b/tests/baselines/reference/negateOperatorWithAnyOtherType.js index 6a2fe74c7ba..eb5f70d8c9c 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -13,7 +13,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types index 0de8123861d..ca13759bac4 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.types +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -31,7 +31,7 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : undefined >1 : 1 () => x; @@ -53,24 +53,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -82,14 +82,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } switch (1) { @@ -111,14 +111,14 @@ function a4() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -145,14 +145,14 @@ function a5() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types index 65b5d73db9d..9e0147f25f7 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.types +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -5,24 +5,24 @@ function a0() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -33,14 +33,14 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -51,10 +51,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -65,24 +65,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -98,14 +98,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -116,10 +116,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types index 865dea31e37..bf38f46d508 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.types +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -18,10 +18,10 @@ function a0() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -49,10 +49,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -76,10 +76,10 @@ function a2() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -111,10 +111,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt index f7e6475b971..02a288b2859 100644 --- a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt +++ b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt @@ -2,8 +2,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,5): error TS1 tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,6): error TS7031: Binding element 'a' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,10): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,11): error TS7031: Binding element 'b' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,15): error TS7005: Variable 'c' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,18): error TS7005: Variable 'd' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,5): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,6): error TS7031: Binding element 'a1' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,23): error TS1182: A destructuring declaration must have an initializer. @@ -22,7 +20,7 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type. -==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ==== +==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (20 errors) ==== var [a], {b}, c, d; // error ~~~ !!! error TS1182: A destructuring declaration must have an initializer. @@ -32,10 +30,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS1182: A destructuring declaration must have an initializer. ~ !!! error TS7031: Binding element 'b' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'c' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'd' implicitly has an 'any' type. var [a1 = undefined], {b1 = null}, c1 = undefined, d1 = null; // error ~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 2fb8e5a4103..69b5cd34906 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,11 +1,10 @@ tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyForIn.ts(21,9): error TS7005: Variable 'b' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -==== tests/cases/compiler/noImplicitAnyForIn.ts (5 errors) ==== +==== tests/cases/compiler/noImplicitAnyForIn.ts (4 errors) ==== var x: {}[] = [[1, 2, 3], ["hello"]]; @@ -31,8 +30,6 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si for (var a in x) { // Should yield an implicit 'any' error. var b; - ~ -!!! error TS7005: Variable 'b' implicitly has an 'any' type. var c = a || b; } diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index 4f4482906aa..168fcc07af7 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 1565be04625..80cbe304040 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types index 234375fb46d..ca7d65c9c34 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -10,12 +10,12 @@ function f1() { if (a < b || b > (c + 1)) { } >a < b || b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types index ed3b4b903bb..f4c1c2ac690 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -10,12 +10,12 @@ function f() { if (a < b && b > (c + 1)) { } >a < b && b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types index 61601d8bdf6..b1129656342 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -10,13 +10,13 @@ function f() { if (a < b && b < (c + 1)) { } >a < b && b < (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b < (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/tsxEmit1.types b/tests/baselines/reference/tsxEmit1.types index 84f00b4758a..c3ca7a2b1b0 100644 --- a/tests/baselines/reference/tsxEmit1.types +++ b/tests/baselines/reference/tsxEmit1.types @@ -61,7 +61,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any var openClosed1 =
; @@ -82,7 +82,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -91,8 +91,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -101,8 +101,8 @@ var openClosed5 =
{p > p}
; >div : any >n : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -180,7 +180,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -189,7 +189,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxEmit2.types b/tests/baselines/reference/tsxEmit2.types index 5b267d8b802..d306dc9ffe0 100644 --- a/tests/baselines/reference/tsxEmit2.types +++ b/tests/baselines/reference/tsxEmit2.types @@ -22,16 +22,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -39,19 +39,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -59,10 +59,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index e77e832cb0a..7dbb2477db5 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -3,7 +3,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols index 6d90c583a66..2d3c1f18d48 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols @@ -7,10 +7,10 @@ declare module JSX { >isElement : Symbol(Element.isElement, Decl(file.tsx, 1, 20)) } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : Symbol(T, Decl(file.tsx, 4, 3)) ->T1 : Symbol(T1, Decl(file.tsx, 4, 6)) ->T2 : Symbol(T2, Decl(file.tsx, 4, 10)) +>T1 : Symbol(T1, Decl(file.tsx, 4, 11)) +>T2 : Symbol(T2, Decl(file.tsx, 4, 20)) // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types index 693f920195d..0f746a07136 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types @@ -7,7 +7,7 @@ declare module JSX { >isElement : any } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : any >T1 : any >T2 : any diff --git a/tests/baselines/reference/tsxReactEmit1.types b/tests/baselines/reference/tsxReactEmit1.types index 8eb14e91963..b2cb2f73eba 100644 --- a/tests/baselines/reference/tsxReactEmit1.types +++ b/tests/baselines/reference/tsxReactEmit1.types @@ -63,7 +63,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any >b : any @@ -85,7 +85,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -94,8 +94,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -105,8 +105,8 @@ var openClosed5 =
{p > p}
; >n : any >b : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -184,7 +184,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -193,7 +193,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxReactEmit2.types b/tests/baselines/reference/tsxReactEmit2.types index 928eeecadfa..b05764e996f 100644 --- a/tests/baselines/reference/tsxReactEmit2.types +++ b/tests/baselines/reference/tsxReactEmit2.types @@ -24,16 +24,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -41,19 +41,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -61,10 +61,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxReactEmit5.types b/tests/baselines/reference/tsxReactEmit5.types index fb1c6594f30..73e7e6ff391 100644 --- a/tests/baselines/reference/tsxReactEmit5.types +++ b/tests/baselines/reference/tsxReactEmit5.types @@ -32,6 +32,6 @@ var spread1 =
; >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any diff --git a/tests/baselines/reference/tsxReactEmit6.types b/tests/baselines/reference/tsxReactEmit6.types index b8a307eb9d7..ae56de052cc 100644 --- a/tests/baselines/reference/tsxReactEmit6.types +++ b/tests/baselines/reference/tsxReactEmit6.types @@ -35,7 +35,7 @@ namespace M { >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any // Quotes diff --git a/tests/baselines/reference/unusedSwitchStatment.errors.txt b/tests/baselines/reference/unusedSwitchStatment.errors.txt index a22c252f60d..591e9deca7a 100644 --- a/tests/baselines/reference/unusedSwitchStatment.errors.txt +++ b/tests/baselines/reference/unusedSwitchStatment.errors.txt @@ -4,9 +4,10 @@ tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declare tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used. tests/cases/compiler/unusedSwitchStatment.ts(15,10): error TS2678: Type '0' is not comparable to type '2'. tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is not comparable to type '2'. +tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/unusedSwitchStatment.ts (6 errors) ==== +==== tests/cases/compiler/unusedSwitchStatment.ts (7 errors) ==== switch (1) { case 0: @@ -37,4 +38,6 @@ tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is n ~ !!! error TS2678: Type '1' is not comparable to type '2'. x++; + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. } \ No newline at end of file From 2035db1d51b0eaae1d840ceba1a70541a77153c3 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 23 Sep 2016 17:37:11 -0700 Subject: [PATCH 15/56] Convert to Doc Comment --- src/services/types.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/types.ts b/src/services/types.ts index e8c411cc1c8..35d52532687 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -473,7 +473,11 @@ namespace ts { export interface CompletionInfo { isMemberCompletion: boolean; - isNewIdentifierLocation: boolean; // true when the current location also allows for a new identifier + + /** + * true when the current location also allows for a new identifier + */ + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } From b38d7ac9fd41c46b70c0e5fcfe815a25c98270a4 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 26 Sep 2016 11:19:06 -0700 Subject: [PATCH 16/56] Annotate directorySeparator --- src/compiler/core.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 72d05e1cfd7..aca9701eee7 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1044,9 +1044,14 @@ namespace ts { return 0; } + /** + * Internally, we represent paths as strings with '/' as the directory separator. + * When we make system calls (eg: LanguageServiceHost.getDirectory()), + * we expect the host to correctly handle paths in our specified format. + */ export const directorySeparator = "/"; const directorySeparatorCharCode = CharacterCodes.slash; - function getNormalizedParts(normalizedSlashedPath: string, rootLength: number) { + function getNormalizedParts(normalizedSlashedPath: string, rootLength: number): string[] { const parts = normalizedSlashedPath.substr(rootLength).split(directorySeparator); const normalized: string[] = []; for (const part of parts) { From d423aadc72c5247db5f674f7277429bcf39fc6af Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 26 Sep 2016 13:34:07 -0700 Subject: [PATCH 17/56] comments --- src/services/completions.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index d6a4da89ed1..00a5f80379b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -323,12 +323,12 @@ namespace ts.Completions { } function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { - fragment = getDirectoryPath(fragment); + fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "./"; + fragment = "." + directorySeparator; } else { - fragment = ensureTrailingDirectorySeparator(fragment); + fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? } const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment)); @@ -544,7 +544,7 @@ namespace ts.Completions { const kind = match[2]; const toComplete = match[3]; - const scriptPath = getDirectoryPath(sourceFile.path); + const scriptPath = getDirectoryPath(sourceFile.path); // TODO: normalize for win10? let entries: CompletionEntry[]; if (kind === "path") { // Give completions for a relative path From 1f7b6e6a31afaaa00a57cf875b7a3a41af267250 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 27 Sep 2016 10:54:03 -0700 Subject: [PATCH 18/56] More comments --- src/compiler/core.ts | 11 +++++++++-- src/services/completions.ts | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index aca9701eee7..0b6dd3c9d7c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1015,7 +1015,9 @@ namespace ts { return path.replace(/\\/g, "/"); } - // Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + /** + * Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + */ export function getRootLength(path: string): number { if (path.charCodeAt(0) === CharacterCodes.slash) { if (path.charCodeAt(1) !== CharacterCodes.slash) return 1; @@ -1074,7 +1076,7 @@ namespace ts { export function normalizePath(path: string): string { path = normalizeSlashes(path); - const rootLength = getRootLength(path); + const rootLength = getRootLength(path); // TODO: this expects un-slash-normalized strings. eg: 'x:\\...' const root = path.substr(0, rootLength); const normalized = getNormalizedParts(path, rootLength); if (normalized.length) { @@ -1091,6 +1093,11 @@ namespace ts { return path.charCodeAt(path.length - 1) === directorySeparatorCharCode; } + /** + * Returns the path except for its basename. Eg: + * + * /path/to/file.ext -> /path/to + */ export function getDirectoryPath(path: Path): Path; export function getDirectoryPath(path: string): string; export function getDirectoryPath(path: string): any { diff --git a/src/services/completions.ts b/src/services/completions.ts index 00a5f80379b..04b68544376 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -322,10 +322,22 @@ namespace ts.Completions { return result; } + /** + * Given a path ending at a directory, gets the completions for the path. + */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { + /*Debug.assert(fragment !== undefined); + + if (fragment === "") { + fragment = "."; + } else { + fragment = getDirectoryPath(fragment); + } + */ + fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "." + directorySeparator; + fragment = "."; } else { fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? From 769d248519c28bc538ee9eedf657d9fbacf3f354 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 27 Sep 2016 13:43:42 -0700 Subject: [PATCH 19/56] new test --- .../tripleSlashRefPathRelativePaths.ts | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts b/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts new file mode 100644 index 00000000000..96d0a11214f --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathRelativePaths.ts @@ -0,0 +1,137 @@ +/// + +// Exercises relative path completions going up and down 2 directories +// and the use of forward- and back-slashes and combinations thereof. + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ +// @Filename: dir1/g1.ts +//// /*g1*/ +// @Filename: dir1/g2.ts +//// /*g2*/ +// @Filename: dir1/dir2/h1.ts +//// /*h1*/ +// @Filename: dir1/dir2/h2.ts +//// /*h2*/ +// @Filename: dir1/dir2/.hidden.ts +//// /*hidden*/ +// @Filename: dir1/dir2/dir3/i1.ts +//// /*i1*/ +// @Filename: dir1/dir2/dir3/i2.ts +//// /*i2*/ +// @Filename: dir1/dir2/dir3/dir4/j1.ts +//// /*j1*/ +// @Filename: dir1/dir2/dir3/dir4/j2.ts +//// /*j2*/ + + +// @Filename: dir1/dir2/test.ts +//// /// Date: Tue, 27 Sep 2016 14:04:57 -0700 Subject: [PATCH 20/56] remove Comment --- src/services/completions.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 04b68544376..35a7bce5561 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -326,18 +326,9 @@ namespace ts.Completions { * Given a path ending at a directory, gets the completions for the path. */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { - /*Debug.assert(fragment !== undefined); - - if (fragment === "") { - fragment = "."; - } else { - fragment = getDirectoryPath(fragment); - } - */ - fragment = getDirectoryPath(fragment); // TODO: modify fragment so it respects our internal path representation? if (!fragment) { - fragment = "."; + fragment = "./"; } else { fragment = ensureTrailingDirectorySeparator(fragment); // TODO: why is this necessary? From 629e126718d7a6950e0394082fdd7964bdc4857f Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 28 Sep 2016 16:04:39 -0700 Subject: [PATCH 21/56] Factored out hidden path test --- .../fourslash/tripleSlashRefPathHiddenFile.ts | 28 +++++++++++++++++++ .../tripleSlashRefPathRelativePaths.ts | 8 ++---- 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts b/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts new file mode 100644 index 00000000000..6c1280637e9 --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathHiddenFile.ts @@ -0,0 +1,28 @@ +/// + +// Exercises completions for hidden files (ie: those beginning with '.') + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ +// @Filename: .hidden.ts +//// /*hidden*/ + +// @Filename: test.ts +//// /// Date: Wed, 28 Sep 2016 16:45:52 -0700 Subject: [PATCH 22/56] factor and simplify rel path test --- .../tripleSlashRefPathBackandForwardSlash.ts | 73 +++++++++ .../tripleSlashRefPathCompletionsNarrow.ts | 21 +++ .../fourslash/tripleSlashRefPathHiddenFile.ts | 9 +- .../tripleSlashRefPathRelativePaths.ts | 143 ++++++------------ 4 files changed, 145 insertions(+), 101 deletions(-) create mode 100644 tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts create mode 100644 tests/cases/fourslash/tripleSlashRefPathCompletionsNarrow.ts diff --git a/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts b/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts new file mode 100644 index 00000000000..c7cae3c4a45 --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathBackandForwardSlash.ts @@ -0,0 +1,73 @@ +/// + +// Exercises completions for hidden files (ie: those beginning with '.') + +// @Filename: f.ts +//// /*f1*/ +// @Filename: d1/g.ts +//// /*g1*/ +// @Filename: d1/d2/h.ts +//// /*h1*/ +// @Filename: d1/d2/d3/i.ts +//// /// + +// Exercises relative path completions going up and down 2 directories +// and the use of forward- and back-slashes and combinations thereof. + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ + +// @Filename: test.ts +//// ///