From 38b7757e5704b33987d7d1f46c12a5c637248470 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 18 Nov 2016 17:55:06 -0800 Subject: [PATCH] Tests for iterationMode=iterable --- .../reference/ES5For-of33.errors.txt | 9 + tests/baselines/reference/ES5For-of33.js | 21 ++ tests/baselines/reference/ES5For-of33.js.map | 2 + .../reference/ES5For-of33.sourcemap.txt | 130 ++++++++++ .../reference/ES5For-of34.errors.txt | 12 + tests/baselines/reference/ES5For-of34.js | 27 ++ tests/baselines/reference/ES5For-of34.js.map | 2 + .../reference/ES5For-of34.sourcemap.txt | 186 ++++++++++++++ .../reference/ES5For-of35.errors.txt | 13 + tests/baselines/reference/ES5For-of35.js | 23 ++ tests/baselines/reference/ES5For-of35.js.map | 2 + .../reference/ES5For-of35.sourcemap.txt | 144 +++++++++++ .../reference/ES5For-of36.errors.txt | 10 + tests/baselines/reference/ES5For-of36.js | 31 +++ tests/baselines/reference/ES5For-of36.js.map | 2 + .../reference/ES5For-of36.sourcemap.txt | 152 ++++++++++++ .../arrayLiteralSpreadES5iterable.js | 58 +++++ .../arrayLiteralSpreadES5iterable.symbols | 67 +++++ .../arrayLiteralSpreadES5iterable.types | 133 ++++++++++ ...atternAndAssignment1ES5iterable.errors.txt | 65 +++++ ...BindingPatternAndAssignment1ES5iterable.js | 112 +++++++++ ...arameterDeclaration1ES5iterable.errors.txt | 106 ++++++++ ...cturingParameterDeclaration1ES5iterable.js | 234 ++++++++++++++++++ ...cturingParameterDeclaration3ES5iterable.js | 133 ++++++++++ ...ngParameterDeclaration3ES5iterable.symbols | 145 +++++++++++ ...ringParameterDeclaration3ES5iterable.types | 206 +++++++++++++++ ...cturingParameterDeclaration7ES5iterable.js | 35 +++ ...ngParameterDeclaration7ES5iterable.symbols | 33 +++ ...ringParameterDeclaration7ES5iterable.types | 33 +++ ...ucturingVariableDeclaration1ES5iterable.js | 89 +++++++ ...ingVariableDeclaration1ES5iterable.symbols | 120 +++++++++ ...uringVariableDeclaration1ES5iterable.types | 200 +++++++++++++++ .../emptyAssignmentPatterns01_ES5iterable.js | 15 ++ ...tyAssignmentPatterns01_ES5iterable.symbols | 11 + ...mptyAssignmentPatterns01_ES5iterable.types | 17 ++ .../emptyAssignmentPatterns02_ES5iterable.js | 27 ++ ...tyAssignmentPatterns02_ES5iterable.symbols | 25 ++ ...mptyAssignmentPatterns02_ES5iterable.types | 35 +++ .../emptyAssignmentPatterns03_ES5iterable.js | 15 ++ ...tyAssignmentPatterns03_ES5iterable.symbols | 11 + ...mptyAssignmentPatterns03_ES5iterable.types | 21 ++ .../emptyAssignmentPatterns04_ES5iterable.js | 27 ++ ...tyAssignmentPatterns04_ES5iterable.symbols | 25 ++ ...mptyAssignmentPatterns04_ES5iterable.types | 35 +++ ...eclarationBindingPatterns01_ES5iterable.js | 149 +++++++++++ ...ationBindingPatterns01_ES5iterable.symbols | 92 +++++++ ...arationBindingPatterns01_ES5iterable.types | 115 +++++++++ ...onBindingPatterns02_ES5iterable.errors.txt | 31 +++ ...eclarationBindingPatterns02_ES5iterable.js | 32 +++ ...BindingPatternAndAssignment1ES5iterable.ts | 53 ++++ ...cturingParameterDeclaration1ES5iterable.ts | 97 ++++++++ ...cturingParameterDeclaration3ES5iterable.ts | 47 ++++ ...cturingParameterDeclaration7ES5iterable.ts | 15 ++ ...ucturingVariableDeclaration1ES5iterable.ts | 41 +++ .../emptyAssignmentPatterns01_ES5iterable.ts | 8 + .../emptyAssignmentPatterns02_ES5iterable.ts | 9 + .../emptyAssignmentPatterns03_ES5iterable.ts | 8 + .../emptyAssignmentPatterns04_ES5iterable.ts | 9 + ...eclarationBindingPatterns01_ES5iterable.ts | 51 ++++ ...eclarationBindingPatterns02_ES5iterable.ts | 13 + .../spread/arrayLiteralSpreadES5iterable.ts | 23 ++ .../for-ofStatements/ES5For-of33.ts | 5 + .../for-ofStatements/ES5For-of34.ts | 8 + .../for-ofStatements/ES5For-of35.ts | 6 + .../for-ofStatements/ES5For-of36.ts | 6 + 65 files changed, 3617 insertions(+) create mode 100644 tests/baselines/reference/ES5For-of33.errors.txt create mode 100644 tests/baselines/reference/ES5For-of33.js create mode 100644 tests/baselines/reference/ES5For-of33.js.map create mode 100644 tests/baselines/reference/ES5For-of33.sourcemap.txt create mode 100644 tests/baselines/reference/ES5For-of34.errors.txt create mode 100644 tests/baselines/reference/ES5For-of34.js create mode 100644 tests/baselines/reference/ES5For-of34.js.map create mode 100644 tests/baselines/reference/ES5For-of34.sourcemap.txt create mode 100644 tests/baselines/reference/ES5For-of35.errors.txt create mode 100644 tests/baselines/reference/ES5For-of35.js create mode 100644 tests/baselines/reference/ES5For-of35.js.map create mode 100644 tests/baselines/reference/ES5For-of35.sourcemap.txt create mode 100644 tests/baselines/reference/ES5For-of36.errors.txt create mode 100644 tests/baselines/reference/ES5For-of36.js create mode 100644 tests/baselines/reference/ES5For-of36.js.map create mode 100644 tests/baselines/reference/ES5For-of36.sourcemap.txt create mode 100644 tests/baselines/reference/arrayLiteralSpreadES5iterable.js create mode 100644 tests/baselines/reference/arrayLiteralSpreadES5iterable.symbols create mode 100644 tests/baselines/reference/arrayLiteralSpreadES5iterable.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.errors.txt create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.symbols create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.symbols create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.types create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.symbols create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.types create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.js create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.symbols create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.types create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.errors.txt create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts create mode 100644 tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts create mode 100644 tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts create mode 100644 tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts create mode 100644 tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts create mode 100644 tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts diff --git a/tests/baselines/reference/ES5For-of33.errors.txt b/tests/baselines/reference/ES5For-of33.errors.txt new file mode 100644 index 0000000000..02ba889c54 --- /dev/null +++ b/tests/baselines/reference/ES5For-of33.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts(2,5): error TS2304: Cannot find name 'console'. + + +==== tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts (1 errors) ==== + for (var v of ['a', 'b', 'c']) { + console.log(v); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of33.js b/tests/baselines/reference/ES5For-of33.js new file mode 100644 index 0000000000..205fd29e87 --- /dev/null +++ b/tests/baselines/reference/ES5For-of33.js @@ -0,0 +1,21 @@ +//// [ES5For-of33.ts] +for (var v of ['a', 'b', 'c']) { + console.log(v); +} + +//// [ES5For-of33.js] +var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +try { + for (var iterator_1 = { iterator: __values(['a', 'b', 'c']) }; __step(iterator_1);) { + var v = iterator_1.result.value; + console.log(v); + } +} +catch (e_1_1) { e_1 = { error: e_1_1 }; } +finally { + try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +} +var e_1; +//# sourceMappingURL=ES5For-of33.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of33.js.map b/tests/baselines/reference/ES5For-of33.js.map new file mode 100644 index 0000000000..3ba7af6315 --- /dev/null +++ b/tests/baselines/reference/ES5For-of33.js.map @@ -0,0 +1,2 @@ +//// [ES5For-of33.js.map] +{"version":3,"file":"ES5For-of33.js","sourceRoot":"","sources":["ES5For-of33.ts"],"names":[],"mappings":";;;;IAAA,GAAG,CAAC,CAAU,IAAA,aAAA,EAAA,UAAA,SAAA,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA,EAAA,EAAxB,kBAAK;QAAL,IAAI,CAAC,0BAAA;QACN,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAClB"} \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of33.sourcemap.txt b/tests/baselines/reference/ES5For-of33.sourcemap.txt new file mode 100644 index 0000000000..37e16006d3 --- /dev/null +++ b/tests/baselines/reference/ES5For-of33.sourcemap.txt @@ -0,0 +1,130 @@ +=================================================================== +JsFile: ES5For-of33.js +mapUrl: ES5For-of33.js.map +sourceRoot: +sources: ES5For-of33.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of33.js +sourceFile:ES5For-of33.ts +------------------------------------------------------------------- +>>>var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +>>>var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +>>>var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +>>>try { +>>> for (var iterator_1 = { iterator: __values(['a', 'b', 'c']) }; __step(iterator_1);) { +1 >^^^^ +2 > ^^^ +3 > ^ +4 > ^ +5 > ^^^^ +6 > ^^^^^^^^^^^^^ +7 > ^^ +8 > ^^^^^^^^^^ +9 > ^^^^^^^^^ +10> ^ +11> ^^^ +12> ^^ +13> ^^^ +14> ^^ +15> ^^^ +16> ^ +17> ^ +18> ^^ +19> ^^ +20> ^^^^^^^^^^^^^^^^^^ +1 > +2 > for +3 > +4 > (var v of +5 > +6 > +7 > +8 > +9 > +10> [ +11> 'a' +12> , +13> 'b' +14> , +15> 'c' +16> ] +17> +18> +19> +20> var v +1 >Emitted(5, 5) Source(1, 1) + SourceIndex(0) +2 >Emitted(5, 8) Source(1, 4) + SourceIndex(0) +3 >Emitted(5, 9) Source(1, 5) + SourceIndex(0) +4 >Emitted(5, 10) Source(1, 15) + SourceIndex(0) +5 >Emitted(5, 14) Source(1, 15) + SourceIndex(0) +6 >Emitted(5, 27) Source(1, 15) + SourceIndex(0) +7 >Emitted(5, 29) Source(1, 15) + SourceIndex(0) +8 >Emitted(5, 39) Source(1, 15) + SourceIndex(0) +9 >Emitted(5, 48) Source(1, 15) + SourceIndex(0) +10>Emitted(5, 49) Source(1, 16) + SourceIndex(0) +11>Emitted(5, 52) Source(1, 19) + SourceIndex(0) +12>Emitted(5, 54) Source(1, 21) + SourceIndex(0) +13>Emitted(5, 57) Source(1, 24) + SourceIndex(0) +14>Emitted(5, 59) Source(1, 26) + SourceIndex(0) +15>Emitted(5, 62) Source(1, 29) + SourceIndex(0) +16>Emitted(5, 63) Source(1, 30) + SourceIndex(0) +17>Emitted(5, 64) Source(1, 30) + SourceIndex(0) +18>Emitted(5, 66) Source(1, 30) + SourceIndex(0) +19>Emitted(5, 68) Source(1, 6) + SourceIndex(0) +20>Emitted(5, 86) Source(1, 11) + SourceIndex(0) +--- +>>> var v = iterator_1.result.value; +1 >^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 > var +3 > v +4 > +1 >Emitted(6, 9) Source(1, 6) + SourceIndex(0) +2 >Emitted(6, 13) Source(1, 10) + SourceIndex(0) +3 >Emitted(6, 14) Source(1, 11) + SourceIndex(0) +4 >Emitted(6, 40) Source(1, 11) + SourceIndex(0) +--- +>>> console.log(v); +1 >^^^^^^^^ +2 > ^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +1 > of ['a', 'b', 'c']) { + > +2 > console +3 > . +4 > log +5 > ( +6 > v +7 > ) +8 > ; +1 >Emitted(7, 9) Source(2, 5) + SourceIndex(0) +2 >Emitted(7, 16) Source(2, 12) + SourceIndex(0) +3 >Emitted(7, 17) Source(2, 13) + SourceIndex(0) +4 >Emitted(7, 20) Source(2, 16) + SourceIndex(0) +5 >Emitted(7, 21) Source(2, 17) + SourceIndex(0) +6 >Emitted(7, 22) Source(2, 18) + SourceIndex(0) +7 >Emitted(7, 23) Source(2, 19) + SourceIndex(0) +8 >Emitted(7, 24) Source(2, 20) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 > + >} +1 >Emitted(8, 6) Source(3, 2) + SourceIndex(0) +--- +>>>} +>>>catch (e_1_1) { e_1 = { error: e_1_1 }; } +>>>finally { +>>> try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +>>>} +>>>var e_1; +>>>//# sourceMappingURL=ES5For-of33.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of34.errors.txt b/tests/baselines/reference/ES5For-of34.errors.txt new file mode 100644 index 0000000000..46f9666f77 --- /dev/null +++ b/tests/baselines/reference/ES5For-of34.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts(4,6): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts (1 errors) ==== + function foo() { + return { x: 0 }; + } + for (foo().x of ['a', 'b', 'c']) { + ~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var p = foo().x; + } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of34.js b/tests/baselines/reference/ES5For-of34.js new file mode 100644 index 0000000000..0ad5a2793d --- /dev/null +++ b/tests/baselines/reference/ES5For-of34.js @@ -0,0 +1,27 @@ +//// [ES5For-of34.ts] +function foo() { + return { x: 0 }; +} +for (foo().x of ['a', 'b', 'c']) { + var p = foo().x; +} + +//// [ES5For-of34.js] +var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +function foo() { + return { x: 0 }; +} +try { + for (var iterator_1 = { iterator: __values(['a', 'b', 'c']) }; __step(iterator_1);) { + foo().x = iterator_1.result.value; + var p = foo().x; + } +} +catch (e_1_1) { e_1 = { error: e_1_1 }; } +finally { + try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +} +var e_1; +//# sourceMappingURL=ES5For-of34.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of34.js.map b/tests/baselines/reference/ES5For-of34.js.map new file mode 100644 index 0000000000..44d10b261b --- /dev/null +++ b/tests/baselines/reference/ES5For-of34.js.map @@ -0,0 +1,2 @@ +//// [ES5For-of34.js.map] +{"version":3,"file":"ES5For-of34.js","sourceRoot":"","sources":["ES5For-of34.ts"],"names":[],"mappings":";;;AAAA;IACI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACpB,CAAC;;IACD,GAAG,CAAC,CAAY,IAAA,aAAA,EAAA,UAAA,SAAA,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA,EAAA,EAA1B,kBAAO;QAAP,GAAG,EAAE,CAAC,CAAC,0BAAA;QACR,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;KACnB"} \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of34.sourcemap.txt b/tests/baselines/reference/ES5For-of34.sourcemap.txt new file mode 100644 index 0000000000..6d2d772474 --- /dev/null +++ b/tests/baselines/reference/ES5For-of34.sourcemap.txt @@ -0,0 +1,186 @@ +=================================================================== +JsFile: ES5For-of34.js +mapUrl: ES5For-of34.js.map +sourceRoot: +sources: ES5For-of34.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of34.js +sourceFile:ES5For-of34.ts +------------------------------------------------------------------- +>>>var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +>>>var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +>>>var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +>>>function foo() { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(4, 1) Source(1, 1) + SourceIndex(0) +--- +>>> return { x: 0 }; +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^ +7 > ^ +8 > ^^ +9 > ^ +1->function foo() { + > +2 > return +3 > +4 > { +5 > x +6 > : +7 > 0 +8 > } +9 > ; +1->Emitted(5, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(5, 11) Source(2, 11) + SourceIndex(0) +3 >Emitted(5, 12) Source(2, 12) + SourceIndex(0) +4 >Emitted(5, 14) Source(2, 14) + SourceIndex(0) +5 >Emitted(5, 15) Source(2, 15) + SourceIndex(0) +6 >Emitted(5, 17) Source(2, 17) + SourceIndex(0) +7 >Emitted(5, 18) Source(2, 18) + SourceIndex(0) +8 >Emitted(5, 20) Source(2, 20) + SourceIndex(0) +9 >Emitted(5, 21) Source(2, 21) + SourceIndex(0) +--- +>>>} +1 > +2 >^ +3 > ^^^^^-> +1 > + > +2 >} +1 >Emitted(6, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(6, 2) Source(3, 2) + SourceIndex(0) +--- +>>>try { +>>> for (var iterator_1 = { iterator: __values(['a', 'b', 'c']) }; __step(iterator_1);) { +1->^^^^ +2 > ^^^ +3 > ^ +4 > ^ +5 > ^^^^ +6 > ^^^^^^^^^^^^^ +7 > ^^ +8 > ^^^^^^^^^^ +9 > ^^^^^^^^^ +10> ^ +11> ^^^ +12> ^^ +13> ^^^ +14> ^^ +15> ^^^ +16> ^ +17> ^ +18> ^^ +19> ^^ +20> ^^^^^^^^^^^^^^^^^^ +1-> + > +2 > for +3 > +4 > (foo().x of +5 > +6 > +7 > +8 > +9 > +10> [ +11> 'a' +12> , +13> 'b' +14> , +15> 'c' +16> ] +17> +18> +19> +20> foo().x +1->Emitted(8, 5) Source(4, 1) + SourceIndex(0) +2 >Emitted(8, 8) Source(4, 4) + SourceIndex(0) +3 >Emitted(8, 9) Source(4, 5) + SourceIndex(0) +4 >Emitted(8, 10) Source(4, 17) + SourceIndex(0) +5 >Emitted(8, 14) Source(4, 17) + SourceIndex(0) +6 >Emitted(8, 27) Source(4, 17) + SourceIndex(0) +7 >Emitted(8, 29) Source(4, 17) + SourceIndex(0) +8 >Emitted(8, 39) Source(4, 17) + SourceIndex(0) +9 >Emitted(8, 48) Source(4, 17) + SourceIndex(0) +10>Emitted(8, 49) Source(4, 18) + SourceIndex(0) +11>Emitted(8, 52) Source(4, 21) + SourceIndex(0) +12>Emitted(8, 54) Source(4, 23) + SourceIndex(0) +13>Emitted(8, 57) Source(4, 26) + SourceIndex(0) +14>Emitted(8, 59) Source(4, 28) + SourceIndex(0) +15>Emitted(8, 62) Source(4, 31) + SourceIndex(0) +16>Emitted(8, 63) Source(4, 32) + SourceIndex(0) +17>Emitted(8, 64) Source(4, 32) + SourceIndex(0) +18>Emitted(8, 66) Source(4, 32) + SourceIndex(0) +19>Emitted(8, 68) Source(4, 6) + SourceIndex(0) +20>Emitted(8, 86) Source(4, 13) + SourceIndex(0) +--- +>>> foo().x = iterator_1.result.value; +1 >^^^^^^^^ +2 > ^^^ +3 > ^^ +4 > ^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 > foo +3 > () +4 > . +5 > x +6 > +1 >Emitted(9, 9) Source(4, 6) + SourceIndex(0) +2 >Emitted(9, 12) Source(4, 9) + SourceIndex(0) +3 >Emitted(9, 14) Source(4, 11) + SourceIndex(0) +4 >Emitted(9, 15) Source(4, 12) + SourceIndex(0) +5 >Emitted(9, 16) Source(4, 13) + SourceIndex(0) +6 >Emitted(9, 42) Source(4, 13) + SourceIndex(0) +--- +>>> var p = foo().x; +1 >^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^ +5 > ^^^ +6 > ^^ +7 > ^ +8 > ^ +9 > ^ +1 > of ['a', 'b', 'c']) { + > +2 > var +3 > p +4 > = +5 > foo +6 > () +7 > . +8 > x +9 > ; +1 >Emitted(10, 9) Source(5, 5) + SourceIndex(0) +2 >Emitted(10, 13) Source(5, 9) + SourceIndex(0) +3 >Emitted(10, 14) Source(5, 10) + SourceIndex(0) +4 >Emitted(10, 17) Source(5, 13) + SourceIndex(0) +5 >Emitted(10, 20) Source(5, 16) + SourceIndex(0) +6 >Emitted(10, 22) Source(5, 18) + SourceIndex(0) +7 >Emitted(10, 23) Source(5, 19) + SourceIndex(0) +8 >Emitted(10, 24) Source(5, 20) + SourceIndex(0) +9 >Emitted(10, 25) Source(5, 21) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 > + >} +1 >Emitted(11, 6) Source(6, 2) + SourceIndex(0) +--- +>>>} +>>>catch (e_1_1) { e_1 = { error: e_1_1 }; } +>>>finally { +>>> try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +>>>} +>>>var e_1; +>>>//# sourceMappingURL=ES5For-of34.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of35.errors.txt b/tests/baselines/reference/ES5For-of35.errors.txt new file mode 100644 index 0000000000..8c43d95988 --- /dev/null +++ b/tests/baselines/reference/ES5For-of35.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,13): error TS2459: Type 'number' has no property 'x' and no string index signature. +tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,23): error TS2459: Type 'number' has no property 'y' and no string index signature. + + +==== tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts (2 errors) ==== + for (const {x: a = 0, y: b = 1} of [2, 3]) { + ~ +!!! error TS2459: Type 'number' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type 'number' has no property 'y' and no string index signature. + a; + b; + } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of35.js b/tests/baselines/reference/ES5For-of35.js new file mode 100644 index 0000000000..74bf504d78 --- /dev/null +++ b/tests/baselines/reference/ES5For-of35.js @@ -0,0 +1,23 @@ +//// [ES5For-of35.ts] +for (const {x: a = 0, y: b = 1} of [2, 3]) { + a; + b; +} + +//// [ES5For-of35.js] +var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +try { + for (var iterator_1 = { iterator: __values([2, 3]) }; __step(iterator_1);) { + var _a = iterator_1.result.value, _b = _a.x, a = _b === void 0 ? 0 : _b, _c = _a.y, b = _c === void 0 ? 1 : _c; + a; + b; + } +} +catch (e_1_1) { e_1 = { error: e_1_1 }; } +finally { + try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +} +var e_1; +//# sourceMappingURL=ES5For-of35.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of35.js.map b/tests/baselines/reference/ES5For-of35.js.map new file mode 100644 index 0000000000..514377fba6 --- /dev/null +++ b/tests/baselines/reference/ES5For-of35.js.map @@ -0,0 +1,2 @@ +//// [ES5For-of35.js.map] +{"version":3,"file":"ES5For-of35.js","sourceRoot":"","sources":["ES5For-of35.ts"],"names":[],"mappings":";;;;IAAA,GAAG,CAAC,CAA+B,IAAA,aAAA,EAAA,UAAA,SAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,EAApC,kBAA0B;QAApB,IAAA,4BAAoB,EAAnB,SAAQ,EAAR,0BAAQ,EAAE,SAAQ,EAAR,0BAAQ;QAC1B,CAAC,CAAC;QACF,CAAC,CAAC;KACL"} \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of35.sourcemap.txt b/tests/baselines/reference/ES5For-of35.sourcemap.txt new file mode 100644 index 0000000000..1bc0bc77b8 --- /dev/null +++ b/tests/baselines/reference/ES5For-of35.sourcemap.txt @@ -0,0 +1,144 @@ +=================================================================== +JsFile: ES5For-of35.js +mapUrl: ES5For-of35.js.map +sourceRoot: +sources: ES5For-of35.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of35.js +sourceFile:ES5For-of35.ts +------------------------------------------------------------------- +>>>var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +>>>var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +>>>var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +>>>try { +>>> for (var iterator_1 = { iterator: __values([2, 3]) }; __step(iterator_1);) { +1 >^^^^ +2 > ^^^ +3 > ^ +4 > ^ +5 > ^^^^ +6 > ^^^^^^^^^^^^^ +7 > ^^ +8 > ^^^^^^^^^^ +9 > ^^^^^^^^^ +10> ^ +11> ^ +12> ^^ +13> ^ +14> ^ +15> ^ +16> ^^ +17> ^^ +18> ^^^^^^^^^^^^^^^^^^ +19> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 > for +3 > +4 > (const {x: a = 0, y: b = 1} of +5 > +6 > +7 > +8 > +9 > +10> [ +11> 2 +12> , +13> 3 +14> ] +15> +16> +17> +18> const {x: a = 0, y: b = 1} +1 >Emitted(5, 5) Source(1, 1) + SourceIndex(0) +2 >Emitted(5, 8) Source(1, 4) + SourceIndex(0) +3 >Emitted(5, 9) Source(1, 5) + SourceIndex(0) +4 >Emitted(5, 10) Source(1, 36) + SourceIndex(0) +5 >Emitted(5, 14) Source(1, 36) + SourceIndex(0) +6 >Emitted(5, 27) Source(1, 36) + SourceIndex(0) +7 >Emitted(5, 29) Source(1, 36) + SourceIndex(0) +8 >Emitted(5, 39) Source(1, 36) + SourceIndex(0) +9 >Emitted(5, 48) Source(1, 36) + SourceIndex(0) +10>Emitted(5, 49) Source(1, 37) + SourceIndex(0) +11>Emitted(5, 50) Source(1, 38) + SourceIndex(0) +12>Emitted(5, 52) Source(1, 40) + SourceIndex(0) +13>Emitted(5, 53) Source(1, 41) + SourceIndex(0) +14>Emitted(5, 54) Source(1, 42) + SourceIndex(0) +15>Emitted(5, 55) Source(1, 42) + SourceIndex(0) +16>Emitted(5, 57) Source(1, 42) + SourceIndex(0) +17>Emitted(5, 59) Source(1, 6) + SourceIndex(0) +18>Emitted(5, 77) Source(1, 32) + SourceIndex(0) +--- +>>> var _a = iterator_1.result.value, _b = _a.x, a = _b === void 0 ? 0 : _b, _c = _a.y, b = _c === void 0 ? 1 : _c; +1->^^^^^^^^ +2 > ^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 > +3 > {x: a = 0, y: b = 1} +4 > +5 > x: a = 0 +6 > +7 > x: a = 0 +8 > , +9 > y: b = 1 +10> +11> y: b = 1 +1->Emitted(6, 9) Source(1, 12) + SourceIndex(0) +2 >Emitted(6, 13) Source(1, 12) + SourceIndex(0) +3 >Emitted(6, 41) Source(1, 32) + SourceIndex(0) +4 >Emitted(6, 43) Source(1, 13) + SourceIndex(0) +5 >Emitted(6, 52) Source(1, 21) + SourceIndex(0) +6 >Emitted(6, 54) Source(1, 13) + SourceIndex(0) +7 >Emitted(6, 80) Source(1, 21) + SourceIndex(0) +8 >Emitted(6, 82) Source(1, 23) + SourceIndex(0) +9 >Emitted(6, 91) Source(1, 31) + SourceIndex(0) +10>Emitted(6, 93) Source(1, 23) + SourceIndex(0) +11>Emitted(6, 119) Source(1, 31) + SourceIndex(0) +--- +>>> a; +1 >^^^^^^^^ +2 > ^ +3 > ^ +4 > ^-> +1 >} of [2, 3]) { + > +2 > a +3 > ; +1 >Emitted(7, 9) Source(2, 5) + SourceIndex(0) +2 >Emitted(7, 10) Source(2, 6) + SourceIndex(0) +3 >Emitted(7, 11) Source(2, 7) + SourceIndex(0) +--- +>>> b; +1->^^^^^^^^ +2 > ^ +3 > ^ +1-> + > +2 > b +3 > ; +1->Emitted(8, 9) Source(3, 5) + SourceIndex(0) +2 >Emitted(8, 10) Source(3, 6) + SourceIndex(0) +3 >Emitted(8, 11) Source(3, 7) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 > + >} +1 >Emitted(9, 6) Source(4, 2) + SourceIndex(0) +--- +>>>} +>>>catch (e_1_1) { e_1 = { error: e_1_1 }; } +>>>finally { +>>> try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +>>>} +>>>var e_1; +>>>//# sourceMappingURL=ES5For-of35.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of36.errors.txt b/tests/baselines/reference/ES5For-of36.errors.txt new file mode 100644 index 0000000000..bd476f77c6 --- /dev/null +++ b/tests/baselines/reference/ES5For-of36.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts(1,10): error TS2544: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator. + + +==== tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts (1 errors) ==== + for (let [a = 0, b = 1] of [2, 3]) { + ~~~~~~~~~~~~~~ +!!! error TS2544: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator. + a; + b; + } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of36.js b/tests/baselines/reference/ES5For-of36.js new file mode 100644 index 0000000000..ace65b7827 --- /dev/null +++ b/tests/baselines/reference/ES5For-of36.js @@ -0,0 +1,31 @@ +//// [ES5For-of36.ts] +for (let [a = 0, b = 1] of [2, 3]) { + a; + b; +} + +//// [ES5For-of36.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +try { + for (var iterator_1 = { iterator: __values([2, 3]) }; __step(iterator_1);) { + var _a = __read(iterator_1.result.value, 2), _b = _a[0], a = _b === void 0 ? 0 : _b, _c = _a[1], b = _c === void 0 ? 1 : _c; + a; + b; + } +} +catch (e_1_1) { e_1 = { error: e_1_1 }; } +finally { + try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +} +var e_1; +//# sourceMappingURL=ES5For-of36.js.map \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of36.js.map b/tests/baselines/reference/ES5For-of36.js.map new file mode 100644 index 0000000000..8b3e7a42e9 --- /dev/null +++ b/tests/baselines/reference/ES5For-of36.js.map @@ -0,0 +1,2 @@ +//// [ES5For-of36.js.map] +{"version":3,"file":"ES5For-of36.js","sourceRoot":"","sources":["ES5For-of36.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,GAAG,CAAC,CAAuB,IAAA,aAAA,EAAA,UAAA,SAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,EAA5B,kBAAkB;QAAd,IAAA,uCAAc,EAAb,UAAK,EAAL,0BAAK,EAAE,UAAK,EAAL,0BAAK;QAClB,CAAC,CAAC;QACF,CAAC,CAAC;KACL"} \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of36.sourcemap.txt b/tests/baselines/reference/ES5For-of36.sourcemap.txt new file mode 100644 index 0000000000..f52ca8eec8 --- /dev/null +++ b/tests/baselines/reference/ES5For-of36.sourcemap.txt @@ -0,0 +1,152 @@ +=================================================================== +JsFile: ES5For-of36.js +mapUrl: ES5For-of36.js.map +sourceRoot: +sources: ES5For-of36.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of36.js +sourceFile:ES5For-of36.ts +------------------------------------------------------------------- +>>>var __read = (this && this.__read) || function (o, n) { +>>> if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; +>>> var m, i = m.call(o), ar = [], r, e; +>>> try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } +>>> catch (error) { e = { error: error }; } +>>> finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } +>>> return ar; +>>>}; +>>>var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +>>>var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +>>>var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +>>>try { +>>> for (var iterator_1 = { iterator: __values([2, 3]) }; __step(iterator_1);) { +1 >^^^^ +2 > ^^^ +3 > ^ +4 > ^ +5 > ^^^^ +6 > ^^^^^^^^^^^^^ +7 > ^^ +8 > ^^^^^^^^^^ +9 > ^^^^^^^^^ +10> ^ +11> ^ +12> ^^ +13> ^ +14> ^ +15> ^ +16> ^^ +17> ^^ +18> ^^^^^^^^^^^^^^^^^^ +19> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 > for +3 > +4 > (let [a = 0, b = 1] of +5 > +6 > +7 > +8 > +9 > +10> [ +11> 2 +12> , +13> 3 +14> ] +15> +16> +17> +18> let [a = 0, b = 1] +1 >Emitted(13, 5) Source(1, 1) + SourceIndex(0) +2 >Emitted(13, 8) Source(1, 4) + SourceIndex(0) +3 >Emitted(13, 9) Source(1, 5) + SourceIndex(0) +4 >Emitted(13, 10) Source(1, 28) + SourceIndex(0) +5 >Emitted(13, 14) Source(1, 28) + SourceIndex(0) +6 >Emitted(13, 27) Source(1, 28) + SourceIndex(0) +7 >Emitted(13, 29) Source(1, 28) + SourceIndex(0) +8 >Emitted(13, 39) Source(1, 28) + SourceIndex(0) +9 >Emitted(13, 48) Source(1, 28) + SourceIndex(0) +10>Emitted(13, 49) Source(1, 29) + SourceIndex(0) +11>Emitted(13, 50) Source(1, 30) + SourceIndex(0) +12>Emitted(13, 52) Source(1, 32) + SourceIndex(0) +13>Emitted(13, 53) Source(1, 33) + SourceIndex(0) +14>Emitted(13, 54) Source(1, 34) + SourceIndex(0) +15>Emitted(13, 55) Source(1, 34) + SourceIndex(0) +16>Emitted(13, 57) Source(1, 34) + SourceIndex(0) +17>Emitted(13, 59) Source(1, 6) + SourceIndex(0) +18>Emitted(13, 77) Source(1, 24) + SourceIndex(0) +--- +>>> var _a = __read(iterator_1.result.value, 2), _b = _a[0], a = _b === void 0 ? 0 : _b, _c = _a[1], b = _c === void 0 ? 1 : _c; +1->^^^^^^^^ +2 > ^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 > +3 > [a = 0, b = 1] +4 > +5 > a = 0 +6 > +7 > a = 0 +8 > , +9 > b = 1 +10> +11> b = 1 +1->Emitted(14, 9) Source(1, 10) + SourceIndex(0) +2 >Emitted(14, 13) Source(1, 10) + SourceIndex(0) +3 >Emitted(14, 52) Source(1, 24) + SourceIndex(0) +4 >Emitted(14, 54) Source(1, 11) + SourceIndex(0) +5 >Emitted(14, 64) Source(1, 16) + SourceIndex(0) +6 >Emitted(14, 66) Source(1, 11) + SourceIndex(0) +7 >Emitted(14, 92) Source(1, 16) + SourceIndex(0) +8 >Emitted(14, 94) Source(1, 18) + SourceIndex(0) +9 >Emitted(14, 104) Source(1, 23) + SourceIndex(0) +10>Emitted(14, 106) Source(1, 18) + SourceIndex(0) +11>Emitted(14, 132) Source(1, 23) + SourceIndex(0) +--- +>>> a; +1 >^^^^^^^^ +2 > ^ +3 > ^ +4 > ^-> +1 >] of [2, 3]) { + > +2 > a +3 > ; +1 >Emitted(15, 9) Source(2, 5) + SourceIndex(0) +2 >Emitted(15, 10) Source(2, 6) + SourceIndex(0) +3 >Emitted(15, 11) Source(2, 7) + SourceIndex(0) +--- +>>> b; +1->^^^^^^^^ +2 > ^ +3 > ^ +1-> + > +2 > b +3 > ; +1->Emitted(16, 9) Source(3, 5) + SourceIndex(0) +2 >Emitted(16, 10) Source(3, 6) + SourceIndex(0) +3 >Emitted(16, 11) Source(3, 7) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 > + >} +1 >Emitted(17, 6) Source(4, 2) + SourceIndex(0) +--- +>>>} +>>>catch (e_1_1) { e_1 = { error: e_1_1 }; } +>>>finally { +>>> try { __close(iterator_1); } finally { if (e_1) throw e_1.error; } +>>>} +>>>var e_1; +>>>//# sourceMappingURL=ES5For-of36.js.map \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralSpreadES5iterable.js b/tests/baselines/reference/arrayLiteralSpreadES5iterable.js new file mode 100644 index 0000000000..6e24b8389a --- /dev/null +++ b/tests/baselines/reference/arrayLiteralSpreadES5iterable.js @@ -0,0 +1,58 @@ +//// [arrayLiteralSpreadES5iterable.ts] +function f0() { + var a = [1, 2, 3]; + var a1 = [...a]; + var a2 = [1, ...a]; + var a3 = [1, 2, ...a]; + var a4 = [...a, 1]; + var a5 = [...a, 1, 2]; + var a6 = [1, 2, ...a, 1, 2]; + var a7 = [1, ...a, 2, ...a]; + var a8 = [...a, ...a, ...a]; +} + +function f1() { + var a = [1, 2, 3]; + var b = ["hello", ...a, true]; + var b: (string | number | boolean)[]; +} + +function f2() { + var a = [...[...[...[...[...[]]]]]]; + var b = [...[...[...[...[...[5]]]]]]; +} + + +//// [arrayLiteralSpreadES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __spread = (this && this.__spread) || function () { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + return ar; +}; +function f0() { + var a = [1, 2, 3]; + var a1 = __spread(a); + var a2 = __spread([1], a); + var a3 = __spread([1, 2], a); + var a4 = __spread(a, [1]); + var a5 = __spread(a, [1, 2]); + var a6 = __spread([1, 2], a, [1, 2]); + var a7 = __spread([1], a, [2], a); + var a8 = __spread(a, a, a); +} +function f1() { + var a = [1, 2, 3]; + var b = __spread(["hello"], a, [true]); + var b; +} +function f2() { + var a = __spread([]); + var b = __spread([5]); +} diff --git a/tests/baselines/reference/arrayLiteralSpreadES5iterable.symbols b/tests/baselines/reference/arrayLiteralSpreadES5iterable.symbols new file mode 100644 index 0000000000..e31cc74e01 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralSpreadES5iterable.symbols @@ -0,0 +1,67 @@ +=== tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts === +function f0() { +>f0 : Symbol(f0, Decl(arrayLiteralSpreadES5iterable.ts, 0, 0)) + + var a = [1, 2, 3]; +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a1 = [...a]; +>a1 : Symbol(a1, Decl(arrayLiteralSpreadES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a2 = [1, ...a]; +>a2 : Symbol(a2, Decl(arrayLiteralSpreadES5iterable.ts, 3, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a3 = [1, 2, ...a]; +>a3 : Symbol(a3, Decl(arrayLiteralSpreadES5iterable.ts, 4, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a4 = [...a, 1]; +>a4 : Symbol(a4, Decl(arrayLiteralSpreadES5iterable.ts, 5, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a5 = [...a, 1, 2]; +>a5 : Symbol(a5, Decl(arrayLiteralSpreadES5iterable.ts, 6, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a6 = [1, 2, ...a, 1, 2]; +>a6 : Symbol(a6, Decl(arrayLiteralSpreadES5iterable.ts, 7, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a7 = [1, ...a, 2, ...a]; +>a7 : Symbol(a7, Decl(arrayLiteralSpreadES5iterable.ts, 8, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) + + var a8 = [...a, ...a, ...a]; +>a8 : Symbol(a8, Decl(arrayLiteralSpreadES5iterable.ts, 9, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 1, 7)) +} + +function f1() { +>f1 : Symbol(f1, Decl(arrayLiteralSpreadES5iterable.ts, 10, 1)) + + var a = [1, 2, 3]; +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 13, 7)) + + var b = ["hello", ...a, true]; +>b : Symbol(b, Decl(arrayLiteralSpreadES5iterable.ts, 14, 7), Decl(arrayLiteralSpreadES5iterable.ts, 15, 7)) +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 13, 7)) + + var b: (string | number | boolean)[]; +>b : Symbol(b, Decl(arrayLiteralSpreadES5iterable.ts, 14, 7), Decl(arrayLiteralSpreadES5iterable.ts, 15, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(arrayLiteralSpreadES5iterable.ts, 16, 1)) + + var a = [...[...[...[...[...[]]]]]]; +>a : Symbol(a, Decl(arrayLiteralSpreadES5iterable.ts, 19, 7)) + + var b = [...[...[...[...[...[5]]]]]]; +>b : Symbol(b, Decl(arrayLiteralSpreadES5iterable.ts, 20, 7)) +} + diff --git a/tests/baselines/reference/arrayLiteralSpreadES5iterable.types b/tests/baselines/reference/arrayLiteralSpreadES5iterable.types new file mode 100644 index 0000000000..21c41bb6dc --- /dev/null +++ b/tests/baselines/reference/arrayLiteralSpreadES5iterable.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts === +function f0() { +>f0 : () => void + + var a = [1, 2, 3]; +>a : number[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + + var a1 = [...a]; +>a1 : number[] +>[...a] : number[] +>...a : number +>a : number[] + + var a2 = [1, ...a]; +>a2 : number[] +>[1, ...a] : number[] +>1 : 1 +>...a : number +>a : number[] + + var a3 = [1, 2, ...a]; +>a3 : number[] +>[1, 2, ...a] : number[] +>1 : 1 +>2 : 2 +>...a : number +>a : number[] + + var a4 = [...a, 1]; +>a4 : number[] +>[...a, 1] : number[] +>...a : number +>a : number[] +>1 : 1 + + var a5 = [...a, 1, 2]; +>a5 : number[] +>[...a, 1, 2] : number[] +>...a : number +>a : number[] +>1 : 1 +>2 : 2 + + var a6 = [1, 2, ...a, 1, 2]; +>a6 : number[] +>[1, 2, ...a, 1, 2] : number[] +>1 : 1 +>2 : 2 +>...a : number +>a : number[] +>1 : 1 +>2 : 2 + + var a7 = [1, ...a, 2, ...a]; +>a7 : number[] +>[1, ...a, 2, ...a] : number[] +>1 : 1 +>...a : number +>a : number[] +>2 : 2 +>...a : number +>a : number[] + + var a8 = [...a, ...a, ...a]; +>a8 : number[] +>[...a, ...a, ...a] : number[] +>...a : number +>a : number[] +>...a : number +>a : number[] +>...a : number +>a : number[] +} + +function f1() { +>f1 : () => void + + var a = [1, 2, 3]; +>a : number[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + + var b = ["hello", ...a, true]; +>b : (string | number | boolean)[] +>["hello", ...a, true] : (string | number | boolean)[] +>"hello" : "hello" +>...a : number +>a : number[] +>true : true + + var b: (string | number | boolean)[]; +>b : (string | number | boolean)[] +} + +function f2() { +>f2 : () => void + + var a = [...[...[...[...[...[]]]]]]; +>a : any[] +>[...[...[...[...[...[]]]]]] : undefined[] +>...[...[...[...[...[]]]]] : undefined +>[...[...[...[...[]]]]] : undefined[] +>...[...[...[...[]]]] : undefined +>[...[...[...[]]]] : undefined[] +>...[...[...[]]] : undefined +>[...[...[]]] : undefined[] +>...[...[]] : undefined +>[...[]] : undefined[] +>...[] : undefined +>[] : undefined[] + + var b = [...[...[...[...[...[5]]]]]]; +>b : number[] +>[...[...[...[...[...[5]]]]]] : number[] +>...[...[...[...[...[5]]]]] : number +>[...[...[...[...[5]]]]] : number[] +>...[...[...[...[5]]]] : number +>[...[...[...[5]]]] : number[] +>...[...[...[5]]] : number +>[...[...[5]]] : number[] +>...[...[5]] : number +>[...[5]] : number[] +>...[5] : number +>[5] : number[] +>5 : 5 +} + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.errors.txt new file mode 100644 index 0000000000..6a2647013f --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.errors.txt @@ -0,0 +1,65 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts (3 errors) ==== + /* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + + // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. + // An expression of type S is considered assignable to an assignment target V if one of the following is true + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + + var [a0, a1]: any = undefined; + var [a2 = false, a3 = 1]: any = undefined; + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2] = [2, 3, 4]; + var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + + function foo() { + return [1, 2, 3]; + } + + var [b6, b7] = foo(); + var [...b8] = foo(); + + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1,2,3] + var [c0, c1] = [...temp]; + var [c2] = []; + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. + var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. + var [[c5], c6]: [[string|number], boolean] = [[1], true]; + var [, c7] = [1, 2, 3]; + var [,,, c8] = [1, 2, 3, 4]; + var [,,, c9] = [1, 2, 3, 4]; + var [,,,...c10] = [1, 2, 3, 4, "hello"]; + var [c11, c12, ...c13] = [1, 2, "string"]; + var [c14, c15, c16] = [1, 2, "string"]; + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.js new file mode 100644 index 0000000000..c0e896dce7 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.js @@ -0,0 +1,112 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES5iterable.ts] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; + + + +//// [destructuringArrayBindingPatternAndAssignment1ES5iterable.js] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __spread = (this && this.__spread) || function () { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + return ar; +}; +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var _a = __read(undefined, 2), a0 = _a[0], a1 = _a[1]; +var _b = __read(undefined, 2), _c = _b[0], a2 = _c === void 0 ? false : _c, _d = _b[1], a3 = _d === void 0 ? 1 : _d; +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var _e = __read([2, 3, 4], 3), b0 = _e[0], b1 = _e[1], b2 = _e[2]; +var _f = __read([1, 2, "string"], 3), b3 = _f[0], b4 = _f[1], b5 = _f[2]; +function foo() { + return [1, 2, 3]; +} +var _g = __read(foo(), 2), b6 = _g[0], b7 = _g[1]; +var _h = __read(foo()), b8 = _h.slice(0); +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3]; +var _j = __read(__spread(temp), 2), c0 = _j[0], c1 = _j[1]; +var _k = __read([], 1), c2 = _k[0]; +var _l = __read([[[]], [[[[]]]]], 2), _m = __read(_l[0], 1), _o = __read(_m[0], 1), c3 = _o[0], _p = __read(_l[1], 1), _q = __read(_p[0], 1), _r = __read(_q[0], 1), _s = __read(_r[0], 1), c4 = _s[0]; +var _t = __read([[1], true], 2), _u = __read(_t[0], 1), c5 = _u[0], c6 = _t[1]; +var _v = __read([1, 2, 3], 2), c7 = _v[1]; +var _w = __read([1, 2, 3, 4], 4), c8 = _w[3]; +var _x = __read([1, 2, 3, 4], 4), c9 = _x[3]; +var _y = __read([1, 2, 3, 4, "hello"]), c10 = _y.slice(3); +var _z = __read([1, 2, "string"]), c11 = _z[0], c12 = _z[1], c13 = _z.slice(2); +var _0 = __read([1, 2, "string"], 3), c14 = _0[0], c15 = _0[1], c16 = _0[2]; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt new file mode 100644 index 0000000000..101a37fc84 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt @@ -0,0 +1,106 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(62,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(63,10): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts (2 errors) ==== + // A parameter declaration may specify either an identifier or a binding pattern. + // The identifiers specified in parameter declarations and binding patterns + // in a parameter list must be unique within that parameter list. + + // If the declaration includes a type annotation, the parameter is of that type + function a1([a, b, [[c]]]: [number, number, string[][]]) { } + function a2(o: { x: number, a: number }) { } + function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; + function a4({x, a}: { x: number, a: number }) { } + + a1([1, 2, [["world"]]]); + a1([1, 2, [["world"]], 3]); + + // If the declaration includes an initializer expression (which is permitted only + // when the parameter list occurs in conjunction with a function body), + // the parameter type is the widened form (section 3.11) of the type of the initializer expression. + + function b1(z = [undefined, null]) { }; + function b2(z = null, o = { x: 0, y: undefined }) { } + function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + + interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); + } + + function b6([a, z, y] = [undefined, null, undefined]) { } + function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + + b1([1, 2, 3]); // z is widen to the type any[] + b2("string", { x: 200, y: "string" }); + b2("string", { x: 200, y: true }); + b6(["string", 1, 2]); // Shouldn't be an error + b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + + + // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) + enum Foo { a } + function c0({z: {x, y: {j}}}) { } + function c1({z} = { z: 10 }) { } + function c2({z = 10}) { } + function c3({b}: { b: number|string} = { b: "hello" }) { } + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c=1]]]) { } + + c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } + c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + + c1(); // Implied type is {z:number}? + c1({ z: 1 }) // Implied type is {z:number}? + + c2({}); // Implied type is {z?: number} + c2({z:1}); // Implied type is {z?: number} + + c3({ b: 1 }); // Implied type is { b: number|string }. + + c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] + c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + + // A parameter can be marked optional by following its name or binding pattern with a question mark (?) + // or by including an initializer. + + function d0(x?) { } + ~~ +!!! error TS2393: Duplicate function implementation. + function d0(x = 10) { } + ~~ +!!! error TS2393: Duplicate function implementation. + + interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); + } + + class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } + } + + class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } + } + + + function d5({x, y} = { x: 1, y: 2 }) { } + d5(); // Parameter is optional as its declaration included an initializer + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e1({x: number}) { } // x has type any NOT number + function e2({x}: { x: number }) { } // x is type number + function e3({x}: { x?: number }) { } // x is an optional with type number + function e4({x: [number,string,any] }) { } // x has type [any, any, any] + function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.js b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.js new file mode 100644 index 0000000000..ca3627f374 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.js @@ -0,0 +1,234 @@ +//// [destructuringParameterDeclaration1ES5iterable.ts] +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a4({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +function d0(x?) { } +function d0(x = 10) { } + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + + +//// [destructuringParameterDeclaration1ES5iterable.js] +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +// If the declaration includes a type annotation, the parameter is of that type +function a1(_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], _c = __read(_b[2], 1), _d = __read(_c[0], 1), c = _d[0]; +} +function a2(o) { } +function a3(_a) { + var j = _a.j, k = _a.k, _b = _a.l, m = _b.m, n = _b.n, _c = __read(_a.q, 3), a = _c[0], b = _c[1], c = _c[2]; +} +; +function a4(_a) { + var x = _a.x, a = _a.a; +} +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. +function b1(z) { + if (z === void 0) { z = [undefined, null]; } +} +; +function b2(z, o) { + if (z === void 0) { z = null; } + if (o === void 0) { o = { x: 0, y: undefined }; } +} +function b3(_a) { + var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; +} +function b6(_a) { + var _b = __read(_a === void 0 ? [undefined, null, undefined] : _a, 3), a = _b[0], z = _b[1], y = _b[2]; +} +function b7(_a) { + var _b = __read(_a === void 0 ? [[undefined], undefined, [[undefined, undefined]]] : _a, 3), _c = __read(_b[0], 1), a = _c[0], b = _b[1], _d = __read(_b[2], 1), _e = __read(_d[0], 2), c = _e[0], d = _e[1]; +} +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function c0(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; +} +function c1(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; +} +function c2(_a) { + var _b = _a.z, z = _b === void 0 ? 10 : _b; +} +function c3(_a) { + var b = (_a === void 0 ? { b: "hello" } : _a).b; +} +function c5(_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], _c = __read(_b[2], 1), _d = __read(_c[0], 1), c = _d[0]; +} +function c6(_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], _c = __read(_b[2], 1), _d = __read(_c[0], 1), _e = _d[0], c = _e === void 0 ? 1 : _e; +} +c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} } +c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} } +c1(); // Implied type is {z:number}? +c1({ z: 1 }); // Implied type is {z:number}? +c2({}); // Implied type is {z?: number} +c2({ z: 1 }); // Implied type is {z?: number} +c3({ b: 1 }); // Implied type is { b: number|string }. +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. +function d0(x) { } +function d0(x) { + if (x === void 0) { x = 10; } +} +var C2 = (function () { + function C2() { + } + C2.prototype.d3 = function () { }; + C2.prototype.d4 = function () { }; + C2.prototype.e0 = function (_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], c = _b[2]; + }; + return C2; +}()); +var C3 = (function () { + function C3() { + } + C3.prototype.d3 = function (_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], c = _b[2]; + }; + C3.prototype.d4 = function (_a) { + var x = _a.x, y = _a.y, z = _a.z; + }; + C3.prototype.e0 = function (_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], c = _b[2]; + }; + return C3; +}()); +function d5(_a) { + var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y; +} +d5(); // Parameter is optional as its declaration included an initializer +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration +function e1(_a) { + var number = _a.x; +} // x has type any NOT number +function e2(_a) { + var x = _a.x; +} // x is type number +function e3(_a) { + var x = _a.x; +} // x is an optional with type number +function e4(_a) { + var _b = __read(_a.x, 3), number = _b[0], string = _b[1], any = _b[2]; +} // x has type [any, any, any] +function e5(_a) { + var _b = __read(_a.x, 3), a = _b[0], b = _b[1], c = _b[2]; +} // x has type [any, any, any] diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.js b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.js new file mode 100644 index 0000000000..339913732b --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.js @@ -0,0 +1,133 @@ +//// [destructuringParameterDeclaration3ES5iterable.ts] + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + + + +//// [destructuringParameterDeclaration3ES5iterable.js] +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __spread = (this && this.__spread) || function () { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + return ar; +}; +function a1() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i] = arguments[_i]; + } +} +function a2() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +function a3() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +function a4() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +function a5() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +function a9(_a) { + var _b = __read(_a, 3), a = _b[0], b = _b[1], _c = __read(_b[2], 1), _d = __read(_c[0], 1), c = _d[0]; +} +function a10(_a) { + var _b = __read(_a), a = _b[0], b = _b[1], _c = __read(_b[2], 1), _d = __read(_c[0], 1), c = _d[0], x = _b.slice(3); +} +function a11(_a) { + var _b = __read(_a), a = _b[0], b = _b[1], c = _b[2], x = _b.slice(3); +} +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2(__spread(array)); +a1.apply(void 0, __spread(array)); +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] +// Rest parameter with generic +function foo() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +foo("hello", 1, 2); +foo("hello", "world"); +var E; +(function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; +})(E || (E = {})); +function foo1() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i] = arguments[_i]; + } +} +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, 0 /* a */, E.b); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.symbols new file mode 100644 index 0000000000..52b2d290fa --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5iterable.ts, 0, 0)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type someArray = Array | number[]; +>someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES5iterable.ts, 7, 32)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type stringOrNumArray = Array; +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5iterable.ts, 8, 42)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Number : Symbol(Number, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +function a1(...x: (number|string)[]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 9, 45)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5iterable.ts, 11, 12)) + +function a2(...a) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5iterable.ts, 11, 40)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 12, 12)) + +function a3(...a: Array) { } +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES5iterable.ts, 12, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 13, 12)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +function a4(...a: arrayString) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES5iterable.ts, 13, 36)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 14, 12)) +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5iterable.ts, 0, 0)) + +function a5(...a: stringOrNumArray) { } +>a5 : Symbol(a5, Decl(destructuringParameterDeclaration3ES5iterable.ts, 14, 34)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 15, 12)) +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5iterable.ts, 8, 42)) + +function a9([a, b, [[c]]]) { } +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5iterable.ts, 15, 39)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 21)) + +function a10([a, b, [[c]], ...x]) { } +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 26)) + +function a11([a, b, c, ...x]: number[]) { } +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 37)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 18, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 18, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5iterable.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5iterable.ts, 18, 22)) + + +var array = [1, 2, 3]; +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5iterable.ts, 21, 3)) + +var array2 = [true, false, "hello"]; +>array2 : Symbol(array2, Decl(destructuringParameterDeclaration3ES5iterable.ts, 22, 3)) + +a2([...array]); +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5iterable.ts, 11, 40)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5iterable.ts, 21, 3)) + +a1(...array); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 9, 45)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5iterable.ts, 21, 3)) + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5iterable.ts, 15, 39)) + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 30)) + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 30)) + +a10([1, 2]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5iterable.ts, 16, 30)) + +a11([1, 2]); // Parameter type is number[] +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5iterable.ts, 17, 37)) + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5iterable.ts, 31, 12)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5iterable.ts, 34, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 34, 16)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5iterable.ts, 34, 13)) + +foo("hello", 1, 2); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5iterable.ts, 31, 12)) + +foo("hello", "world"); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5iterable.ts, 31, 12)) + +enum E { a, b } +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5iterable.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 8)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 11)) + +const enum E1 { a, b } +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 15)) +>b : Symbol(E1.b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 18)) + +function foo1(...a: T[]) { } +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 22)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5iterable.ts, 40, 14)) +>Number : Symbol(Number, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 40, 32)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5iterable.ts, 40, 14)) + +foo1(1, 2, 3, E.a); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 22)) +>E.a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 8)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5iterable.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 8)) + +foo1(1, 2, 3, E1.a, E.b); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 22)) +>E1.a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 15)) +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5iterable.ts, 39, 15)) +>E.b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 11)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5iterable.ts, 36, 22)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5iterable.ts, 38, 11)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types new file mode 100644 index 0000000000..d003531c67 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types @@ -0,0 +1,206 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : String[] +>Array : T[] +>String : String + +type someArray = Array | number[]; +>someArray : someArray +>Array : T[] +>String : String + +type stringOrNumArray = Array; +>stringOrNumArray : (String | Number)[] +>Array : T[] +>String : String +>Number : Number + +function a1(...x: (number|string)[]) { } +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] + +function a2(...a) { } +>a2 : (...a: any[]) => void +>a : any[] + +function a3(...a: Array) { } +>a3 : (...a: String[]) => void +>a : String[] +>Array : T[] +>String : String + +function a4(...a: arrayString) { } +>a4 : (...a: String[]) => void +>a : String[] +>arrayString : String[] + +function a5(...a: stringOrNumArray) { } +>a5 : (...a: (String | Number)[]) => void +>a : (String | Number)[] +>stringOrNumArray : (String | Number)[] + +function a9([a, b, [[c]]]) { } +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>a : any +>b : any +>c : any + +function a10([a, b, [[c]], ...x]) { } +>a10 : ([a, b, [[c]], ...x]: any[]) => void +>a : any +>b : any +>c : any +>x : any[] + +function a11([a, b, c, ...x]: number[]) { } +>a11 : ([a, b, c, ...x]: number[]) => void +>a : number +>b : number +>c : number +>x : number[] + + +var array = [1, 2, 3]; +>array : number[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + +var array2 = [true, false, "hello"]; +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] +>true : true +>false : false +>"hello" : "hello" + +a2([...array]); +>a2([...array]) : void +>a2 : (...a: any[]) => void +>[...array] : number[] +>...array : number +>array : number[] + +a1(...array); +>a1(...array) : void +>a1 : (...x: (string | number)[]) => void +>...array : number +>array : number[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9([1, 2, [["string"]], false, true]) : void +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : 1 +>2 : 2 +>[["string"]] : [[string]] +>["string"] : [string] +>"string" : "string" +>false : false +>true : true + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10([1, 2, [["string"]], false, true]) : void +>a10 : ([a, b, [[c]], ...x]: any[]) => void +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>1 : 1 +>2 : 2 +>[["string"]] : string[][] +>["string"] : string[] +>"string" : "string" +>false : false +>true : true + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10([1, 2, 3, false, true]) : void +>a10 : ([a, b, [[c]], ...x]: any[]) => void +>[1, 2, 3, false, true] : (number | boolean)[] +>1 : 1 +>2 : 2 +>3 : 3 +>false : false +>true : true + +a10([1, 2]); // Parameter type is any[] +>a10([1, 2]) : void +>a10 : ([a, b, [[c]], ...x]: any[]) => void +>[1, 2] : number[] +>1 : 1 +>2 : 2 + +a11([1, 2]); // Parameter type is number[] +>a11([1, 2]) : void +>a11 : ([a, b, c, ...x]: number[]) => void +>[1, 2] : number[] +>1 : 1 +>2 : 2 + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : (...a: T[]) => void +>T : T +>a : T[] +>T : T + +foo("hello", 1, 2); +>foo("hello", 1, 2) : void +>foo : (...a: T[]) => void +>"hello" : "hello" +>1 : 1 +>2 : 2 + +foo("hello", "world"); +>foo("hello", "world") : void +>foo : (...a: T[]) => void +>"hello" : "hello" +>"world" : "world" + +enum E { a, b } +>E : E +>a : E.a +>b : E.b + +const enum E1 { a, b } +>E1 : E1 +>a : E1.a +>b : E1.b + +function foo1(...a: T[]) { } +>foo1 : (...a: T[]) => void +>T : T +>Number : Number +>a : T[] +>T : T + +foo1(1, 2, 3, E.a); +>foo1(1, 2, 3, E.a) : void +>foo1 : (...a: T[]) => void +>1 : 1 +>2 : 2 +>3 : 3 +>E.a : E.a +>E : typeof E +>a : E.a + +foo1(1, 2, 3, E1.a, E.b); +>foo1(1, 2, 3, E1.a, E.b) : void +>foo1 : (...a: T[]) => void +>1 : 1 +>2 : 2 +>3 : 3 +>E1.a : E1.a +>E1 : typeof E1 +>a : E1.a +>E.b : E.b +>E : typeof E +>b : E.b + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.js b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.js new file mode 100644 index 0000000000..c6b3742bc6 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.js @@ -0,0 +1,35 @@ +//// [destructuringParameterDeclaration7ES5iterable.ts] + +interface ISomething { + foo: string, + bar: string +} + +function foo({}, {foo, bar}: ISomething) {} + +function baz([], {foo, bar}: ISomething) {} + +function one([], {}) {} + +function two([], [a, b, c]: number[]) {} + + +//// [destructuringParameterDeclaration7ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +function foo(_a, _b) { + var foo = _b.foo, bar = _b.bar; +} +function baz(_a, _b) { + var foo = _b.foo, bar = _b.bar; +} +function one(_a, _b) { } +function two(_a, _b) { + var _c = __read(_b, 3), a = _c[0], b = _c[1], c = _c[2]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.symbols b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.symbols new file mode 100644 index 0000000000..0548f1247f --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts === + +interface ISomething { +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5iterable.ts, 0, 0)) + + foo: string, +>foo : Symbol(ISomething.foo, Decl(destructuringParameterDeclaration7ES5iterable.ts, 1, 22)) + + bar: string +>bar : Symbol(ISomething.bar, Decl(destructuringParameterDeclaration7ES5iterable.ts, 2, 16)) +} + +function foo({}, {foo, bar}: ISomething) {} +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5iterable.ts, 4, 1)) +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5iterable.ts, 6, 18)) +>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5iterable.ts, 6, 22)) +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5iterable.ts, 0, 0)) + +function baz([], {foo, bar}: ISomething) {} +>baz : Symbol(baz, Decl(destructuringParameterDeclaration7ES5iterable.ts, 6, 43)) +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5iterable.ts, 8, 18)) +>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5iterable.ts, 8, 22)) +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5iterable.ts, 0, 0)) + +function one([], {}) {} +>one : Symbol(one, Decl(destructuringParameterDeclaration7ES5iterable.ts, 8, 43)) + +function two([], [a, b, c]: number[]) {} +>two : Symbol(two, Decl(destructuringParameterDeclaration7ES5iterable.ts, 10, 23)) +>a : Symbol(a, Decl(destructuringParameterDeclaration7ES5iterable.ts, 12, 18)) +>b : Symbol(b, Decl(destructuringParameterDeclaration7ES5iterable.ts, 12, 20)) +>c : Symbol(c, Decl(destructuringParameterDeclaration7ES5iterable.ts, 12, 23)) + diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.types new file mode 100644 index 0000000000..402ea7ac5e --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5iterable.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts === + +interface ISomething { +>ISomething : ISomething + + foo: string, +>foo : string + + bar: string +>bar : string +} + +function foo({}, {foo, bar}: ISomething) {} +>foo : ({}: {}, {foo, bar}: ISomething) => void +>foo : string +>bar : string +>ISomething : ISomething + +function baz([], {foo, bar}: ISomething) {} +>baz : ([]: any[], {foo, bar}: ISomething) => void +>foo : string +>bar : string +>ISomething : ISomething + +function one([], {}) {} +>one : ([]: any[], {}: {}) => void + +function two([], [a, b, c]: number[]) {} +>two : ([]: any[], [a, b, c]: number[]) => void +>a : number +>b : number +>c : number + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.js new file mode 100644 index 0000000000..7990a12b1f --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.js @@ -0,0 +1,89 @@ +//// [destructuringVariableDeclaration1ES5iterable.ts] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + + + +//// [destructuringVariableDeclaration1ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __spread = (this && this.__spread) || function () { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + return ar; +}; +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2; +var _b = __read([1, [["hello"]], true], 3), a3 = _b[0], _c = __read(_b[1], 1), _d = __read(_c[0], 1), a4 = _d[0], a5 = _b[2]; +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var _e = { b1: { b11: "world" } }.b1, b11 = (_e === void 0 ? { b11: "string" } : _e).b11; +var temp = { t1: true, t2: "false" }; +var _f = __read([3, false, { t1: false, t2: "hello" }], 3), _g = _f[0], b2 = _g === void 0 ? 3 : _g, _h = _f[1], b3 = _h === void 0 ? true : _h, _j = _f[2], b4 = _j === void 0 ? temp : _j; +var _k = __read([undefined, undefined, undefined], 3), _l = _k[0], b5 = _l === void 0 ? 3 : _l, _m = _k[1], b6 = _m === void 0 ? true : _m, _o = _k[2], b7 = _o === void 0 ? temp : _o; +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var _p = __read([1, 2, 3]), c1 = _p.slice(0); +var _q = __read([1, 2, 3, "string"]), c2 = _q.slice(0); +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var _r = __read([1, "string"], 2), d1 = _r[0], d2 = _r[1]; +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true]; +var _s = __read(__spread([1, "string"], temp1), 2), d3 = _s[0], d4 = _s[1]; +// Combining both forms of destructuring, +var _t = __read({ e: [1, 2, { b1: 4, b4: 0 }] }.e, 3), e1 = _t[0], e2 = _t[1], _u = _t[2], e3 = _u === void 0 ? { b1: 1000, b4: 200 } : _u; +var _v = __read({ f: [1, 2, { f3: 4, f5: 0 }] }.f, 4), f1 = _v[0], f2 = _v[1], _w = _v[2], f4 = _w.f3, f5 = _w.f5; +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var _x = { g: { g1: [1, 2] } }.g.g1, g1 = _x === void 0 ? [undefined, null] : _x; +var _y = { h: { h1: [1, 2] } }.h.h1, h1 = _y === void 0 ? [undefined, null] : _y; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.symbols new file mode 100644 index 0000000000..b0ed4280cb --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES5iterable.ts, 3, 16)) + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5iterable.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5iterable.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5iterable.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5iterable.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5iterable.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES5iterable.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES5iterable.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES5iterable.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5iterable.ts, 8, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : Symbol(c1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 16, 5)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : Symbol(d1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 22, 8)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 28, 8)) +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 49)) +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 41)) +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 12)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 53)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5iterable.ts, 32, 60)) + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5iterable.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types new file mode 100644 index 0000000000..6ef4c3d574 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5iterable.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : number +>a2 : string +>a1 : number +>a2 : string +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number +>10 : 10 +>a2 : string +>"world" : "world" + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number +>a4 : string +>a5 : boolean +>[1, [["hello"]], true] : [number, [[string]], true] +>1 : 1 +>[["hello"]] : [[string]] +>["hello"] : [string] +>"hello" : "hello" +>true : true + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : any +>b11 : string +>{ b11: "string" } : { b11: string; } +>b11 : string +>"string" : "string" +>{ b1: { b11: "world" } } : { b1?: { b11: string; }; } +>b1 : { b11: string; } +>{ b11: "world" } : { b11: string; } +>b11 : string +>"world" : "world" + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; } +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean +>true : true +>t2 : string +>"false" : "false" + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number +>3 : 3 +>b3 : boolean +>true : true +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } +>[3, false, { t1: false, t2: "hello" }] : [number, false, { t1: false; t2: string; }] +>3 : 3 +>false : false +>{ t1: false, t2: "hello" } : { t1: false; t2: string; } +>t1 : boolean +>false : false +>t2 : string +>"hello" : "hello" + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : 3 +>3 : 3 +>b6 : true +>true : true +>b7 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined +>undefined : undefined +>undefined : undefined + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : number[] +>[1,2,3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[] +>[1,2,3, "string"] : (string | number)[] +>1 : 1 +>2 : 2 +>3 : 3 +>"string" : "string" + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : number +>d2 : string +>[1,"string"] : [number, string] +>1 : 1 +>"string" : "string" + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : boolean[] +>[true, false, true] : boolean[] +>true : true +>false : false +>true : true + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean +>d4 : string | number | boolean +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : 1 +>"string" : "string" +>...temp1 : boolean +>temp1 : boolean[] + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : any +>e1 : number +>e2 : number +>e3 : { b1: number; b4: number; } +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number +>1000 : 1000 +>b4 : number +>200 : 200 +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }] +>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] +>1 : 1 +>2 : 2 +>{ b1: 4, b4: 0 } : { b1: number; b4: number; } +>b1 : number +>4 : 4 +>b4 : number +>0 : 0 + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number +>f2 : number +>f3 : any +>f4 : number +>f5 : number +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, any]; } +>f : [number, number, { f3: number; f5: number; }, any] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, any] +>1 : 1 +>2 : 2 +>{ f3: 4, f5: 0 } : { f3: number; f5: number; } +>f3 : number +>4 : 4 +>f5 : number +>0 : 0 + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : any +>g1 : any[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>g : { g1: any[]; } +>g1 : any[] +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; } +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[] +>[1, 2] : number[] +>1 : 1 +>2 : 2 + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>h : { h1: number[]; } +>h1 : number[] +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; } +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[] +>[1, 2] : number[] +>1 : 1 +>2 : 2 + + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.js new file mode 100644 index 0000000000..7123841025 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.js @@ -0,0 +1,15 @@ +//// [emptyAssignmentPatterns01_ES5iterable.ts] + +var a: any; + +({} = a); +([] = a); + +//// [emptyAssignmentPatterns01_ES5iterable.js] +var a; +(a); +(a); + + +//// [emptyAssignmentPatterns01_ES5iterable.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.symbols b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.symbols new file mode 100644 index 0000000000..8811c61dd9 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5iterable.ts, 1, 3)) + +({} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5iterable.ts, 1, 3)) + +([] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5iterable.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.types b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.types new file mode 100644 index 0000000000..4a5e17d7cd --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5iterable.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts === + +var a: any; +>a : any + +({} = a); +>({} = a) : any +>{} = a : any +>{} : {} +>a : any + +([] = a); +>([] = a) : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.js new file mode 100644 index 0000000000..0c6a12c45c --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.js @@ -0,0 +1,27 @@ +//// [emptyAssignmentPatterns02_ES5iterable.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); + +//// [emptyAssignmentPatterns02_ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var a; +var x, y, z, a1, a2, a3; +(x = a.x, y = a.y, z = a.z); +(_a = __read(a, 3), a1 = _a[0], a2 = _a[1], a3 = _a[2]); +var _a; + + +//// [emptyAssignmentPatterns02_ES5iterable.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.symbols b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.symbols new file mode 100644 index 0000000000..fc90df74d1 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 20)) + +({} = { x, y, z } = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 4, 7)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 4, 10)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 4, 13)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 1, 3)) + +([] = [ a1, a2, a3] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5iterable.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.types b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.types new file mode 100644 index 0000000000..5f19cd98ec --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5iterable.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({} = { x, y, z } = a); +>({} = { x, y, z } = a) : any +>{} = { x, y, z } = a : any +>{} : {} +>{ x, y, z } = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>a : any + +([] = [ a1, a2, a3] = a); +>([] = [ a1, a2, a3] = a) : any +>[] = [ a1, a2, a3] = a : any +>[] : undefined[] +>[ a1, a2, a3] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.js new file mode 100644 index 0000000000..79806e5994 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.js @@ -0,0 +1,15 @@ +//// [emptyAssignmentPatterns03_ES5iterable.ts] + +var a: any; + +({} = {} = a); +([] = [] = a); + +//// [emptyAssignmentPatterns03_ES5iterable.js] +var a; +(a); +(a); + + +//// [emptyAssignmentPatterns03_ES5iterable.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.symbols b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.symbols new file mode 100644 index 0000000000..e1ac0ea4c5 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5iterable.ts, 1, 3)) + +({} = {} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5iterable.ts, 1, 3)) + +([] = [] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5iterable.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.types b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.types new file mode 100644 index 0000000000..273d360d92 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5iterable.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts === + +var a: any; +>a : any + +({} = {} = a); +>({} = {} = a) : any +>{} = {} = a : any +>{} : {} +>{} = a : any +>{} : {} +>a : any + +([] = [] = a); +>([] = [] = a) : any +>[] = [] = a : any +>[] : undefined[] +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.js new file mode 100644 index 0000000000..656bc1d4c4 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.js @@ -0,0 +1,27 @@ +//// [emptyAssignmentPatterns04_ES5iterable.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); + +//// [emptyAssignmentPatterns04_ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var a; +var x, y, z, a1, a2, a3; +(x = a.x, y = a.y, z = a.z); +(_a = __read(a, 3), a1 = _a[0], a2 = _a[1], a3 = _a[2]); +var _a; + + +//// [emptyAssignmentPatterns04_ES5iterable.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.symbols b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.symbols new file mode 100644 index 0000000000..d433a0f125 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 20)) + +({ x, y, z } = {} = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 4, 2)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 4, 5)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 4, 8)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 1, 3)) + +([ a1, a2, a3] = [] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5iterable.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.types b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.types new file mode 100644 index 0000000000..c926ec31bf --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5iterable.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({ x, y, z } = {} = a); +>({ x, y, z } = {} = a) : any +>{ x, y, z } = {} = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>{} = a : any +>{} : {} +>a : any + +([ a1, a2, a3] = [] = a); +>([ a1, a2, a3] = [] = a) : any +>[ a1, a2, a3] = [] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.js new file mode 100644 index 0000000000..e93d30e351 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.js @@ -0,0 +1,149 @@ +//// [emptyVariableDeclarationBindingPatterns01_ES5iterable.ts] + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } +})(); + +//// [emptyVariableDeclarationBindingPatterns01_ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +var __values = (this && this.__values) || function (o) { return (i = typeof Symbol === "function" && o[Symbol.iterator] || 0) ? i.call(o) : { next: function () { return { done: d = d || i >= o.length, value: d ? void 0 : o[i++] }; } }; var i, d; }; +var __step = (this && this.__step) || function (r) { return !(r.done || (r.done = (r.result = r.iterator.next()).done)); }; +var __close = (this && this.__close) || function (r) { return (m = !(r && r.done) && r.iterator["return"]) && m.call(r.iterator); var m; }; +(function () { + var a; + var _a = a; + var _b = a; + var _c = a; + var _d = __read(a, 0); + var _e = __read(a, 0); + var _f = __read(a, 0); + var _g = a, _h = __read(a, 0); + var _j = a, _k = __read(a, 0); + var _l = a, _m = __read(a, 0); + var _o = a.p1, _p = __read(a.p2, 0); + var _q = a.p1, _r = __read(a.p2, 0); + var _s = a.p1, _t = __read(a.p2, 0); + for (var _u = {}, _v = {}; false; void 0) { + } + function f(_a, _b, _c) { + _a = a; + _b = a; + var _d = (_c === void 0 ? a : _c).p, _e = _d === void 0 ? a : _d; + return function (_a, _b, _c) { + _a = a; + _b = a; + var _d = (_c === void 0 ? a : _c).p, _e = _d === void 0 ? a : _d; + return a; + }; + } +})(); +(function () { + var ns = []; + try { + for (var ns_1 = { iterator: __values(ns) }; __step(ns_1);) { + var _a = ns_1.result.value; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { __close(ns_1); } finally { if (e_1) throw e_1.error; } + } + try { + for (var ns_2 = { iterator: __values(ns) }; __step(ns_2);) { + var _b = ns_2.result.value; + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { __close(ns_2); } finally { if (e_2) throw e_2.error; } + } + try { + for (var ns_3 = { iterator: __values(ns) }; __step(ns_3);) { + var _c = ns_3.result.value; + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { __close(ns_3); } finally { if (e_3) throw e_3.error; } + } + try { + for (var ns_4 = { iterator: __values(ns) }; __step(ns_4);) { + var _d = __read(ns_4.result.value, 0); + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { __close(ns_4); } finally { if (e_4) throw e_4.error; } + } + try { + for (var ns_5 = { iterator: __values(ns) }; __step(ns_5);) { + var _e = __read(ns_5.result.value, 0); + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { __close(ns_5); } finally { if (e_5) throw e_5.error; } + } + try { + for (var ns_6 = { iterator: __values(ns) }; __step(ns_6);) { + var _f = __read(ns_6.result.value, 0); + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { __close(ns_6); } finally { if (e_6) throw e_6.error; } + } + var e_1, e_2, e_3, e_4, e_5, e_6; +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.symbols new file mode 100644 index 0000000000..d77525cf76 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.symbols @@ -0,0 +1,92 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts === + +(function () { + var a: any; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + var {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + let {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + const {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + var [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + let [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + const [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + var {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + let {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + const {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + var { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + let { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + const { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + for (var {} = {}, {} = {}; false; void 0) { + } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : Symbol(f, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 21, 5)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 2, 7)) + } +})(); + +(function () { + const ns: number[][] = []; +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + + for (var {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } + + for (let {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } + + for (const {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } + + for (var [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } + + for (let [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } + + for (const [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5iterable.ts, 29, 9)) + } +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.types new file mode 100644 index 0000000000..591b149ac0 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5iterable.types @@ -0,0 +1,115 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts === + +(function () { +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }} : () => void + + var a: any; +>a : any + + var {} = a; +>a : any + + let {} = a; +>a : any + + const {} = a; +>a : any + + var [] = a; +>a : any + + let [] = a; +>a : any + + const [] = a; +>a : any + + var {} = a, [] = a; +>a : any +>a : any + + let {} = a, [] = a; +>a : any +>a : any + + const {} = a, [] = a; +>a : any +>a : any + + var { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + let { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + const { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + for (var {} = {}, {} = {}; false; void 0) { +>{} : {} +>{} : {} +>false : false +>void 0 : undefined +>0 : 0 + } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : ({}?: any, []?: any, {p: {}}?: any) => ({}?: any, []?: any, {p: {}}?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, {p: {}}?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any +>a : any + } +})(); + +(function () { +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }})() : void +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }}) : () => void +>function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }} : () => void + + const ns: number[][] = []; +>ns : number[][] +>[] : undefined[] + + for (var {} of ns) { +>ns : number[][] + } + + for (let {} of ns) { +>ns : number[][] + } + + for (const {} of ns) { +>ns : number[][] + } + + for (var [] of ns) { +>ns : number[][] + } + + for (let [] of ns) { +>ns : number[][] + } + + for (const [] of ns) { +>ns : number[][] + } +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.errors.txt b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.errors.txt new file mode 100644 index 0000000000..453f44be10 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(3,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(4,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(5,11): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(7,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(8,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts(9,11): error TS1182: A destructuring declaration must have an initializer. + + +==== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts (6 errors) ==== + + (function () { + var {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + + var []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + })(); \ No newline at end of file diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.js new file mode 100644 index 0000000000..e61e8b877d --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5iterable.js @@ -0,0 +1,32 @@ +//// [emptyVariableDeclarationBindingPatterns02_ES5iterable.ts] + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); + +//// [emptyVariableDeclarationBindingPatterns02_ES5iterable.js] +var __read = (this && this.__read) || function (o, n) { + if (!(m = typeof Symbol === "function" && o[Symbol.iterator])) return o; + var m, i = m.call(o), ar = [], r, e; + try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } + catch (error) { e = { error: error }; } + finally { try { if (m = !(r && r.done) && i["return"]) m.call(i); } finally { if (e) throw e.error; } } + return ar; +}; +(function () { + var _a = void 0; + var _b = void 0; + var _c = void 0; + var _d = __read(void 0, 0); + var _e = __read(void 0, 0); + var _f = __read(void 0, 0); +})(); + + +//// [emptyVariableDeclarationBindingPatterns02_ES5iterable.d.ts] diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts new file mode 100644 index 0000000000..eac4a0bf66 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5iterable.ts @@ -0,0 +1,53 @@ +// @iterationMode: iterable +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts new file mode 100644 index 0000000000..381dd47d3e --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts @@ -0,0 +1,97 @@ +// @iterationMode: iterable +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a4({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +function d0(x?) { } +function d0(x = 10) { } + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts new file mode 100644 index 0000000000..e919526a45 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts @@ -0,0 +1,47 @@ +// @target: es5 +// @iterationMode: iterable + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts new file mode 100644 index 0000000000..cbef9355d6 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5iterable.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @iterationMode: iterable + +interface ISomething { + foo: string, + bar: string +} + +function foo({}, {foo, bar}: ISomething) {} + +function baz([], {foo, bar}: ISomething) {} + +function one([], {}) {} + +function two([], [a, b, c]: number[]) {} diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts new file mode 100644 index 0000000000..6d71f96087 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5iterable.ts @@ -0,0 +1,41 @@ +// @iterationMode: iterable +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts new file mode 100644 index 0000000000..26b8e52821 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5iterable.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @declaration: true +// @iterationMode: iterable + +var a: any; + +({} = a); +([] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts new file mode 100644 index 0000000000..6e08bd7b15 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5iterable.ts @@ -0,0 +1,9 @@ +// @target: es5 +// @declaration: true +// @iterationMode: iterable + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts new file mode 100644 index 0000000000..799208853f --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5iterable.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @declaration: true +// @iterationMode: iterable + +var a: any; + +({} = {} = a); +([] = [] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts new file mode 100644 index 0000000000..c9a5e0765c --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5iterable.ts @@ -0,0 +1,9 @@ +// @target: es5 +// @declaration: true +// @iterationMode: iterable + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts new file mode 100644 index 0000000000..8a85c91746 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5iterable.ts @@ -0,0 +1,51 @@ +// @target: es5 +// @iterationMode: iterable + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } +})(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts new file mode 100644 index 0000000000..bd991072ae --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5iterable.ts @@ -0,0 +1,13 @@ +// @target: es5 +// @declaration: true +// @iterationMode: iterable + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts b/tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts new file mode 100644 index 0000000000..eb1566ad1d --- /dev/null +++ b/tests/cases/conformance/es6/spread/arrayLiteralSpreadES5iterable.ts @@ -0,0 +1,23 @@ +// @iterationMode: iterable +function f0() { + var a = [1, 2, 3]; + var a1 = [...a]; + var a2 = [1, ...a]; + var a3 = [1, 2, ...a]; + var a4 = [...a, 1]; + var a5 = [...a, 1, 2]; + var a6 = [1, 2, ...a, 1, 2]; + var a7 = [1, ...a, 2, ...a]; + var a8 = [...a, ...a, ...a]; +} + +function f1() { + var a = [1, 2, 3]; + var b = ["hello", ...a, true]; + var b: (string | number | boolean)[]; +} + +function f2() { + var a = [...[...[...[...[...[]]]]]]; + var b = [...[...[...[...[...[5]]]]]]; +} diff --git a/tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts b/tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts new file mode 100644 index 0000000000..33116b0ec6 --- /dev/null +++ b/tests/cases/conformance/statements/for-ofStatements/ES5For-of33.ts @@ -0,0 +1,5 @@ +//@sourcemap: true +//@iterationMode: iterable +for (var v of ['a', 'b', 'c']) { + console.log(v); +} \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts b/tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts new file mode 100644 index 0000000000..17aad2319f --- /dev/null +++ b/tests/cases/conformance/statements/for-ofStatements/ES5For-of34.ts @@ -0,0 +1,8 @@ +//@sourcemap: true +//@iterationMode: iterable +function foo() { + return { x: 0 }; +} +for (foo().x of ['a', 'b', 'c']) { + var p = foo().x; +} \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts b/tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts new file mode 100644 index 0000000000..d314386119 --- /dev/null +++ b/tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts @@ -0,0 +1,6 @@ +//@sourcemap: true +//@iterationMode: iterable +for (const {x: a = 0, y: b = 1} of [2, 3]) { + a; + b; +} \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts b/tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts new file mode 100644 index 0000000000..0a09632b0e --- /dev/null +++ b/tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts @@ -0,0 +1,6 @@ +//@sourcemap: true +//@iterationMode: iterable +for (let [a = 0, b = 1] of [2, 3]) { + a; + b; +} \ No newline at end of file