From b434ee42a85700b1865fc43c180a97edbfecfb2e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 16:06:34 -0800 Subject: [PATCH 1/8] Added tests. --- ...estructuringPropertyParameters1.errors.txt | 68 +++++++++++++++++++ ...estructuringPropertyParameters2.errors.txt | 53 +++++++++++++++ .../destructuringPropertyParameters2.js | 58 ++++++++++++++++ ...estructuringPropertyParameters3.errors.txt | 53 +++++++++++++++ .../destructuringPropertyParameters3.js | 63 +++++++++++++++++ ...estructuringPropertyParameters4.errors.txt | 57 ++++++++++++++++ .../destructuringPropertyParameters4.js | 65 ++++++++++++++++++ ...estructuringPropertyParameters5.errors.txt | 51 ++++++++++++++ .../destructuringPropertyParameters1.ts | 29 ++++++++ .../destructuringPropertyParameters2.ts | 28 ++++++++ .../destructuringPropertyParameters3.ts | 31 +++++++++ .../destructuringPropertyParameters4.ts | 27 ++++++++ .../destructuringPropertyParameters5.ts | 12 ++++ 13 files changed, 595 insertions(+) create mode 100644 tests/baselines/reference/destructuringPropertyParameters1.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters2.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters2.js create mode 100644 tests/baselines/reference/destructuringPropertyParameters3.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters3.js create mode 100644 tests/baselines/reference/destructuringPropertyParameters4.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters4.js create mode 100644 tests/baselines/reference/destructuringPropertyParameters5.errors.txt create mode 100644 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts diff --git a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt new file mode 100644 index 0000000000000..58625d2d115c7 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt @@ -0,0 +1,68 @@ +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(16,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,26): error TS2339: Property 'x' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,35): error TS2339: Property 'y' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,43): error TS2339: Property 'y' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,52): error TS2339: Property 'z' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(27,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,6): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,23): error TS1005: ':' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (12 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + } + } + + type TupleType1 = [string, number, boolean]; + + class C2 { + constructor(public [x, y, z]: TupleType1) { + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~ +!!! error TS1005: ',' expected. + } + } + + var c1 = new C1([]); + c1 = new C1(["larry", "{curly}", "moe"]); + var useC1Properties = c1.x === c1.y && c1.y === c1.z; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C1'. + + var c2 = new C2(["10", 10, !!10]); + var useC2Properties = c2.x === c2.y && c2.y === c2.z; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C2'. + + var c3 = new C3({x: 0, y: "", z: false}); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + c3 = new C3({x: 0, "y", z: true}); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~ +!!! error TS1005: ':' expected. + var useC3Properties = c3.x === c3.y && c3.y === c3.z; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters2.errors.txt b/tests/baselines/reference/destructuringPropertyParameters2.errors.txt new file mode 100644 index 0000000000000..75d873cf3d653 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters2.errors.txt @@ -0,0 +1,53 @@ +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. + + +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts (7 errors) ==== + class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + var x = new C1(undefined, [0, undefined, ""]); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. + var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + + var y = new C1(10, [0, "", true]); + var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + + var z = new C1(10, [undefined, "", null]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters2.js b/tests/baselines/reference/destructuringPropertyParameters2.js new file mode 100644 index 0000000000000..026fe4896f850 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters2.js @@ -0,0 +1,58 @@ +//// [destructuringPropertyParameters2.ts] +class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, undefined, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, "", true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", null]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + +//// [destructuringPropertyParameters2.js] +var C1 = (function () { + function C1(k, _a) { + var a = _a[0], b = _a[1], c = _a[2]; + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var x = new C1(undefined, [0, undefined, ""]); +var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2]; +var y = new C1(10, [0, "", true]); +var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2]; +var z = new C1(10, [undefined, "", null]); +var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters3.errors.txt b/tests/baselines/reference/destructuringPropertyParameters3.errors.txt new file mode 100644 index 0000000000000..15cd0dbdebfb8 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters3.errors.txt @@ -0,0 +1,53 @@ +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. + + +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts (6 errors) ==== + class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + var x = new C1(undefined, [0, true, ""]); + var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + + var y = new C1(10, [0, true, true]); + var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + + var z = new C1(10, [undefined, "", ""]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + var w = new C1(10, [undefined, undefined, undefined]); + var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters3.js b/tests/baselines/reference/destructuringPropertyParameters3.js new file mode 100644 index 0000000000000..538f58d53f75f --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters3.js @@ -0,0 +1,63 @@ +//// [destructuringPropertyParameters3.ts] +class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, true, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, true, true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", ""]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + +var w = new C1(10, [undefined, undefined, undefined]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + + +//// [destructuringPropertyParameters3.js] +var C1 = (function () { + function C1(k, _a) { + var a = _a[0], b = _a[1], c = _a[2]; + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var x = new C1(undefined, [0, true, ""]); +var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2]; +var y = new C1(10, [0, true, true]); +var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2]; +var z = new C1(10, [undefined, "", ""]); +var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2]; +var w = new C1(10, [undefined, undefined, undefined]); +var _d = [z.getA(), z.getB(), z.getC()], z_a = _d[0], z_b = _d[1], z_c = _d[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters4.errors.txt b/tests/baselines/reference/destructuringPropertyParameters4.errors.txt new file mode 100644 index 0000000000000..f8c9e899ebb51 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters4.errors.txt @@ -0,0 +1,57 @@ +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(10,21): error TS2339: Property 'a' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(14,21): error TS2339: Property 'b' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(18,21): error TS2339: Property 'c' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,24): error TS2339: Property 'x' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,34): error TS2339: Property 'y' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,44): error TS2339: Property 'z' does not exist on type 'C2'. + + +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts (9 errors) ==== + + class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + this.a = a || k; + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + } + + public getA() { + return this.a + ~ +!!! error TS2339: Property 'a' does not exist on type 'C1'. + } + + public getB() { + return this.b + ~ +!!! error TS2339: Property 'b' does not exist on type 'C1'. + } + + public getC() { + return this.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'C1'. + } + } + + class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.x} ${this.y} ${this.z}`; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C2'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C2'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters4.js b/tests/baselines/reference/destructuringPropertyParameters4.js new file mode 100644 index 0000000000000..02784ad5f8263 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters4.js @@ -0,0 +1,65 @@ +//// [destructuringPropertyParameters4.ts] + +class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.x} ${this.y} ${this.z}`; + } +} + + +//// [destructuringPropertyParameters4.js] +var __extends = 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 __(); +}; +var C1 = (function () { + function C1(k, [a, b, c]) { + this.k = k; + this.[a, b, c] = [a, b, c]; + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + C1.prototype.getA = function () { + return this.a; + }; + C1.prototype.getB = function () { + return this.b; + }; + C1.prototype.getC = function () { + return this.c; + }; + return C1; +})(); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + C2.prototype.doSomethingWithSuperProperties = function () { + return `${this.x} ${this.y} ${this.z}`; + }; + return C2; +})(C1); diff --git a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt new file mode 100644 index 0000000000000..4531b82d647f5 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,29): error TS2339: Property 'x1' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,40): error TS2339: Property 'x2' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,51): error TS2339: Property 'x3' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,62): error TS2339: Property 'y' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,72): error TS2339: Property 'z' does not exist on type 'C1'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. + Types of property '0' are incompatible. + Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. + Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,56): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (10 errors) ==== + type ObjType1 = { x: number; y: string; z: boolean } + type TupleType1 = [ObjType1, number, string] + + class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. + ~~ +!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + ~~ +!!! error TS2339: Property 'x1' does not exist on type 'C1'. + ~~ +!!! error TS2339: Property 'x2' does not exist on type 'C1'. + ~~ +!!! error TS2339: Property 'x3' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C1'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C1'. + } + } + + var a = new C1([{ x1: 10, x2: "", x3: true }, "", false); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. +!!! error TS2345: Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. + ~ +!!! error TS1005: ',' expected. + var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts new file mode 100644 index 0000000000000..8571db338e88b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts @@ -0,0 +1,29 @@ +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 = [string, number, boolean]; + +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } + +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; + +var c2 = new C2(["10", 10, !!10]); +var useC2Properties = c2.x === c2.y && c2.y === c2.z; + +var c3 = new C3({x: 0, y: "", z: false}); +c3 = new C3({x: 0, "y", z: true}); +var useC3Properties = c3.x === c3.y && c3.y === c3.z; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts new file mode 100644 index 0000000000000..b7f37809154be --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts @@ -0,0 +1,28 @@ +class C1 { + constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, undefined, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, "", true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", null]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts new file mode 100644 index 0000000000000..6819d024e6a15 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts @@ -0,0 +1,31 @@ +class C1 { + constructor(private k: T, private [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +var x = new C1(undefined, [0, true, ""]); +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; + +var y = new C1(10, [0, true, true]); +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; + +var z = new C1(10, [undefined, "", ""]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; + +var w = new C1(10, [undefined, undefined, undefined]); +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts new file mode 100644 index 0000000000000..e8a494b227481 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts @@ -0,0 +1,27 @@ +// @target: es6 + +class C1 { + constructor(private k: T, protected [a, b, c]: [T,U,V]) { + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { + this.a = a || k; + } + } + + public getA() { + return this.a + } + + public getB() { + return this.b + } + + public getC() { + return this.c; + } +} + +class C2 extends C1 { + public doSomethingWithSuperProperties() { + return `${this.x} ${this.y} ${this.z}`; + } +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts new file mode 100644 index 0000000000000..94ec1fe27b56e --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts @@ -0,0 +1,12 @@ +type ObjType1 = { x: number; y: string; z: boolean } +type TupleType1 = [ObjType1, number, string] + +class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + } +} + +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false); +var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file From 372b0a4e15e988be403d267ca67ad658f1ca7225 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 16:24:23 -0800 Subject: [PATCH 2/8] Updated parser lookahead for modifiers to anticipate object literals. --- src/compiler/parser.ts | 5 +++- ...estructuringPropertyParameters1.errors.txt | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b70c4a7a1d5cb..5ae44e5ff398a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1395,7 +1395,10 @@ module ts { } function canFollowModifier(): boolean { - return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName(); + return token === SyntaxKind.OpenBracketToken + || token === SyntaxKind.OpenBraceToken + || token === SyntaxKind.AsteriskToken + || isLiteralPropertyName(); } // True if positioned at the start of a list element diff --git a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt index 58625d2d115c7..d4ed1e27cc00b 100644 --- a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(16,24): error TS1005: ',' expected. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. @@ -7,12 +6,14 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,35): error TS2339: Property 'y' does not exist on type 'C2'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,43): error TS2339: Property 'y' does not exist on type 'C2'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,52): error TS2339: Property 'z' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(27,10): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,6): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,23): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,26): error TS2339: Property 'x' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,35): error TS2339: Property 'y' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,43): error TS2339: Property 'y' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,52): error TS2339: Property 'z' does not exist on type 'C3'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (12 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (13 errors) ==== class C1 { constructor(public [x, y, z]: string[]) { } @@ -29,8 +30,6 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28 class C3 { constructor(public { x, y, z }: ObjType1) { - ~ -!!! error TS1005: ',' expected. } } @@ -58,11 +57,15 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28 !!! error TS2339: Property 'z' does not exist on type 'C2'. var c3 = new C3({x: 0, y: "", z: false}); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. c3 = new C3({x: 0, "y", z: true}); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. ~ !!! error TS1005: ':' expected. - var useC3Properties = c3.x === c3.y && c3.y === c3.z; \ No newline at end of file + var useC3Properties = c3.x === c3.y && c3.y === c3.z; + ~ +!!! error TS2339: Property 'x' does not exist on type 'C3'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C3'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'C3'. + ~ +!!! error TS2339: Property 'z' does not exist on type 'C3'. \ No newline at end of file From e20b22c18bfcdfb838c09831ae391c9282106a3b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 16:46:41 -0800 Subject: [PATCH 3/8] Minor changes. --- 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 7604c709fbc71..8ddfb53d21f0d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7189,7 +7189,7 @@ module ts { checkVariableLikeDeclaration(node); var func = getContainingFunction(node); - if (node.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { + if (node.flags & NodeFlags.AccessibilityModifier) { func = getContainingFunction(node); if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); @@ -7208,17 +7208,20 @@ module ts { checkGrammarIndexSignature(node); } // TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled - else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType || + else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType || node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor || node.kind === SyntaxKind.ConstructSignature){ checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); + forEach(node.parameters, checkParameter); + if (node.type) { checkSourceElement(node.type); } + if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { From 38d8ab5376898c4140a1867d3377eb8f121523bd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 16:54:15 -0800 Subject: [PATCH 4/8] SymbolFlags.None --- src/compiler/binder.ts | 22 +++++++++++----------- src/compiler/checker.ts | 18 +++++++++--------- src/compiler/types.ts | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 201913a50b465..4a9a72609bdca 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -126,7 +126,7 @@ module ts { var name = getDeclarationName(node); if (name !== undefined) { - var symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + var symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(SymbolFlags.None, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -143,11 +143,11 @@ module ts { }); file.semanticDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); - symbol = createSymbol(0, name); + symbol = createSymbol(SymbolFlags.None, name); } } else { - symbol = createSymbol(0, "__missing"); + symbol = createSymbol(SymbolFlags.None, "__missing"); } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; @@ -192,7 +192,7 @@ module ts { // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. - var exportKind = 0; + var exportKind = SymbolFlags.None; if (symbolKind & SymbolFlags.Value) { exportKind |= SymbolFlags.ExportValue; } @@ -384,7 +384,7 @@ module ts { case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: if (isBindingPattern((node).name)) { - bindChildren(node, 0, /*isBlockScopeContainer*/ false); + bindChildren(node, SymbolFlags.None, /*isBlockScopeContainer*/ false); } else if (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) { bindBlockScopedVariableDeclaration(node); @@ -395,7 +395,7 @@ module ts { break; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - bindDeclaration(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); + bindDeclaration(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: @@ -407,7 +407,7 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - bindDeclaration(node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false); + bindDeclaration(node, SymbolFlags.Signature, /*excludes*/ SymbolFlags.None, /*isBlockScopeContainer*/ false); break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: @@ -415,14 +415,14 @@ module ts { // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - bindDeclaration(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : 0), + bindDeclaration(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.FunctionDeclaration: bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Constructor: - bindDeclaration(node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true); + bindDeclaration(node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None, /*isBlockScopeContainer:*/ true); break; case SyntaxKind.GetAccessor: bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); @@ -482,7 +482,7 @@ module ts { case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.SwitchStatement: - bindChildren(node, 0, /*isBlockScopeContainer*/ true); + bindChildren(node, SymbolFlags.None, /*isBlockScopeContainer*/ true); break; default: var saveParent = parent; @@ -502,7 +502,7 @@ module ts { // If this is a property-parameter, then also declare the property symbol into the // containing class. - if (node.flags & NodeFlags.AccessibilityModifier && + if ((node.flags & NodeFlags.AccessibilityModifier) && node.parent.kind === SyntaxKind.Constructor && node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ddfb53d21f0d..58f86fccb5396 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -122,7 +122,7 @@ module ts { } function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags { - var result: SymbolFlags = 0; + var result = SymbolFlags.None; if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes; if (flags & SymbolFlags.FunctionScopedVariable) result |= SymbolFlags.FunctionScopedVariableExcludes; if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes; @@ -1745,7 +1745,7 @@ module ts { function getTypeFromObjectBindingPattern(pattern: BindingPattern): Type { var members: SymbolTable = {}; forEach(pattern.elements, e => { - var flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0); + var flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : SymbolFlags.None); var name = e.propertyName || e.name; var symbol = createSymbol(flags, name.text); symbol.type = getTypeFromBindingElement(e); @@ -5481,7 +5481,7 @@ module ts { } function getDeclarationFlagsFromSymbol(s: Symbol) { - return s.valueDeclaration ? getCombinedNodeFlags(s.valueDeclaration) : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0; + return s.valueDeclaration ? getCombinedNodeFlags(s.valueDeclaration) : s.flags & SymbolFlags.Prototype ? (NodeFlags.Public | NodeFlags.Static) : SymbolFlags.None; } function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol) { @@ -7772,8 +7772,8 @@ module ts { // we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace // to denote disjoint declarationSpaces (without making new enum type). - var exportedDeclarationSpaces: SymbolFlags = 0; - var nonExportedDeclarationSpaces: SymbolFlags = 0; + var exportedDeclarationSpaces = SymbolFlags.None; + var nonExportedDeclarationSpaces = SymbolFlags.None; forEach(symbol.declarations, d => { var declarationSpaces = getDeclarationSpaces(d); if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { @@ -7807,7 +7807,7 @@ module ts { case SyntaxKind.EnumDeclaration: return SymbolFlags.ExportType | SymbolFlags.ExportValue; case SyntaxKind.ImportDeclaration: - var result: SymbolFlags = 0; + var result = SymbolFlags.None; var target = resolveImport(getSymbolOfNode(d)); forEach(target.declarations, d => { result |= getDeclarationSpaces(d); }); return result; @@ -9108,9 +9108,9 @@ module ts { } if (target !== unknownSymbol) { var excludedMeanings = - (symbol.flags & SymbolFlags.Value ? SymbolFlags.Value : 0) | - (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | - (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); + (symbol.flags & SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.None) | + (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : SymbolFlags.None) | + (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : SymbolFlags.None); if (target.flags & excludedMeanings) { error(node, Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0, symbolToString(symbol)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9ebab8dc2207c..a9ee10a9090f1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1129,6 +1129,7 @@ module ts { } export const enum SymbolFlags { + None = 0x00000000, // None FunctionScopedVariable = 0x00000001, // Variable (var) or parameter BlockScopedVariable = 0x00000002, // A block-scoped variable (let or const) Property = 0x00000004, // Property or enum member From 7d331431956ea070b25d5d5f0fa5e3db68ae493b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 17:36:53 -0800 Subject: [PATCH 5/8] Added binding support for destructured parameter properties. --- src/compiler/binder.ts | 19 +- ...estructuringPropertyParameters1.errors.txt | 50 ++--- ...estructuringPropertyParameters2.errors.txt | 20 +- ...estructuringPropertyParameters3.errors.txt | 53 ------ .../destructuringPropertyParameters3.types | 180 ++++++++++++++++++ ...estructuringPropertyParameters4.errors.txt | 20 +- ...estructuringPropertyParameters5.errors.txt | 17 +- 7 files changed, 213 insertions(+), 146 deletions(-) delete mode 100644 tests/baselines/reference/destructuringPropertyParameters3.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters3.types diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4a9a72609bdca..0e6954ad07b8e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -493,7 +493,9 @@ module ts { } function bindParameter(node: ParameterDeclaration) { - if (isBindingPattern(node.name)) { + var isBinding = isBindingPattern(node.name); + + if (isBinding) { bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node), /*isBlockScopeContainer*/ false); } else { @@ -507,7 +509,20 @@ module ts { node.parent.parent.kind === SyntaxKind.ClassDeclaration) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + + if (isBinding) { + forEach((node.name).elements, function declareBindingParameterProperties(curr: BindingElement) { + if (isBindingPattern(curr.name)) { + forEach((curr.name).elements, declareBindingParameterProperties) + } + else if (curr.name.kind === SyntaxKind.Identifier) { + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, curr, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + } + }); + } + else { + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + } } } } diff --git a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt index d4ed1e27cc00b..a542442ea4088 100644 --- a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt @@ -1,19 +1,11 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,26): error TS2339: Property 'x' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,35): error TS2339: Property 'y' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,43): error TS2339: Property 'y' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,52): error TS2339: Property 'z' does not exist on type 'C2'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,23): error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,40): error TS2365: Operator '===' cannot be applied to types 'number' and 'boolean'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,23): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,26): error TS2339: Property 'x' does not exist on type 'C3'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,35): error TS2339: Property 'y' does not exist on type 'C3'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,43): error TS2339: Property 'y' does not exist on type 'C3'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,52): error TS2339: Property 'z' does not exist on type 'C3'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,23): error TS2365: Operator '===' cannot be applied to types 'number' and 'string'. +tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,40): error TS2365: Operator '===' cannot be applied to types 'string' and 'boolean'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (13 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (5 errors) ==== class C1 { constructor(public [x, y, z]: string[]) { } @@ -36,36 +28,20 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29 var c1 = new C1([]); c1 = new C1(["larry", "{curly}", "moe"]); var useC1Properties = c1.x === c1.y && c1.y === c1.z; - ~ -!!! error TS2339: Property 'x' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'z' does not exist on type 'C1'. var c2 = new C2(["10", 10, !!10]); var useC2Properties = c2.x === c2.y && c2.y === c2.z; - ~ -!!! error TS2339: Property 'x' does not exist on type 'C2'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C2'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C2'. - ~ -!!! error TS2339: Property 'z' does not exist on type 'C2'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'number' and 'boolean'. var c3 = new C3({x: 0, y: "", z: false}); c3 = new C3({x: 0, "y", z: true}); ~ !!! error TS1005: ':' expected. var useC3Properties = c3.x === c3.y && c3.y === c3.z; - ~ -!!! error TS2339: Property 'x' does not exist on type 'C3'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C3'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C3'. - ~ -!!! error TS2339: Property 'z' does not exist on type 'C3'. \ No newline at end of file + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'number' and 'string'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'string' and 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters2.errors.txt b/tests/baselines/reference/destructuringPropertyParameters2.errors.txt index 75d873cf3d653..ce3f8cb684737 100644 --- a/tests/baselines/reference/destructuringPropertyParameters2.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters2.errors.txt @@ -1,42 +1,24 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts (7 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts (1 errors) ==== class C1 { constructor(private k: number, private [a, b, c]: [number, string, boolean]) { if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. this.a = a || k; - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. } } public getA() { return this.a - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. } public getB() { return this.b - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. } public getC() { return this.c; - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. } } diff --git a/tests/baselines/reference/destructuringPropertyParameters3.errors.txt b/tests/baselines/reference/destructuringPropertyParameters3.errors.txt deleted file mode 100644 index 15cd0dbdebfb8..0000000000000 --- a/tests/baselines/reference/destructuringPropertyParameters3.errors.txt +++ /dev/null @@ -1,53 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. - - -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts (6 errors) ==== - class C1 { - constructor(private k: T, private [a, b, c]: [T,U,V]) { - if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. - this.a = a || k; - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. - } - } - - public getA() { - return this.a - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. - } - - public getB() { - return this.b - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. - } - - public getC() { - return this.c; - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. - } - } - - var x = new C1(undefined, [0, true, ""]); - var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; - - var y = new C1(10, [0, true, true]); - var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; - - var z = new C1(10, [undefined, "", ""]); - var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; - - var w = new C1(10, [undefined, undefined, undefined]); - var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters3.types b/tests/baselines/reference/destructuringPropertyParameters3.types new file mode 100644 index 0000000000000..bc4eb59fcfe13 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters3.types @@ -0,0 +1,180 @@ +=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts === +class C1 { +>C1 : C1 +>T : T +>U : U +>V : V + + constructor(private k: T, private [a, b, c]: [T,U,V]) { +>k : T +>T : T +>a : T +>b : U +>c : V +>T : T +>U : U +>V : V + + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { +>(b === undefined && c === undefined) || (this.b === undefined && this.c === undefined) : boolean +>(b === undefined && c === undefined) : boolean +>b === undefined && c === undefined : boolean +>b === undefined : boolean +>b : U +>undefined : undefined +>c === undefined : boolean +>c : V +>undefined : undefined +>(this.b === undefined && this.c === undefined) : boolean +>this.b === undefined && this.c === undefined : boolean +>this.b === undefined : boolean +>this.b : U +>this : C1 +>b : U +>undefined : undefined +>this.c === undefined : boolean +>this.c : V +>this : C1 +>c : V +>undefined : undefined + + this.a = a || k; +>this.a = a || k : T +>this.a : T +>this : C1 +>a : T +>a || k : T +>a : T +>k : T + } + } + + public getA() { +>getA : () => T + + return this.a +>this.a : T +>this : C1 +>a : T + } + + public getB() { +>getB : () => U + + return this.b +>this.b : U +>this : C1 +>b : U + } + + public getC() { +>getC : () => V + + return this.c; +>this.c : V +>this : C1 +>c : V + } +} + +var x = new C1(undefined, [0, true, ""]); +>x : C1 +>new C1(undefined, [0, true, ""]) : C1 +>C1 : typeof C1 +>undefined : undefined +>[0, true, ""] : [number, boolean, string] + +var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; +>x_a : number +>x_b : boolean +>x_c : string +>[x.getA(), x.getB(), x.getC()] : [number, boolean, string] +>x.getA() : number +>x.getA : () => number +>x : C1 +>getA : () => number +>x.getB() : boolean +>x.getB : () => boolean +>x : C1 +>getB : () => boolean +>x.getC() : string +>x.getC : () => string +>x : C1 +>getC : () => string + +var y = new C1(10, [0, true, true]); +>y : C1 +>new C1(10, [0, true, true]) : C1 +>C1 : typeof C1 +>[0, true, true] : [number, boolean, boolean] + +var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()]; +>y_a : number +>y_b : boolean +>y_c : boolean +>[y.getA(), y.getB(), y.getC()] : [number, boolean, boolean] +>y.getA() : number +>y.getA : () => number +>y : C1 +>getA : () => number +>y.getB() : boolean +>y.getB : () => boolean +>y : C1 +>getB : () => boolean +>y.getC() : boolean +>y.getC : () => boolean +>y : C1 +>getC : () => boolean + +var z = new C1(10, [undefined, "", ""]); +>z : C1 +>new C1(10, [undefined, "", ""]) : C1 +>C1 : typeof C1 +>[undefined, "", ""] : [undefined, string, string] +>undefined : undefined + +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; +>z_a : number +>z_b : string +>z_c : string +>[z.getA(), z.getB(), z.getC()] : [number, string, string] +>z.getA() : number +>z.getA : () => number +>z : C1 +>getA : () => number +>z.getB() : string +>z.getB : () => string +>z : C1 +>getB : () => string +>z.getC() : string +>z.getC : () => string +>z : C1 +>getC : () => string + +var w = new C1(10, [undefined, undefined, undefined]); +>w : C1 +>new C1(10, [undefined, undefined, undefined]) : C1 +>C1 : typeof C1 +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined +>undefined : undefined +>undefined : undefined + +var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; +>z_a : number +>z_b : string +>z_c : string +>[z.getA(), z.getB(), z.getC()] : [number, string, string] +>z.getA() : number +>z.getA : () => number +>z : C1 +>getA : () => number +>z.getB() : string +>z.getB : () => string +>z : C1 +>getB : () => string +>z.getC() : string +>z.getC : () => string +>z : C1 +>getC : () => string + diff --git a/tests/baselines/reference/destructuringPropertyParameters4.errors.txt b/tests/baselines/reference/destructuringPropertyParameters4.errors.txt index f8c9e899ebb51..253a6a6ef9de9 100644 --- a/tests/baselines/reference/destructuringPropertyParameters4.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters4.errors.txt @@ -1,45 +1,27 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(10,21): error TS2339: Property 'a' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(14,21): error TS2339: Property 'b' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(18,21): error TS2339: Property 'c' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,24): error TS2339: Property 'x' does not exist on type 'C2'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,34): error TS2339: Property 'y' does not exist on type 'C2'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,44): error TS2339: Property 'z' does not exist on type 'C2'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts (9 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts (3 errors) ==== class C1 { constructor(private k: T, protected [a, b, c]: [T,U,V]) { if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. this.a = a || k; - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. } } public getA() { return this.a - ~ -!!! error TS2339: Property 'a' does not exist on type 'C1'. } public getB() { return this.b - ~ -!!! error TS2339: Property 'b' does not exist on type 'C1'. } public getC() { return this.c; - ~ -!!! error TS2339: Property 'c' does not exist on type 'C1'. } } diff --git a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt index 4531b82d647f5..3a745fb56b350 100644 --- a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt @@ -1,11 +1,6 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,29): error TS2339: Property 'x1' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,40): error TS2339: Property 'x2' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,51): error TS2339: Property 'x3' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,62): error TS2339: Property 'y' does not exist on type 'C1'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,72): error TS2339: Property 'z' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. Types of property '0' are incompatible. Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. @@ -13,7 +8,7 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11 tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,56): error TS1005: ',' expected. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (10 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (5 errors) ==== type ObjType1 = { x: number; y: string; z: boolean } type TupleType1 = [ObjType1, number, string] @@ -27,16 +22,6 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11 !!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. var foo: any = x1 || x2 || x3 || y || z; var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; - ~~ -!!! error TS2339: Property 'x1' does not exist on type 'C1'. - ~~ -!!! error TS2339: Property 'x2' does not exist on type 'C1'. - ~~ -!!! error TS2339: Property 'x3' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C1'. - ~ -!!! error TS2339: Property 'z' does not exist on type 'C1'. } } From c172707a952c6f89735c33bd77ec4a52420308af Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Jan 2015 17:45:02 -0800 Subject: [PATCH 6/8] Fixed incorrect tests. --- ...estructuringPropertyParameters1.errors.txt | 47 ------- .../destructuringPropertyParameters1.js | 61 +++++++++ .../destructuringPropertyParameters1.types | 129 ++++++++++++++++++ ...estructuringPropertyParameters4.errors.txt | 39 ------ .../destructuringPropertyParameters4.js | 4 +- .../destructuringPropertyParameters4.types | 100 ++++++++++++++ ...estructuringPropertyParameters5.errors.txt | 9 +- .../destructuringPropertyParameters5.js | 26 ++++ .../destructuringPropertyParameters1.ts | 6 +- .../destructuringPropertyParameters4.ts | 2 +- .../destructuringPropertyParameters5.ts | 2 +- 11 files changed, 326 insertions(+), 99 deletions(-) delete mode 100644 tests/baselines/reference/destructuringPropertyParameters1.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters1.js create mode 100644 tests/baselines/reference/destructuringPropertyParameters1.types delete mode 100644 tests/baselines/reference/destructuringPropertyParameters4.errors.txt create mode 100644 tests/baselines/reference/destructuringPropertyParameters4.types create mode 100644 tests/baselines/reference/destructuringPropertyParameters5.js diff --git a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt b/tests/baselines/reference/destructuringPropertyParameters1.errors.txt deleted file mode 100644 index a542442ea4088..0000000000000 --- a/tests/baselines/reference/destructuringPropertyParameters1.errors.txt +++ /dev/null @@ -1,47 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,23): error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,40): error TS2365: Operator '===' cannot be applied to types 'number' and 'boolean'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,23): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,23): error TS2365: Operator '===' cannot be applied to types 'number' and 'string'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(29,40): error TS2365: Operator '===' cannot be applied to types 'string' and 'boolean'. - - -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (5 errors) ==== - class C1 { - constructor(public [x, y, z]: string[]) { - } - } - - type TupleType1 = [string, number, boolean]; - - class C2 { - constructor(public [x, y, z]: TupleType1) { - } - } - - type ObjType1 = { x: number; y: string; z: boolean } - - class C3 { - constructor(public { x, y, z }: ObjType1) { - } - } - - var c1 = new C1([]); - c1 = new C1(["larry", "{curly}", "moe"]); - var useC1Properties = c1.x === c1.y && c1.y === c1.z; - - var c2 = new C2(["10", 10, !!10]); - var useC2Properties = c2.x === c2.y && c2.y === c2.z; - ~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. - ~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'number' and 'boolean'. - - var c3 = new C3({x: 0, y: "", z: false}); - c3 = new C3({x: 0, "y", z: true}); - ~ -!!! error TS1005: ':' expected. - var useC3Properties = c3.x === c3.y && c3.y === c3.z; - ~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'number' and 'string'. - ~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'string' and 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters1.js b/tests/baselines/reference/destructuringPropertyParameters1.js new file mode 100644 index 0000000000000..95f3bc9736fd2 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters1.js @@ -0,0 +1,61 @@ +//// [destructuringPropertyParameters1.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 = [string, number, boolean]; + +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } + +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; + +var c2 = new C2(["10", 10, !!10]); +var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; + +var c3 = new C3({x: 0, y: "", z: false}); +c3 = new C3({x: 0, "y": "y", z: true}); +var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; + +//// [destructuringPropertyParameters1.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); +var c1 = new C1([]); +c1 = new C1(["larry", "{curly}", "moe"]); +var useC1Properties = c1.x === c1.y && c1.y === c1.z; +var c2 = new C2(["10", 10, !!10]); +var _a = [c2.x, c2.y, c2.z], c2_x = _a[0], c2_y = _a[1], c2_z = _a[2]; +var c3 = new C3({ x: 0, y: "", z: false }); +c3 = new C3({ x: 0, "y": "y", z: true }); +var _b = [c3.x, c3.y, c3.z], c3_x = _b[0], c3_y = _b[1], c3_z = _b[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters1.types b/tests/baselines/reference/destructuringPropertyParameters1.types new file mode 100644 index 0000000000000..1155edb0b0202 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters1.types @@ -0,0 +1,129 @@ +=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts === +class C1 { +>C1 : C1 + + constructor(public [x, y, z]: string[]) { +>x : string +>y : string +>z : string + } +} + +type TupleType1 = [string, number, boolean]; +>TupleType1 : [string, number, boolean] + +class C2 { +>C2 : C2 + + constructor(public [x, y, z]: TupleType1) { +>x : string +>y : number +>z : boolean +>TupleType1 : [string, number, boolean] + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +>ObjType1 : { x: number; y: string; z: boolean; } +>x : number +>y : string +>z : boolean + +class C3 { +>C3 : C3 + + constructor(public { x, y, z }: ObjType1) { +>x : number +>y : string +>z : boolean +>ObjType1 : { x: number; y: string; z: boolean; } + } +} + +var c1 = new C1([]); +>c1 : C1 +>new C1([]) : C1 +>C1 : typeof C1 +>[] : undefined[] + +c1 = new C1(["larry", "{curly}", "moe"]); +>c1 = new C1(["larry", "{curly}", "moe"]) : C1 +>c1 : C1 +>new C1(["larry", "{curly}", "moe"]) : C1 +>C1 : typeof C1 +>["larry", "{curly}", "moe"] : string[] + +var useC1Properties = c1.x === c1.y && c1.y === c1.z; +>useC1Properties : boolean +>c1.x === c1.y && c1.y === c1.z : boolean +>c1.x === c1.y : boolean +>c1.x : string +>c1 : C1 +>x : string +>c1.y : string +>c1 : C1 +>y : string +>c1.y === c1.z : boolean +>c1.y : string +>c1 : C1 +>y : string +>c1.z : string +>c1 : C1 +>z : string + +var c2 = new C2(["10", 10, !!10]); +>c2 : C2 +>new C2(["10", 10, !!10]) : C2 +>C2 : typeof C2 +>["10", 10, !!10] : [string, number, boolean] +>!!10 : boolean +>!10 : boolean + +var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; +>c2_x : string +>c2_y : number +>c2_z : boolean +>[c2.x, c2.y, c2.z] : [string, number, boolean] +>c2.x : string +>c2 : C2 +>x : string +>c2.y : number +>c2 : C2 +>y : number +>c2.z : boolean +>c2 : C2 +>z : boolean + +var c3 = new C3({x: 0, y: "", z: false}); +>c3 : C3 +>new C3({x: 0, y: "", z: false}) : C3 +>C3 : typeof C3 +>{x: 0, y: "", z: false} : { x: number; y: string; z: boolean; } +>x : number +>y : string +>z : boolean + +c3 = new C3({x: 0, "y": "y", z: true}); +>c3 = new C3({x: 0, "y": "y", z: true}) : C3 +>c3 : C3 +>new C3({x: 0, "y": "y", z: true}) : C3 +>C3 : typeof C3 +>{x: 0, "y": "y", z: true} : { x: number; "y": string; z: boolean; } +>x : number +>z : boolean + +var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; +>c3_x : number +>c3_y : string +>c3_z : boolean +>[c3.x, c3.y, c3.z] : [number, string, boolean] +>c3.x : number +>c3 : C3 +>x : number +>c3.y : string +>c3 : C3 +>y : string +>c3.z : boolean +>c3 : C3 +>z : boolean + diff --git a/tests/baselines/reference/destructuringPropertyParameters4.errors.txt b/tests/baselines/reference/destructuringPropertyParameters4.errors.txt deleted file mode 100644 index 253a6a6ef9de9..0000000000000 --- a/tests/baselines/reference/destructuringPropertyParameters4.errors.txt +++ /dev/null @@ -1,39 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,24): error TS2339: Property 'x' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,34): error TS2339: Property 'y' does not exist on type 'C2'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,44): error TS2339: Property 'z' does not exist on type 'C2'. - - -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts (3 errors) ==== - - class C1 { - constructor(private k: T, protected [a, b, c]: [T,U,V]) { - if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { - this.a = a || k; - } - } - - public getA() { - return this.a - } - - public getB() { - return this.b - } - - public getC() { - return this.c; - } - } - - class C2 extends C1 { - public doSomethingWithSuperProperties() { - return `${this.x} ${this.y} ${this.z}`; - ~ -!!! error TS2339: Property 'x' does not exist on type 'C2'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'C2'. - ~ -!!! error TS2339: Property 'z' does not exist on type 'C2'. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters4.js b/tests/baselines/reference/destructuringPropertyParameters4.js index 02784ad5f8263..4aa796a4f3771 100644 --- a/tests/baselines/reference/destructuringPropertyParameters4.js +++ b/tests/baselines/reference/destructuringPropertyParameters4.js @@ -22,7 +22,7 @@ class C1 { class C2 extends C1 { public doSomethingWithSuperProperties() { - return `${this.x} ${this.y} ${this.z}`; + return `${this.a} ${this.b} ${this.c}`; } } @@ -59,7 +59,7 @@ var C2 = (function (_super) { _super.apply(this, arguments); } C2.prototype.doSomethingWithSuperProperties = function () { - return `${this.x} ${this.y} ${this.z}`; + return `${this.a} ${this.b} ${this.c}`; }; return C2; })(C1); diff --git a/tests/baselines/reference/destructuringPropertyParameters4.types b/tests/baselines/reference/destructuringPropertyParameters4.types new file mode 100644 index 0000000000000..61b5c485a6b2b --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters4.types @@ -0,0 +1,100 @@ +=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts === + +class C1 { +>C1 : C1 +>T : T +>U : U +>V : V + + constructor(private k: T, protected [a, b, c]: [T,U,V]) { +>k : T +>T : T +>a : T +>b : U +>c : V +>T : T +>U : U +>V : V + + if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { +>(b === undefined && c === undefined) || (this.b === undefined && this.c === undefined) : boolean +>(b === undefined && c === undefined) : boolean +>b === undefined && c === undefined : boolean +>b === undefined : boolean +>b : U +>undefined : undefined +>c === undefined : boolean +>c : V +>undefined : undefined +>(this.b === undefined && this.c === undefined) : boolean +>this.b === undefined && this.c === undefined : boolean +>this.b === undefined : boolean +>this.b : U +>this : C1 +>b : U +>undefined : undefined +>this.c === undefined : boolean +>this.c : V +>this : C1 +>c : V +>undefined : undefined + + this.a = a || k; +>this.a = a || k : T +>this.a : T +>this : C1 +>a : T +>a || k : T +>a : T +>k : T + } + } + + public getA() { +>getA : () => T + + return this.a +>this.a : T +>this : C1 +>a : T + } + + public getB() { +>getB : () => U + + return this.b +>this.b : U +>this : C1 +>b : U + } + + public getC() { +>getC : () => V + + return this.c; +>this.c : V +>this : C1 +>c : V + } +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + public doSomethingWithSuperProperties() { +>doSomethingWithSuperProperties : () => string + + return `${this.a} ${this.b} ${this.c}`; +>this.a : number +>this : C2 +>a : number +>this.b : string +>this : C2 +>b : string +>this.c : boolean +>this : C2 +>c : boolean + } +} + diff --git a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt index 3a745fb56b350..c1b0757fa695b 100644 --- a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt +++ b/tests/baselines/reference/destructuringPropertyParameters5.errors.txt @@ -5,10 +5,9 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11 Types of property '0' are incompatible. Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,56): error TS1005: ',' expected. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (5 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (4 errors) ==== type ObjType1 = { x: number; y: string; z: boolean } type TupleType1 = [ObjType1, number, string] @@ -25,12 +24,10 @@ tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11 } } - var a = new C1([{ x1: 10, x2: "", x3: true }, "", false); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. !!! error TS2345: Types of property '0' are incompatible. !!! error TS2345: Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. !!! error TS2345: Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. - ~ -!!! error TS1005: ',' expected. var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringPropertyParameters5.js b/tests/baselines/reference/destructuringPropertyParameters5.js new file mode 100644 index 0000000000000..16f551a24b7b8 --- /dev/null +++ b/tests/baselines/reference/destructuringPropertyParameters5.js @@ -0,0 +1,26 @@ +//// [destructuringPropertyParameters5.ts] +type ObjType1 = { x: number; y: string; z: boolean } +type TupleType1 = [ObjType1, number, string] + +class C1 { + constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + var foo: any = x1 || x2 || x3 || y || z; + var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z; + } +} + +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); +var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; + +//// [destructuringPropertyParameters5.js] +var C1 = (function () { + function C1(_a) { + var _b = _a[0], x1 = _b.x1, x2 = _b.x2, x3 = _b.x3, y = _a[1], z = _a[2]; + this.[{ x1, x2, x3 }, y, z] = [{ x1, x2, x3 }, y, z]; + var foo = x1 || x2 || x3 || y || z; + var bar = this.x1 || this.x2 || this.x3 || this.y || this.z; + } + return C1; +})(); +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); +var _a = [a.x1, a.x2, a.x3, a.y, a.z], a_x1 = _a[0], a_x2 = _a[1], a_x3 = _a[2], a_y = _a[3], a_z = _a[4]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts index 8571db338e88b..ba73adc9fde21 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts @@ -22,8 +22,8 @@ c1 = new C1(["larry", "{curly}", "moe"]); var useC1Properties = c1.x === c1.y && c1.y === c1.z; var c2 = new C2(["10", 10, !!10]); -var useC2Properties = c2.x === c2.y && c2.y === c2.z; +var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; var c3 = new C3({x: 0, y: "", z: false}); -c3 = new C3({x: 0, "y", z: true}); -var useC3Properties = c3.x === c3.y && c3.y === c3.z; \ No newline at end of file +c3 = new C3({x: 0, "y": "y", z: true}); +var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts index e8a494b227481..7a83e5f4d4b99 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts @@ -22,6 +22,6 @@ class C1 { class C2 extends C1 { public doSomethingWithSuperProperties() { - return `${this.x} ${this.y} ${this.z}`; + return `${this.a} ${this.b} ${this.c}`; } } diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts index 94ec1fe27b56e..02f9b780ad99d 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts @@ -8,5 +8,5 @@ class C1 { } } -var a = new C1([{ x1: 10, x2: "", x3: true }, "", false); +var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file From 865f99911f2dd657ba7089b1b84a798f06efe597 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Jan 2015 14:14:05 -0800 Subject: [PATCH 7/8] Properly propagate flags to all bindings; properly emit parameter properties. --- src/compiler/emitter.ts | 34 ++++++++++++------- src/compiler/parser.ts | 19 ++++++++++- .../destructuringPropertyParameters1.js | 12 +++++-- .../destructuringPropertyParameters2.js | 4 ++- .../destructuringPropertyParameters3.js | 4 ++- .../destructuringPropertyParameters4.js | 4 ++- .../destructuringPropertyParameters5.js | 6 +++- 7 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d82e577971d5e..01419f71e3705 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3053,7 +3053,7 @@ module ts { } } - function emitBindingElement(target: BindingElement, value: Expression) { + function emitBindingElement(target: BindingElement, value?: Expression) { if (target.initializer) { // Combine value and initializer value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; @@ -3369,18 +3369,26 @@ module ts { } function emitParameterPropertyAssignments(node: ConstructorDeclaration) { - forEach(node.parameters, param => { - if (param.flags & NodeFlags.AccessibilityModifier) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNode(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); + forEach(node.parameters, function emitBoundProperty(binding: ParameterDeclaration | BindingElement) { + if (binding.flags & NodeFlags.AccessibilityModifier) { + if (isBindingPattern(binding.name)) { + emitStart(binding); + forEach((binding.name).elements, emitBoundProperty); + emitEnd(binding.name); + } + else { + writeLine(); + emitStart(binding); + emitStart(binding.name); + write("this."); + emitNode(binding.name); + emitEnd(binding.name); + write(" = "); + emit(binding.name); + write(";"); + emitEnd(binding); + } + } }); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5ae44e5ff398a..fbc73de19fd24 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2155,7 +2155,8 @@ module ts { function parseParameter(): ParameterDeclaration { var node = createNode(SyntaxKind.Parameter); - setModifiers(node, parseModifiers()); + var modifiers = parseModifiers(); + setModifiers(node, modifiers); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); // SingleNameBinding[Yield,GeneratorParameter] : See 13.2.3 @@ -2164,6 +2165,10 @@ module ts { node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifierOrPattern) : parseIdentifierOrPattern(); + if (isBindingPattern(node.name)) { + propagateModifiersToBindingElements(node.name, modifiers); + } + if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) { // in cases like // 'use strict' @@ -2191,6 +2196,18 @@ module ts { return finishNode(node); } + function propagateModifiersToBindingElements(bindingPattern: BindingPattern, modifiers: ModifiersArray): void { + forEach(bindingPattern.elements, propagate); + + function propagate(node: BindingElement): void { + setModifiers(node, modifiers); + + if (isBindingPattern(node.name)) { + forEach((node.name).elements, propagate); + } + } + } + function parseParameterInitializer() { return parseInitializer(/*inParameter*/ true); } diff --git a/tests/baselines/reference/destructuringPropertyParameters1.js b/tests/baselines/reference/destructuringPropertyParameters1.js index 95f3bc9736fd2..a7fa6b3808664 100644 --- a/tests/baselines/reference/destructuringPropertyParameters1.js +++ b/tests/baselines/reference/destructuringPropertyParameters1.js @@ -33,21 +33,27 @@ var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; var C1 = (function () { function C1(_a) { var x = _a[0], y = _a[1], z = _a[2]; - this.[x, y, z] = [x, y, z]; + this.x = x; + this.y = y; + this.z = z; } return C1; })(); var C2 = (function () { function C2(_a) { var x = _a[0], y = _a[1], z = _a[2]; - this.[x, y, z] = [x, y, z]; + this.x = x; + this.y = y; + this.z = z; } return C2; })(); var C3 = (function () { function C3(_a) { var x = _a.x, y = _a.y, z = _a.z; - this.{ x, y, z } = { x, y, z }; + this.x = x; + this.y = y; + this.z = z; } return C3; })(); diff --git a/tests/baselines/reference/destructuringPropertyParameters2.js b/tests/baselines/reference/destructuringPropertyParameters2.js index 026fe4896f850..7ef739549bbc5 100644 --- a/tests/baselines/reference/destructuringPropertyParameters2.js +++ b/tests/baselines/reference/destructuringPropertyParameters2.js @@ -34,7 +34,9 @@ var C1 = (function () { function C1(k, _a) { var a = _a[0], b = _a[1], c = _a[2]; this.k = k; - this.[a, b, c] = [a, b, c]; + this.a = a; + this.b = b; + this.c = c; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } diff --git a/tests/baselines/reference/destructuringPropertyParameters3.js b/tests/baselines/reference/destructuringPropertyParameters3.js index 538f58d53f75f..5047da1b95c6d 100644 --- a/tests/baselines/reference/destructuringPropertyParameters3.js +++ b/tests/baselines/reference/destructuringPropertyParameters3.js @@ -37,7 +37,9 @@ var C1 = (function () { function C1(k, _a) { var a = _a[0], b = _a[1], c = _a[2]; this.k = k; - this.[a, b, c] = [a, b, c]; + this.a = a; + this.b = b; + this.c = c; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } diff --git a/tests/baselines/reference/destructuringPropertyParameters4.js b/tests/baselines/reference/destructuringPropertyParameters4.js index 4aa796a4f3771..9f011e922db96 100644 --- a/tests/baselines/reference/destructuringPropertyParameters4.js +++ b/tests/baselines/reference/destructuringPropertyParameters4.js @@ -37,7 +37,9 @@ var __extends = this.__extends || function (d, b) { var C1 = (function () { function C1(k, [a, b, c]) { this.k = k; - this.[a, b, c] = [a, b, c]; + this.a = a; + this.b = b; + this.c = c; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } diff --git a/tests/baselines/reference/destructuringPropertyParameters5.js b/tests/baselines/reference/destructuringPropertyParameters5.js index 16f551a24b7b8..00ec011d722c8 100644 --- a/tests/baselines/reference/destructuringPropertyParameters5.js +++ b/tests/baselines/reference/destructuringPropertyParameters5.js @@ -16,7 +16,11 @@ var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; var C1 = (function () { function C1(_a) { var _b = _a[0], x1 = _b.x1, x2 = _b.x2, x3 = _b.x3, y = _a[1], z = _a[2]; - this.[{ x1, x2, x3 }, y, z] = [{ x1, x2, x3 }, y, z]; + this.x1 = x1; + this.x2 = x2; + this.x3 = x3; + this.y = y; + this.z = z; var foo = x1 || x2 || x3 || y || z; var bar = this.x1 || this.x2 || this.x3 || this.y || this.z; } From 59267905897761c65565162ccab8a1be435c6719 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 14 Jan 2015 14:20:32 -0800 Subject: [PATCH 8/8] Renamed tests. --- ...meters1.js => destructuringParameterProperties1.js} | 4 ++-- ...1.types => destructuringParameterProperties1.types} | 2 +- ...xt => destructuringParameterProperties2.errors.txt} | 4 ++-- ...meters2.js => destructuringParameterProperties2.js} | 4 ++-- ...meters3.js => destructuringParameterProperties3.js} | 4 ++-- ...3.types => destructuringParameterProperties3.types} | 2 +- ...meters4.js => destructuringParameterProperties4.js} | 4 ++-- ...4.types => destructuringParameterProperties4.types} | 2 +- ...xt => destructuringParameterProperties5.errors.txt} | 10 +++++----- ...meters5.js => destructuringParameterProperties5.js} | 4 ++-- ...meters1.ts => destructuringParameterProperties1.ts} | 0 ...meters2.ts => destructuringParameterProperties2.ts} | 0 ...meters3.ts => destructuringParameterProperties3.ts} | 0 ...meters4.ts => destructuringParameterProperties4.ts} | 0 ...meters5.ts => destructuringParameterProperties5.ts} | 0 15 files changed, 20 insertions(+), 20 deletions(-) rename tests/baselines/reference/{destructuringPropertyParameters1.js => destructuringParameterProperties1.js} (92%) rename tests/baselines/reference/{destructuringPropertyParameters1.types => destructuringParameterProperties1.types} (91%) rename tests/baselines/reference/{destructuringPropertyParameters2.errors.txt => destructuringParameterProperties2.errors.txt} (73%) rename tests/baselines/reference/{destructuringPropertyParameters2.js => destructuringParameterProperties2.js} (92%) rename tests/baselines/reference/{destructuringPropertyParameters3.js => destructuringParameterProperties3.js} (93%) rename tests/baselines/reference/{destructuringPropertyParameters3.types => destructuringParameterProperties3.types} (93%) rename tests/baselines/reference/{destructuringPropertyParameters4.js => destructuringParameterProperties4.js} (92%) rename tests/baselines/reference/{destructuringPropertyParameters4.types => destructuringParameterProperties4.types} (90%) rename tests/baselines/reference/{destructuringPropertyParameters5.errors.txt => destructuringParameterProperties5.errors.txt} (63%) rename tests/baselines/reference/{destructuringPropertyParameters5.js => destructuringParameterProperties5.js} (90%) rename tests/cases/conformance/es6/destructuring/{destructuringPropertyParameters1.ts => destructuringParameterProperties1.ts} (100%) rename tests/cases/conformance/es6/destructuring/{destructuringPropertyParameters2.ts => destructuringParameterProperties2.ts} (100%) rename tests/cases/conformance/es6/destructuring/{destructuringPropertyParameters3.ts => destructuringParameterProperties3.ts} (100%) rename tests/cases/conformance/es6/destructuring/{destructuringPropertyParameters4.ts => destructuringParameterProperties4.ts} (100%) rename tests/cases/conformance/es6/destructuring/{destructuringPropertyParameters5.ts => destructuringParameterProperties5.ts} (100%) diff --git a/tests/baselines/reference/destructuringPropertyParameters1.js b/tests/baselines/reference/destructuringParameterProperties1.js similarity index 92% rename from tests/baselines/reference/destructuringPropertyParameters1.js rename to tests/baselines/reference/destructuringParameterProperties1.js index a7fa6b3808664..cdcac8f77c4c9 100644 --- a/tests/baselines/reference/destructuringPropertyParameters1.js +++ b/tests/baselines/reference/destructuringParameterProperties1.js @@ -1,4 +1,4 @@ -//// [destructuringPropertyParameters1.ts] +//// [destructuringParameterProperties1.ts] class C1 { constructor(public [x, y, z]: string[]) { } @@ -29,7 +29,7 @@ var c3 = new C3({x: 0, y: "", z: false}); c3 = new C3({x: 0, "y": "y", z: true}); var [c3_x, c3_y, c3_z] = [c3.x, c3.y, c3.z]; -//// [destructuringPropertyParameters1.js] +//// [destructuringParameterProperties1.js] var C1 = (function () { function C1(_a) { var x = _a[0], y = _a[1], z = _a[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters1.types b/tests/baselines/reference/destructuringParameterProperties1.types similarity index 91% rename from tests/baselines/reference/destructuringPropertyParameters1.types rename to tests/baselines/reference/destructuringParameterProperties1.types index 1155edb0b0202..81c325aed9274 100644 --- a/tests/baselines/reference/destructuringPropertyParameters1.types +++ b/tests/baselines/reference/destructuringParameterProperties1.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts === +=== tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts === class C1 { >C1 : C1 diff --git a/tests/baselines/reference/destructuringPropertyParameters2.errors.txt b/tests/baselines/reference/destructuringParameterProperties2.errors.txt similarity index 73% rename from tests/baselines/reference/destructuringPropertyParameters2.errors.txt rename to tests/baselines/reference/destructuringParameterProperties2.errors.txt index ce3f8cb684737..c963b6d1acc86 100644 --- a/tests/baselines/reference/destructuringPropertyParameters2.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties2.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts (1 errors) ==== class C1 { constructor(private k: number, private [a, b, c]: [number, string, boolean]) { if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { diff --git a/tests/baselines/reference/destructuringPropertyParameters2.js b/tests/baselines/reference/destructuringParameterProperties2.js similarity index 92% rename from tests/baselines/reference/destructuringPropertyParameters2.js rename to tests/baselines/reference/destructuringParameterProperties2.js index 7ef739549bbc5..8b88fa39fcb4a 100644 --- a/tests/baselines/reference/destructuringPropertyParameters2.js +++ b/tests/baselines/reference/destructuringParameterProperties2.js @@ -1,4 +1,4 @@ -//// [destructuringPropertyParameters2.ts] +//// [destructuringParameterProperties2.ts] class C1 { constructor(private k: number, private [a, b, c]: [number, string, boolean]) { if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { @@ -29,7 +29,7 @@ var z = new C1(10, [undefined, "", null]); var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; -//// [destructuringPropertyParameters2.js] +//// [destructuringParameterProperties2.js] var C1 = (function () { function C1(k, _a) { var a = _a[0], b = _a[1], c = _a[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters3.js b/tests/baselines/reference/destructuringParameterProperties3.js similarity index 93% rename from tests/baselines/reference/destructuringPropertyParameters3.js rename to tests/baselines/reference/destructuringParameterProperties3.js index 5047da1b95c6d..7a54b09f0b655 100644 --- a/tests/baselines/reference/destructuringPropertyParameters3.js +++ b/tests/baselines/reference/destructuringParameterProperties3.js @@ -1,4 +1,4 @@ -//// [destructuringPropertyParameters3.ts] +//// [destructuringParameterProperties3.ts] class C1 { constructor(private k: T, private [a, b, c]: [T,U,V]) { if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { @@ -32,7 +32,7 @@ var w = new C1(10, [undefined, undefined, undefined]); var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()]; -//// [destructuringPropertyParameters3.js] +//// [destructuringParameterProperties3.js] var C1 = (function () { function C1(k, _a) { var a = _a[0], b = _a[1], c = _a[2]; diff --git a/tests/baselines/reference/destructuringPropertyParameters3.types b/tests/baselines/reference/destructuringParameterProperties3.types similarity index 93% rename from tests/baselines/reference/destructuringPropertyParameters3.types rename to tests/baselines/reference/destructuringParameterProperties3.types index bc4eb59fcfe13..19b8b266ddc76 100644 --- a/tests/baselines/reference/destructuringPropertyParameters3.types +++ b/tests/baselines/reference/destructuringParameterProperties3.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts === +=== tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts === class C1 { >C1 : C1 >T : T diff --git a/tests/baselines/reference/destructuringPropertyParameters4.js b/tests/baselines/reference/destructuringParameterProperties4.js similarity index 92% rename from tests/baselines/reference/destructuringPropertyParameters4.js rename to tests/baselines/reference/destructuringParameterProperties4.js index 9f011e922db96..8dd7029aa2d06 100644 --- a/tests/baselines/reference/destructuringPropertyParameters4.js +++ b/tests/baselines/reference/destructuringParameterProperties4.js @@ -1,4 +1,4 @@ -//// [destructuringPropertyParameters4.ts] +//// [destructuringParameterProperties4.ts] class C1 { constructor(private k: T, protected [a, b, c]: [T,U,V]) { @@ -27,7 +27,7 @@ class C2 extends C1 { } -//// [destructuringPropertyParameters4.js] +//// [destructuringParameterProperties4.js] var __extends = this.__extends || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } diff --git a/tests/baselines/reference/destructuringPropertyParameters4.types b/tests/baselines/reference/destructuringParameterProperties4.types similarity index 90% rename from tests/baselines/reference/destructuringPropertyParameters4.types rename to tests/baselines/reference/destructuringParameterProperties4.types index 61b5c485a6b2b..86c5b52e20f42 100644 --- a/tests/baselines/reference/destructuringPropertyParameters4.types +++ b/tests/baselines/reference/destructuringParameterProperties4.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts === +=== tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts === class C1 { >C1 : C1 diff --git a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt b/tests/baselines/reference/destructuringParameterProperties5.errors.txt similarity index 63% rename from tests/baselines/reference/destructuringPropertyParameters5.errors.txt rename to tests/baselines/reference/destructuringParameterProperties5.errors.txt index c1b0757fa695b..30e03c12a43f8 100644 --- a/tests/baselines/reference/destructuringPropertyParameters5.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties5.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. Types of property '0' are incompatible. Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. -==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (4 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts (4 errors) ==== type ObjType1 = { x: number; y: string; z: boolean } type TupleType1 = [ObjType1, number, string] diff --git a/tests/baselines/reference/destructuringPropertyParameters5.js b/tests/baselines/reference/destructuringParameterProperties5.js similarity index 90% rename from tests/baselines/reference/destructuringPropertyParameters5.js rename to tests/baselines/reference/destructuringParameterProperties5.js index 00ec011d722c8..ed0e604a55b62 100644 --- a/tests/baselines/reference/destructuringPropertyParameters5.js +++ b/tests/baselines/reference/destructuringParameterProperties5.js @@ -1,4 +1,4 @@ -//// [destructuringPropertyParameters5.ts] +//// [destructuringParameterProperties5.ts] type ObjType1 = { x: number; y: string; z: boolean } type TupleType1 = [ObjType1, number, string] @@ -12,7 +12,7 @@ class C1 { var a = new C1([{ x1: 10, x2: "", x3: true }, "", false]); var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; -//// [destructuringPropertyParameters5.js] +//// [destructuringParameterProperties5.js] var C1 = (function () { function C1(_a) { var _b = _a[0], x1 = _b.x1, x2 = _b.x2, x3 = _b.x3, y = _a[1], z = _a[2]; diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts