diff --git a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt new file mode 100644 index 00000000000..643305a0167 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,18): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts (4 errors) ==== + enum Foo { a } + function a({x, a}: { x: number, a: number }) { } + function a1({z: {x, y: {j}}}) { } + function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + function a3({z} = {z:10}) { } + function a4({z=10}) { } + function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } + a2(); + a2({ z: { x: "hello" , y: { j: Foo.a } }}); + a3(); + a3({ z: Foo.a }); + a4({}); + a6({ b: 10 }); + a6({ b: true }); + + // error + a4(); + ~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + a3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + function a5([z], z: number) { } + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration.js b/tests/baselines/reference/destructuringParameterDeclaration.js new file mode 100644 index 00000000000..da979430ff3 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration.js @@ -0,0 +1,58 @@ +//// [destructuringParameterDeclaration.ts] +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } + + +//// [destructuringParameterDeclaration.js] +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function a(_a) { + var x = _a.x, a = _a.a; +} +function a1(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; +} +function a2(_a) { + var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; +} +function a3(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; +} +function a4(_a) { + var _b = _a.z, z = _b === void 0 ? 10 : _b; +} +function a6(_a) { + var b = (_a === void 0 ? { b: "hello" } : _a).b; +} +a2(); +a2({ z: { x: "hello", y: { j: Foo.a } } }); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); +// error +a4(); +a3({}); +function a5(_a, z) { + var z = _a[0]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt new file mode 100644 index 00000000000..2651be05038 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt @@ -0,0 +1,48 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(5,16): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(12,18): error TS1047: A rest parameter cannot be optional. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,17): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (6 errors) ==== + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a3(...x = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + function a4(...x: (number|string)[]) { } + function a5(...a) { } + function a6(...a: Array) { } + function a7(...a: arrayString) { } + function a8(...a: stringOrNumArray) { } + function a9(...a: someArray) { } + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a10(...b?) { } + ~ +!!! error TS1047: A rest parameter cannot be optional. + function a11(...b = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + + + a4(1, 2, "hello", true); + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + var array = [1, 2, 3]; + var array2 = [true, false, "hello"]; + a5([...array]); + a4(...array); + a4(...array2); + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1.js new file mode 100644 index 00000000000..37967ddb441 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1.js @@ -0,0 +1,86 @@ +//// [destructuringParameterDeclaration1.ts] +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); + +//// [destructuringParameterDeclaration1.js] +function a3() { + if (x === void 0) { x = [1, 2, 3]; } + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +function a4() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +function a5() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a6() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a7() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a8() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a9() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a10() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} +function a11() { + if (b === void 0) { b = [1, 2, 3]; } + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5(array); +a4.apply(void 0, array); +a4.apply(void 0, array2); diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt new file mode 100644 index 00000000000..786571c88a5 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt @@ -0,0 +1,48 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(5,16): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(12,18): error TS1047: A rest parameter cannot be optional. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(13,17): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (6 errors) ==== + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a3(...x = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + function a4(...x: (number|string)[]) { } + function a5(...a) { } + function a6(...a: Array) { } + function a7(...a: arrayString) { } + function a8(...a: stringOrNumArray) { } + function a9(...a: someArray) { } + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a10(...b?) { } + ~ +!!! error TS1047: A rest parameter cannot be optional. + function a11(...b = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + + + a4(1, 2, "hello", true); + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + var array = [1, 2, 3]; + var array2 = [true, false, "hello"]; + a5([...array]); + a4(...array); + a4(...array2); + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js new file mode 100644 index 00000000000..779f5495f56 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js @@ -0,0 +1,39 @@ +//// [destructuringParameterDeclaration1ES6.ts] +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); + +//// [destructuringParameterDeclaration1ES6.js] +function a3(...x = [1, 2, 3]) { } +function a4(...x) { } +function a5(...a) { } +function a6(...a) { } +function a7(...a) { } +function a8(...a) { } +function a9(...a) { } +function a10(...b) { } +function a11(...b = [1, 2, 3]) { } +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt new file mode 100644 index 00000000000..afe984cc031 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(9,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(12,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (11 errors) ==== + "use strict" + function a({while}) { } + function a1({public}) { } + function a2({public: x}) { } + function a3({while: y}) { } + function a4([while, for, public]){ } + ~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + function a5(...while) { } + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '(' expected. + function a6(...public) { } + function a7(...a: string) { } + ~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + + class C { + constructor(public ...a) { } + ~~~ +!!! error TS1005: ',' expected. + } + + + a2({ public: 1 }); + a3({ while: 1 }); + a({ while: 1 }); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js new file mode 100644 index 00000000000..ba6d7548442 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -0,0 +1,65 @@ +//// [destructuringParameterDeclaration2.ts] +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + + + +//// [destructuringParameterDeclaration2.js] +"use strict"; +function a(_a) { + var while = _a.while; +} +function a1(_a) { + var public = _a.public; +} +function a2(_a) { + var x = _a.public; +} +function a3(_a) { + var y = _a.while; +} +while (, ) + for (, public; ; ) + ; +{ } +while () { } +function a6() { + var public = []; + for (var _i = 0; _i < arguments.length; _i++) { + public[_i - 0] = arguments[_i]; + } +} +function a7() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +var C = (function () { + function C(public) { + var a = []; + for (var _i = 1; _i < arguments.length; _i++) { + a[_i - 1] = arguments[_i]; + } + } + return C; +})(); +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt new file mode 100644 index 00000000000..762a0e1dd8a --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(9,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(12,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts (11 errors) ==== + "use strict" + function a({while}) { } + function a1({public}) { } + function a2({public: x}) { } + function a3({while: y}) { } + function a4([while, for, public]){ } + ~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + function a5(...while) { } + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '(' expected. + function a6(...public) { } + function a7(...a: string) { } + ~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + + class C { + constructor(public ...a) { } + ~~~ +!!! error TS1005: ',' expected. + } + + + a2({ public: 1 }); + a3({ while: 1 }); + a({ while: 1 }); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js new file mode 100644 index 00000000000..6e86aa2c001 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js @@ -0,0 +1,42 @@ +//// [destructuringParameterDeclaration2ES6.ts] +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + + + +//// [destructuringParameterDeclaration2ES6.js] +"use strict"; +function a({ while }) { } +function a1({ public }) { } +function a2({ public: x }) { } +function a3({ while: y }) { } +while (, ) + for (, public; ; ) + ; +{ } +while () { } +function a6(...public) { } +function a7(...a) { } +class C { + constructor(public, ...a) { + } +} +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration3.js new file mode 100644 index 00000000000..82d1404881c --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3.js @@ -0,0 +1,51 @@ +//// [destructuringParameterDeclaration3.ts] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} + + +//// [destructuringParameterDeclaration3.js] +function a(_a) { + var x = _a[0], _b = _a[1], y = _b[0], z = _b[1], j = _a[2][0][0]; + return [x, y, z, j]; +} +function a1(_a) { + var x = _a.slice(0); + return [x]; +} +function a2(_a) { + var public = (_a === void 0 ? { "public": "1" } : _a).public; + return public; +} +function a3(_a) { + var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; + return [y, z, a]; +} +function a4(_a) { + var _b = _a === void 0 ? { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : _a, _c = _b.x, y = _c.y, z = _c.z, a = _b.j.k.a; + return [y, z, a]; +} +function a5(_a) { + var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; + return [y, z, a]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.types b/tests/baselines/reference/destructuringParameterDeclaration3.types new file mode 100644 index 00000000000..41835d9e456 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3.types @@ -0,0 +1,92 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts === +function a([x, [y, z], [[j]]]) { +>a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] +>x : any +>y : any +>z : any +>j : any + + return [x, y, z, j]; +>[x, y, z, j] : any[] +>x : any +>y : any +>z : any +>j : any +} + +function a1([...x]) { +>a1 : ([...x]: any[]) => any[][] +>x : any[] + + return [x]; +>[x] : any[][] +>x : any[] +} + +function a2({public} = { "public": "1" }) { +>a2 : ({public}?: { "public": string; }) => string +>public : string +>{ "public": "1" } : { "public": string; } + + return public; +>public : string +} + +function a3({x: { y, z}, j: {k: {a}} }) { +>a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { +>a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] +>x : unknown +>y : number +>z : number +>j : unknown +>k : unknown +>a : string +>{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } +>x : { y: number; z: number; } +>{ y: 1, z: 1 } : { y: number; z: number; } +>y : number +>z : number +>j : { k: { a: string; }; } +>{ k: { a: "hello" } } : { k: { a: string; }; } +>k : { a: string; } +>{ a: "hello" } : { a: string; } +>a : string + + return [y, z, a]; +>[y, z, a] : (string | number)[] +>y : number +>z : number +>a : string +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { +>a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js new file mode 100644 index 00000000000..e129140f3f2 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js @@ -0,0 +1,45 @@ +//// [destructuringParameterDeclaration3ES6.ts] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} + + +//// [destructuringParameterDeclaration3ES6.js] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} +function a1([...x]) { + return [x]; +} +function a2({ public } = { "public": "1" }) { + return public; +} +function a3({ x: { y, z }, j: { k: { a } } }) { + return [y, z, a]; +} +function a4({ x: { y, z }, j: { k: { a } } } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }) { + return [y, z, a]; +} +function a5({ x: { y, z }, j: { k: { a } } }) { + return [y, z, a]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types new file mode 100644 index 00000000000..01c67e1e547 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -0,0 +1,92 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === +function a([x, [y, z], [[j]]]) { +>a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] +>x : any +>y : any +>z : any +>j : any + + return [x, y, z, j]; +>[x, y, z, j] : any[] +>x : any +>y : any +>z : any +>j : any +} + +function a1([...x]) { +>a1 : ([...x]: Iterable) => any[][] +>x : any[] + + return [x]; +>[x] : any[][] +>x : any[] +} + +function a2({public} = { "public": "1" }) { +>a2 : ({public}?: { "public": string; }) => string +>public : string +>{ "public": "1" } : { "public": string; } + + return public; +>public : string +} + +function a3({x: { y, z}, j: {k: {a}} }) { +>a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { +>a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] +>x : unknown +>y : number +>z : number +>j : unknown +>k : unknown +>a : string +>{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } +>x : { y: number; z: number; } +>{ y: 1, z: 1 } : { y: number; z: number; } +>y : number +>z : number +>j : { k: { a: string; }; } +>{ k: { a: "hello" } } : { k: { a: string; }; } +>k : { a: string; } +>{ a: "hello" } : { a: string; } +>a : string + + return [y, z, a]; +>[y, z, a] : (string | number)[] +>y : number +>z : number +>a : string +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { +>a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt new file mode 100644 index 00000000000..21cd9f36c0f --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,18): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts (4 errors) ==== + enum Foo { a } + function a({x, a}: { x: number, a: number }) { } + function a1({z: {x, y: {j}}}) { } + function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + function a3({z} = {z:10}) { } + function a4({z=10}) { } + function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } + a2(); + a2({ z: { x: "hello" , y: { j: Foo.a } }}); + a3(); + a3({ z: Foo.a }); + a4({}); + a6({ b: 10 }); + a6({ b: true }); + + // error + a4(); + ~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + a3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + function a5([z], z: number) { } + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.js b/tests/baselines/reference/destructuringParameterDeclarationES6.js new file mode 100644 index 00000000000..7a4c929003d --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclarationES6.js @@ -0,0 +1,44 @@ +//// [destructuringParameterDeclarationES6.ts] +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } + + +//// [destructuringParameterDeclarationES6.js] +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function a({ x, a }) { } +function a1({ z: { x, y: { j } } }) { } +function a2({ z: { x, y: { j } } } = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({ z } = { z: 10 }) { } +function a4({ z = 10 }) { } +function a6({ b } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello", y: { j: Foo.a } } }); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); +// error +a4(); +a3({}); +function a5([z], z) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts new file mode 100644 index 00000000000..c840dba2d2b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts @@ -0,0 +1,19 @@ +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts new file mode 100644 index 00000000000..6e9579926dd --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts @@ -0,0 +1,21 @@ +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts new file mode 100644 index 00000000000..1441226e061 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts @@ -0,0 +1,22 @@ +// @target: es6 +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts new file mode 100644 index 00000000000..59763c95902 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -0,0 +1,19 @@ +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts new file mode 100644 index 00000000000..e50a455d824 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts @@ -0,0 +1,20 @@ +//@target: es6 +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts new file mode 100644 index 00000000000..96fc87c6c86 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts @@ -0,0 +1,23 @@ +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts new file mode 100644 index 00000000000..7c50917ebe5 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts @@ -0,0 +1,24 @@ +// @target: es6 +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts new file mode 100644 index 00000000000..0d359421851 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts @@ -0,0 +1,20 @@ +//@target: es6 +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { }