From 5eff0a5fae2aeb6579f1117c3edbd427a28856fe Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 May 2015 12:03:13 -0700 Subject: [PATCH] Adding tests --- tests/baselines/reference/localTypes1.js | 325 ++++++++++++++ tests/baselines/reference/localTypes1.symbols | 357 ++++++++++++++++ tests/baselines/reference/localTypes1.types | 395 ++++++++++++++++++ tests/baselines/reference/localTypes2.js | 92 ++++ tests/baselines/reference/localTypes2.symbols | 122 ++++++ tests/baselines/reference/localTypes2.types | 134 ++++++ tests/baselines/reference/localTypes3.js | 92 ++++ tests/baselines/reference/localTypes3.symbols | 134 ++++++ tests/baselines/reference/localTypes3.types | 146 +++++++ .../reference/localTypes4.errors.txt | 53 +++ tests/baselines/reference/localTypes4.js | 70 ++++ .../types/localTypes/localTypes1.ts | 141 +++++++ .../types/localTypes/localTypes2.ts | 40 ++ .../types/localTypes/localTypes3.ts | 40 ++ .../types/localTypes/localTypes4.ts | 37 ++ 15 files changed, 2178 insertions(+) create mode 100644 tests/baselines/reference/localTypes1.js create mode 100644 tests/baselines/reference/localTypes1.symbols create mode 100644 tests/baselines/reference/localTypes1.types create mode 100644 tests/baselines/reference/localTypes2.js create mode 100644 tests/baselines/reference/localTypes2.symbols create mode 100644 tests/baselines/reference/localTypes2.types create mode 100644 tests/baselines/reference/localTypes3.js create mode 100644 tests/baselines/reference/localTypes3.symbols create mode 100644 tests/baselines/reference/localTypes3.types create mode 100644 tests/baselines/reference/localTypes4.errors.txt create mode 100644 tests/baselines/reference/localTypes4.js create mode 100644 tests/cases/conformance/types/localTypes/localTypes1.ts create mode 100644 tests/cases/conformance/types/localTypes/localTypes2.ts create mode 100644 tests/cases/conformance/types/localTypes/localTypes3.ts create mode 100644 tests/cases/conformance/types/localTypes/localTypes4.ts diff --git a/tests/baselines/reference/localTypes1.js b/tests/baselines/reference/localTypes1.js new file mode 100644 index 00000000000..d1c3758920e --- /dev/null +++ b/tests/baselines/reference/localTypes1.js @@ -0,0 +1,325 @@ +//// [localTypes1.ts] + +function f1() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; +} + +function f2() { + function g() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} + +function f3(b: boolean) { + if (true) { + enum E { + A, B, C + } + if (b) { + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + else { + class A { + x: E; + } + interface J { + x: E; + } + type C = J[]; + let c: C = [new A()]; + c[0].x = E.B; + return c; + } + } +} + +function f5() { + var z1 = function () { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + var z2 = () => { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +class A { + constructor() { + enum E { + A, B, C + } + class C { + x: E; + } + } + m() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + get p() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +function f6() { + class A { + a: string; + } + function g() { + class B extends A { + b: string; + } + function h() { + class C extends B { + c: string; + } + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} + + +//// [localTypes1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +function f1() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; +} +function f2() { + function g() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} +function f3(b) { + if (true) { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + if (b) { + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; + } + else { + var A = (function () { + function A() { + } + return A; + })(); + var c = [new A()]; + c[0].x = E.B; + return c; + } + } +} +function f5() { + var z1 = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; + var z2 = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; +} +var A = (function () { + function A() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + } + A.prototype.m = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; + Object.defineProperty(A.prototype, "p", { + get: function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }, + enumerable: true, + configurable: true + }); + return A; +})(); +function f6() { + var A = (function () { + function A() { + } + return A; + })(); + function g() { + var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; + })(A); + function h() { + var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; + })(B); + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} diff --git a/tests/baselines/reference/localTypes1.symbols b/tests/baselines/reference/localTypes1.symbols new file mode 100644 index 00000000000..53d4191ae61 --- /dev/null +++ b/tests/baselines/reference/localTypes1.symbols @@ -0,0 +1,357 @@ +=== tests/cases/conformance/types/localTypes/localTypes1.ts === + +function f1() { +>f1 : Symbol(f1, Decl(localTypes1.ts, 0, 0)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 2, 12)) +>B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) +>C : Symbol(E.C, Decl(localTypes1.ts, 3, 13)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 4, 5)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 5, 13)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 7, 5)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 8, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 10, 5)) +>I : Symbol(I, Decl(localTypes1.ts, 7, 5)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +>A : Symbol(A, Decl(localTypes1.ts, 10, 5)) +>C : Symbol(C, Decl(localTypes1.ts, 4, 5)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 8, 17)) +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +>x : Symbol(I.x, Decl(localTypes1.ts, 8, 17)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes1.ts, 15, 1)) + + function g() { +>g : Symbol(g, Decl(localTypes1.ts, 17, 15)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 19, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 20, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 21, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 22, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 24, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 25, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 27, 9)) +>I : Symbol(I, Decl(localTypes1.ts, 24, 9)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) +>A : Symbol(A, Decl(localTypes1.ts, 27, 9)) +>C : Symbol(C, Decl(localTypes1.ts, 21, 9)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 25, 21)) +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) +>x : Symbol(I.x, Decl(localTypes1.ts, 25, 21)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) +>B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) + } + return g(); +>g : Symbol(g, Decl(localTypes1.ts, 17, 15)) +} + +function f3(b: boolean) { +>f3 : Symbol(f3, Decl(localTypes1.ts, 34, 1)) +>b : Symbol(b, Decl(localTypes1.ts, 36, 12)) + + if (true) { + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 38, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 39, 17)) + } + if (b) { +>b : Symbol(b, Decl(localTypes1.ts, 36, 12)) + + class C { +>C : Symbol(C, Decl(localTypes1.ts, 41, 16)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 42, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 44, 13)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 45, 25)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 47, 13)) +>I : Symbol(I, Decl(localTypes1.ts, 44, 13)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) +>A : Symbol(A, Decl(localTypes1.ts, 47, 13)) +>C : Symbol(C, Decl(localTypes1.ts, 41, 16)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 45, 25)) +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) +>x : Symbol(I.x, Decl(localTypes1.ts, 45, 25)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) + } + else { + class A { +>A : Symbol(A, Decl(localTypes1.ts, 53, 14)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 54, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + interface J { +>J : Symbol(J, Decl(localTypes1.ts, 56, 13)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 57, 25)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + type C = J[]; +>C : Symbol(C, Decl(localTypes1.ts, 59, 13)) +>J : Symbol(J, Decl(localTypes1.ts, 56, 13)) + + let c: C = [new A()]; +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) +>C : Symbol(C, Decl(localTypes1.ts, 59, 13)) +>A : Symbol(A, Decl(localTypes1.ts, 53, 14)) + + c[0].x = E.B; +>c[0].x : Symbol(J.x, Decl(localTypes1.ts, 57, 25)) +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) +>x : Symbol(J.x, Decl(localTypes1.ts, 57, 25)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) + + return c; +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) + } + } +} + +function f5() { +>f5 : Symbol(f5, Decl(localTypes1.ts, 66, 1)) + + var z1 = function () { +>z1 : Symbol(z1, Decl(localTypes1.ts, 69, 7)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 69, 26)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 70, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 71, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 71, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 72, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 73, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 69, 26)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 72, 9)) + } + var z2 = () => { +>z2 : Symbol(z2, Decl(localTypes1.ts, 78, 7)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 78, 20)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 79, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 80, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 80, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 81, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 82, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 78, 20)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 81, 9)) + } +} + +class A { +>A : Symbol(A, Decl(localTypes1.ts, 87, 1)) + + constructor() { + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 90, 19)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 91, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 92, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 92, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 93, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 94, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 90, 19)) + } + } + m() { +>m : Symbol(m, Decl(localTypes1.ts, 97, 5)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 98, 9)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 99, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 100, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 100, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 101, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 102, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 98, 9)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 101, 9)) + } + get p() { +>p : Symbol(p, Decl(localTypes1.ts, 106, 5)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 107, 13)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 108, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 109, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 109, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 110, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 111, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 107, 13)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 110, 9)) + } +} + +function f6() { +>f6 : Symbol(f6, Decl(localTypes1.ts, 116, 1)) + + class A { +>A : Symbol(A, Decl(localTypes1.ts, 118, 15)) + + a: string; +>a : Symbol(a, Decl(localTypes1.ts, 119, 13)) + } + function g() { +>g : Symbol(g, Decl(localTypes1.ts, 121, 5)) + + class B extends A { +>B : Symbol(B, Decl(localTypes1.ts, 122, 18)) +>A : Symbol(A, Decl(localTypes1.ts, 118, 15)) + + b: string; +>b : Symbol(b, Decl(localTypes1.ts, 123, 27)) + } + function h() { +>h : Symbol(h, Decl(localTypes1.ts, 125, 9)) + + class C extends B { +>C : Symbol(C, Decl(localTypes1.ts, 126, 22)) +>B : Symbol(B, Decl(localTypes1.ts, 122, 18)) + + c: string; +>c : Symbol(c, Decl(localTypes1.ts, 127, 31)) + } + var x = new C(); +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>C : Symbol(C, Decl(localTypes1.ts, 126, 22)) + + x.a = "a"; +>x.a : Symbol(A.a, Decl(localTypes1.ts, 119, 13)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>a : Symbol(A.a, Decl(localTypes1.ts, 119, 13)) + + x.b = "b"; +>x.b : Symbol(B.b, Decl(localTypes1.ts, 123, 27)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>b : Symbol(B.b, Decl(localTypes1.ts, 123, 27)) + + x.c = "c"; +>x.c : Symbol(C.c, Decl(localTypes1.ts, 127, 31)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>c : Symbol(C.c, Decl(localTypes1.ts, 127, 31)) + + return x; +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) + } + return h(); +>h : Symbol(h, Decl(localTypes1.ts, 125, 9)) + } + return g(); +>g : Symbol(g, Decl(localTypes1.ts, 121, 5)) +} + diff --git a/tests/baselines/reference/localTypes1.types b/tests/baselines/reference/localTypes1.types new file mode 100644 index 00000000000..1770a36edb7 --- /dev/null +++ b/tests/baselines/reference/localTypes1.types @@ -0,0 +1,395 @@ +=== tests/cases/conformance/types/localTypes/localTypes1.ts === + +function f1() { +>f1 : () => I[] + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] +} + +function f2() { +>f2 : () => I[] + + function g() { +>g : () => I[] + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] + } + return g(); +>g() : I[] +>g : () => I[] +} + +function f3(b: boolean) { +>f3 : (b: boolean) => I[] +>b : boolean + + if (true) { +>true : boolean + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + if (b) { +>b : boolean + + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] + } + else { + class A { +>A : A + + x: E; +>x : E +>E : E + } + interface J { +>J : J + + x: E; +>x : E +>E : E + } + type C = J[]; +>C : J[] +>J : J + + let c: C = [new A()]; +>c : J[] +>C : J[] +>[new A()] : A[] +>new A() : A +>A : typeof A + + c[0].x = E.B; +>c[0].x = E.B : E +>c[0].x : E +>c[0] : J +>c : J[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return c; +>c : J[] + } + } +} + +function f5() { +>f5 : () => void + + var z1 = function () { +>z1 : () => C +>function () { enum E { A, B, C } class C { x: E; } return new C(); } : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } + var z2 = () => { +>z2 : () => C +>() => { enum E { A, B, C } class C { x: E; } return new C(); } : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } +} + +class A { +>A : A + + constructor() { + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + } + m() { +>m : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } + get p() { +>p : C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } +} + +function f6() { +>f6 : () => C + + class A { +>A : A + + a: string; +>a : string + } + function g() { +>g : () => C + + class B extends A { +>B : B +>A : A + + b: string; +>b : string + } + function h() { +>h : () => C + + class C extends B { +>C : C +>B : B + + c: string; +>c : string + } + var x = new C(); +>x : C +>new C() : C +>C : typeof C + + x.a = "a"; +>x.a = "a" : string +>x.a : string +>x : C +>a : string +>"a" : string + + x.b = "b"; +>x.b = "b" : string +>x.b : string +>x : C +>b : string +>"b" : string + + x.c = "c"; +>x.c = "c" : string +>x.c : string +>x : C +>c : string +>"c" : string + + return x; +>x : C + } + return h(); +>h() : C +>h : () => C + } + return g(); +>g() : C +>g : () => C +} + diff --git a/tests/baselines/reference/localTypes2.js b/tests/baselines/reference/localTypes2.js new file mode 100644 index 00000000000..a95844f0794 --- /dev/null +++ b/tests/baselines/reference/localTypes2.js @@ -0,0 +1,92 @@ +//// [localTypes2.ts] +function f1() { + function f() { + class C { + constructor(public x: number, public y: number) { } + } + return C; + } + let C = f(); + let v = new C(10, 20); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: number) { + class C { + public x = x; + constructor(public y: number) { } + } + return C; + } + let C = f(10); + let v = new C(20); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: number, y: number) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, 20); + let v = new C(); + let x = v.x; + let y = v.y; +} + + +//// [localTypes2.js] +function f1() { + function f() { + var C = (function () { + function C(x, y) { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(); + var v = new C(10, 20); + var x = v.x; + var y = v.y; +} +function f2() { + function f(x) { + var C = (function () { + function C(y) { + this.y = y; + this.x = x; + } + return C; + })(); + return C; + } + var C = f(10); + var v = new C(20); + var x = v.x; + var y = v.y; +} +function f3() { + function f(x, y) { + var C = (function () { + function C() { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(10, 20); + var v = new C(); + var x = v.x; + var y = v.y; +} diff --git a/tests/baselines/reference/localTypes2.symbols b/tests/baselines/reference/localTypes2.symbols new file mode 100644 index 00000000000..3054c6f552d --- /dev/null +++ b/tests/baselines/reference/localTypes2.symbols @@ -0,0 +1,122 @@ +=== tests/cases/conformance/types/localTypes/localTypes2.ts === +function f1() { +>f1 : Symbol(f1, Decl(localTypes2.ts, 0, 0)) + + function f() { +>f : Symbol(f, Decl(localTypes2.ts, 0, 15)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 1, 18)) + + constructor(public x: number, public y: number) { } +>x : Symbol(x, Decl(localTypes2.ts, 3, 24)) +>y : Symbol(y, Decl(localTypes2.ts, 3, 41)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 1, 18)) + } + let C = f(); +>C : Symbol(C, Decl(localTypes2.ts, 7, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 0, 15)) + + let v = new C(10, 20); +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 7, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 9, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 3, 24)) +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 3, 24)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 10, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 3, 41)) +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 3, 41)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes2.ts, 11, 1)) + + function f(x: number) { +>f : Symbol(f, Decl(localTypes2.ts, 13, 15)) +>x : Symbol(x, Decl(localTypes2.ts, 14, 15)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 14, 27)) + + public x = x; +>x : Symbol(x, Decl(localTypes2.ts, 15, 17)) +>x : Symbol(x, Decl(localTypes2.ts, 14, 15)) + + constructor(public y: number) { } +>y : Symbol(y, Decl(localTypes2.ts, 17, 24)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 14, 27)) + } + let C = f(10); +>C : Symbol(C, Decl(localTypes2.ts, 21, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 13, 15)) + + let v = new C(20); +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 21, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 23, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 15, 17)) +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 15, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 24, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 17, 24)) +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 17, 24)) +} + +function f3() { +>f3 : Symbol(f3, Decl(localTypes2.ts, 25, 1)) + + function f(x: number, y: number) { +>f : Symbol(f, Decl(localTypes2.ts, 27, 15)) +>x : Symbol(x, Decl(localTypes2.ts, 28, 15)) +>y : Symbol(y, Decl(localTypes2.ts, 28, 25)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 28, 38)) + + public x = x; +>x : Symbol(x, Decl(localTypes2.ts, 29, 17)) +>x : Symbol(x, Decl(localTypes2.ts, 28, 15)) + + public y = y; +>y : Symbol(y, Decl(localTypes2.ts, 30, 25)) +>y : Symbol(y, Decl(localTypes2.ts, 28, 25)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 28, 38)) + } + let C = f(10, 20); +>C : Symbol(C, Decl(localTypes2.ts, 35, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 27, 15)) + + let v = new C(); +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 35, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 37, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 29, 17)) +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 29, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 38, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 30, 25)) +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 30, 25)) +} + diff --git a/tests/baselines/reference/localTypes2.types b/tests/baselines/reference/localTypes2.types new file mode 100644 index 00000000000..a6b85b7bb14 --- /dev/null +++ b/tests/baselines/reference/localTypes2.types @@ -0,0 +1,134 @@ +=== tests/cases/conformance/types/localTypes/localTypes2.ts === +function f1() { +>f1 : () => void + + function f() { +>f : () => typeof C + + class C { +>C : C + + constructor(public x: number, public y: number) { } +>x : number +>y : number + } + return C; +>C : typeof C + } + let C = f(); +>C : typeof C +>f() : typeof C +>f : () => typeof C + + let v = new C(10, 20); +>v : C +>new C(10, 20) : C +>C : typeof C +>10 : number +>20 : number + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + +function f2() { +>f2 : () => void + + function f(x: number) { +>f : (x: number) => typeof C +>x : number + + class C { +>C : C + + public x = x; +>x : number +>x : number + + constructor(public y: number) { } +>y : number + } + return C; +>C : typeof C + } + let C = f(10); +>C : typeof C +>f(10) : typeof C +>f : (x: number) => typeof C +>10 : number + + let v = new C(20); +>v : C +>new C(20) : C +>C : typeof C +>20 : number + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + +function f3() { +>f3 : () => void + + function f(x: number, y: number) { +>f : (x: number, y: number) => typeof C +>x : number +>y : number + + class C { +>C : C + + public x = x; +>x : number +>x : number + + public y = y; +>y : number +>y : number + } + return C; +>C : typeof C + } + let C = f(10, 20); +>C : typeof C +>f(10, 20) : typeof C +>f : (x: number, y: number) => typeof C +>10 : number +>20 : number + + let v = new C(); +>v : C +>new C() : C +>C : typeof C + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + diff --git a/tests/baselines/reference/localTypes3.js b/tests/baselines/reference/localTypes3.js new file mode 100644 index 00000000000..2d40bc922b9 --- /dev/null +++ b/tests/baselines/reference/localTypes3.js @@ -0,0 +1,92 @@ +//// [localTypes3.ts] +function f1() { + function f() { + class C { + constructor(public x: X, public y: Y) { } + } + return C; + } + let C = f(); + let v = new C(10, "hello"); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: X) { + class C { + public x = x; + constructor(public y: Y) { } + } + return C; + } + let C = f(10); + let v = new C("hello"); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: X, y: Y) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, "hello"); + let v = new C(); + let x = v.x; + let y = v.y; +} + + +//// [localTypes3.js] +function f1() { + function f() { + var C = (function () { + function C(x, y) { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(); + var v = new C(10, "hello"); + var x = v.x; + var y = v.y; +} +function f2() { + function f(x) { + var C = (function () { + function C(y) { + this.y = y; + this.x = x; + } + return C; + })(); + return C; + } + var C = f(10); + var v = new C("hello"); + var x = v.x; + var y = v.y; +} +function f3() { + function f(x, y) { + var C = (function () { + function C() { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(10, "hello"); + var v = new C(); + var x = v.x; + var y = v.y; +} diff --git a/tests/baselines/reference/localTypes3.symbols b/tests/baselines/reference/localTypes3.symbols new file mode 100644 index 00000000000..fe7082e4577 --- /dev/null +++ b/tests/baselines/reference/localTypes3.symbols @@ -0,0 +1,134 @@ +=== tests/cases/conformance/types/localTypes/localTypes3.ts === +function f1() { +>f1 : Symbol(f1, Decl(localTypes3.ts, 0, 0)) + + function f() { +>f : Symbol(f, Decl(localTypes3.ts, 0, 15)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 1, 18)) +>X : Symbol(X, Decl(localTypes3.ts, 2, 16)) +>Y : Symbol(Y, Decl(localTypes3.ts, 2, 18)) + + constructor(public x: X, public y: Y) { } +>x : Symbol(x, Decl(localTypes3.ts, 3, 24)) +>X : Symbol(X, Decl(localTypes3.ts, 2, 16)) +>y : Symbol(y, Decl(localTypes3.ts, 3, 36)) +>Y : Symbol(Y, Decl(localTypes3.ts, 2, 18)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 1, 18)) + } + let C = f(); +>C : Symbol(C, Decl(localTypes3.ts, 7, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 0, 15)) + + let v = new C(10, "hello"); +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 7, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 9, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 3, 24)) +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 3, 24)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 10, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 3, 36)) +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 3, 36)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes3.ts, 11, 1)) + + function f(x: X) { +>f : Symbol(f, Decl(localTypes3.ts, 13, 15)) +>X : Symbol(X, Decl(localTypes3.ts, 14, 15)) +>x : Symbol(x, Decl(localTypes3.ts, 14, 18)) +>X : Symbol(X, Decl(localTypes3.ts, 14, 15)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 14, 25)) +>Y : Symbol(Y, Decl(localTypes3.ts, 15, 16)) + + public x = x; +>x : Symbol(x, Decl(localTypes3.ts, 15, 20)) +>x : Symbol(x, Decl(localTypes3.ts, 14, 18)) + + constructor(public y: Y) { } +>y : Symbol(y, Decl(localTypes3.ts, 17, 24)) +>Y : Symbol(Y, Decl(localTypes3.ts, 15, 16)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 14, 25)) + } + let C = f(10); +>C : Symbol(C, Decl(localTypes3.ts, 21, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 13, 15)) + + let v = new C("hello"); +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 21, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 23, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 15, 20)) +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 15, 20)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 24, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 17, 24)) +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 17, 24)) +} + +function f3() { +>f3 : Symbol(f3, Decl(localTypes3.ts, 25, 1)) + + function f(x: X, y: Y) { +>f : Symbol(f, Decl(localTypes3.ts, 27, 15)) +>X : Symbol(X, Decl(localTypes3.ts, 28, 15)) +>Y : Symbol(Y, Decl(localTypes3.ts, 28, 17)) +>x : Symbol(x, Decl(localTypes3.ts, 28, 21)) +>X : Symbol(X, Decl(localTypes3.ts, 28, 15)) +>y : Symbol(y, Decl(localTypes3.ts, 28, 26)) +>Y : Symbol(Y, Decl(localTypes3.ts, 28, 17)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 28, 34)) + + public x = x; +>x : Symbol(x, Decl(localTypes3.ts, 29, 17)) +>x : Symbol(x, Decl(localTypes3.ts, 28, 21)) + + public y = y; +>y : Symbol(y, Decl(localTypes3.ts, 30, 25)) +>y : Symbol(y, Decl(localTypes3.ts, 28, 26)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 28, 34)) + } + let C = f(10, "hello"); +>C : Symbol(C, Decl(localTypes3.ts, 35, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 27, 15)) + + let v = new C(); +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 35, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 37, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 29, 17)) +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 29, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 38, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 30, 25)) +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 30, 25)) +} + diff --git a/tests/baselines/reference/localTypes3.types b/tests/baselines/reference/localTypes3.types new file mode 100644 index 00000000000..77b397431b7 --- /dev/null +++ b/tests/baselines/reference/localTypes3.types @@ -0,0 +1,146 @@ +=== tests/cases/conformance/types/localTypes/localTypes3.ts === +function f1() { +>f1 : () => void + + function f() { +>f : () => typeof C + + class C { +>C : C +>X : X +>Y : Y + + constructor(public x: X, public y: Y) { } +>x : X +>X : X +>y : Y +>Y : Y + } + return C; +>C : typeof C + } + let C = f(); +>C : typeof C +>f() : typeof C +>f : () => typeof C + + let v = new C(10, "hello"); +>v : C +>new C(10, "hello") : C +>C : typeof C +>10 : number +>"hello" : string + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : C +>y : string +} + +function f2() { +>f2 : () => void + + function f(x: X) { +>f : (x: X) => typeof C +>X : X +>x : X +>X : X + + class C { +>C : C +>Y : Y + + public x = x; +>x : X +>x : X + + constructor(public y: Y) { } +>y : Y +>Y : Y + } + return C; +>C : typeof C + } + let C = f(10); +>C : typeof C +>f(10) : typeof C +>f : (x: X) => typeof C +>10 : number + + let v = new C("hello"); +>v : C +>new C("hello") : C +>C : typeof C +>"hello" : string + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : C +>y : string +} + +function f3() { +>f3 : () => void + + function f(x: X, y: Y) { +>f : (x: X, y: Y) => typeof C +>X : X +>Y : Y +>x : X +>X : X +>y : Y +>Y : Y + + class C { +>C : C + + public x = x; +>x : X +>x : X + + public y = y; +>y : Y +>y : Y + } + return C; +>C : typeof C + } + let C = f(10, "hello"); +>C : typeof C +>f(10, "hello") : typeof C +>f : (x: X, y: Y) => typeof C +>10 : number +>"hello" : string + + let v = new C(); +>v : C +>new C() : C +>C : typeof C + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : C +>y : string +} + diff --git a/tests/baselines/reference/localTypes4.errors.txt b/tests/baselines/reference/localTypes4.errors.txt new file mode 100644 index 00000000000..cad9d30c933 --- /dev/null +++ b/tests/baselines/reference/localTypes4.errors.txt @@ -0,0 +1,53 @@ +tests/cases/conformance/types/localTypes/localTypes4.ts(10,19): error TS2304: Cannot find name 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(10,23): error TS2304: Cannot find name 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(18,16): error TS2300: Duplicate identifier 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(19,19): error TS2300: Duplicate identifier 'T'. + + +==== tests/cases/conformance/types/localTypes/localTypes4.ts (4 errors) ==== + function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } + } + + function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + ~ +!!! error TS2304: Cannot find name 'T'. + ~ +!!! error TS2304: Cannot find name 'T'. + interface T { } + return undefined; + } + } + + function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + ~ +!!! error TS2300: Duplicate identifier 'T'. + interface T { } + ~ +!!! error TS2300: Duplicate identifier 'T'. + return undefined; + } + } + + function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/localTypes4.js b/tests/baselines/reference/localTypes4.js new file mode 100644 index 00000000000..8f51761a65a --- /dev/null +++ b/tests/baselines/reference/localTypes4.js @@ -0,0 +1,70 @@ +//// [localTypes4.ts] +function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } +} + +function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + interface T { } + return undefined; + } +} + +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + interface T { } + return undefined; + } +} + +function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } +} + + +//// [localTypes4.js] +function f1() { + // Type parameters are in scope in parameters and return types + function f(x) { + return undefined; + } +} +function f2() { + // Local types are not in scope in parameters and return types + function f(x) { + return undefined; + } +} +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + return undefined; + } +} +function f4() { + var v; + v.x = 10; + if (true) { + var v_1; + v_1.x = "hello"; + } + else { + v.x = 20; + } +} diff --git a/tests/cases/conformance/types/localTypes/localTypes1.ts b/tests/cases/conformance/types/localTypes/localTypes1.ts new file mode 100644 index 00000000000..bceb9ad32cf --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes1.ts @@ -0,0 +1,141 @@ +// @target: es5 + +function f1() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; +} + +function f2() { + function g() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} + +function f3(b: boolean) { + if (true) { + enum E { + A, B, C + } + if (b) { + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + else { + class A { + x: E; + } + interface J { + x: E; + } + type C = J[]; + let c: C = [new A()]; + c[0].x = E.B; + return c; + } + } +} + +function f5() { + var z1 = function () { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + var z2 = () => { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +class A { + constructor() { + enum E { + A, B, C + } + class C { + x: E; + } + } + m() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + get p() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +function f6() { + class A { + a: string; + } + function g() { + class B extends A { + b: string; + } + function h() { + class C extends B { + c: string; + } + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} diff --git a/tests/cases/conformance/types/localTypes/localTypes2.ts b/tests/cases/conformance/types/localTypes/localTypes2.ts new file mode 100644 index 00000000000..79f1402c702 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes2.ts @@ -0,0 +1,40 @@ +function f1() { + function f() { + class C { + constructor(public x: number, public y: number) { } + } + return C; + } + let C = f(); + let v = new C(10, 20); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: number) { + class C { + public x = x; + constructor(public y: number) { } + } + return C; + } + let C = f(10); + let v = new C(20); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: number, y: number) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, 20); + let v = new C(); + let x = v.x; + let y = v.y; +} diff --git a/tests/cases/conformance/types/localTypes/localTypes3.ts b/tests/cases/conformance/types/localTypes/localTypes3.ts new file mode 100644 index 00000000000..5eb3cf28506 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes3.ts @@ -0,0 +1,40 @@ +function f1() { + function f() { + class C { + constructor(public x: X, public y: Y) { } + } + return C; + } + let C = f(); + let v = new C(10, "hello"); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: X) { + class C { + public x = x; + constructor(public y: Y) { } + } + return C; + } + let C = f(10); + let v = new C("hello"); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: X, y: Y) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, "hello"); + let v = new C(); + let x = v.x; + let y = v.y; +} diff --git a/tests/cases/conformance/types/localTypes/localTypes4.ts b/tests/cases/conformance/types/localTypes/localTypes4.ts new file mode 100644 index 00000000000..bd31e76a80f --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes4.ts @@ -0,0 +1,37 @@ +function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } +} + +function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + interface T { } + return undefined; + } +} + +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + interface T { } + return undefined; + } +} + +function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } +}