From 1d793f4c5e9ab398854ca168b7921b0940c281da Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 23:44:14 -0700 Subject: [PATCH 1/3] Destructuring assignment and variable declaration --- ...turingArrayBindingPatternAndAssignment1.js | 41 ++++++ ...ingArrayBindingPatternAndAssignment1.types | 133 ++++++++++++++++++ ...turingArrayBindingPatternAndAssignment2.js | 25 ++++ ...ingArrayBindingPatternAndAssignment2.types | 41 ++++++ ...rayBindingPatternAndAssignment3.errors.txt | 51 +++++++ ...turingArrayBindingPatternAndAssignment3.js | 41 ++++++ ...uringObjectBindingPatternAndAssignment1.js | 27 ++++ ...ngObjectBindingPatternAndAssignment1.types | 87 ++++++++++++ ...uringObjectBindingPatternAndAssignment2.js | 76 ++++++++++ ...ngObjectBindingPatternAndAssignment2.types | 116 +++++++++++++++ ...ectBindingPatternAndAssignment3.errors.txt | 42 ++++++ ...uringObjectBindingPatternAndAssignment3.js | 23 +++ ...ectBindingPatternAndAssignment4.errors.txt | 37 +++++ ...uringObjectBindingPatternAndAssignment4.js | 37 +++++ ...ariableDeclarationAndAssignment.errors.txt | 15 ++ ...cturingVariableDeclarationAndAssignment.js | 9 ++ ...turingArrayBindingPatternAndAssignment1.ts | 22 +++ ...turingArrayBindingPatternAndAssignment2.ts | 13 ++ ...turingArrayBindingPatternAndAssignment3.ts | 23 +++ ...uringObjectBindingPatternAndAssignment1.ts | 12 ++ ...uringObjectBindingPatternAndAssignment2.ts | 46 ++++++ ...uringObjectBindingPatternAndAssignment3.ts | 10 ++ ...uringObjectBindingPatternAndAssignment4.ts | 23 +++ ...cturingVariableDeclarationAndAssignment.ts | 3 + 24 files changed, 953 insertions(+) create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js create mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt create mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js new file mode 100644 index 0000000000..f6c84b011d --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js @@ -0,0 +1,41 @@ +//// [destructuringArrayBindingPatternAndAssignment1.ts] +var [p0,p1, p2] : any = [2, 3, 4]; +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +var [d, e]: any = undefined; +var [f = false, g = 1]: any = undefined; +g = 10; +f = true; + +var [x] = [] +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +var [[w], m]: [[string|number], boolean] = [[1], true]; +interface J extends Array { + 2: number; +} + +var [, w1] = [1, 2, 3]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,,...w3] = [1, 2, 3, 4, "hello"]; + +var [r, s, ...t] = [1, 2, "string"]; +var [r1, s1, t1] = [1, 2, "string"]; + + + +//// [destructuringArrayBindingPatternAndAssignment1.js] +var _a = [2, 3, 4], p0 = _a[0], p1 = _a[1], p2 = _a[2]; +var _b = [1, 2, "string"], a = _b[0], b = _b[1], c = _b[2]; +var d = undefined[0], e = undefined[1]; +var _c = undefined[0], f = _c === void 0 ? false : _c, _d = undefined[1], g = _d === void 0 ? 1 : _d; +g = 10; +f = true; +var x = ([])[0]; +var _e = [[[]], [[[[]]]]], y = _e[0][0][0], z = _e[1][0][0][0][0]; +var _f = [[1], true], w = _f[0][0], m = _f[1]; +var _g = [1, 2, 3], w1 = _g[1]; +var _h = [1, 2, 3, 4], w2 = _h[3]; +var _j = [1, 2, 3, 4], w2 = _j[3]; +var _k = [1, 2, 3, 4, "hello"], w3 = _k.slice(3); +var _l = [1, 2, "string"], r = _l[0], s = _l[1], t = _l.slice(2); +var _m = [1, 2, "string"], r1 = _m[0], s1 = _m[1], t1 = _m[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types new file mode 100644 index 0000000000..f4abb8953f --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts === +var [p0,p1, p2] : any = [2, 3, 4]; +>p0 : any, Symbol(p0, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 5)) +>p1 : any, Symbol(p1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 8)) +>p2 : any, Symbol(p2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 11)) +>[2, 3, 4] : number[] +>2 : number +>3 : number +>4 : number + +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +>a : number, Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 5)) +>b : number, Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 7)) +>c : string, Symbol(c, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 10)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +var [d, e]: any = undefined; +>d : any, Symbol(d, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 5)) +>e : any, Symbol(e, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 7)) +>undefined : undefined, Symbol(undefined) + +var [f = false, g = 1]: any = undefined; +>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) +>false : boolean +>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) +>1 : number +>undefined : undefined, Symbol(undefined) + +g = 10; +>g = 10 : number +>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) +>10 : number + +f = true; +>f = true : boolean +>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) +>true : boolean + +var [x] = [] +>x : any, Symbol(x, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 7, 5)) +>[] : undefined[] + +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +>y : any, Symbol(y, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 7)) +>z : any, Symbol(z, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 16)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[w], m]: [[string|number], boolean] = [[1], true]; +>w : string | number, Symbol(w, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 6)) +>m : boolean, Symbol(m, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 9)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +interface J extends Array { +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 55)) +>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + + 2: number; +} + +var [, w1] = [1, 2, 3]; +> : undefined +>w1 : number, Symbol(w1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 14, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, w2] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, w2] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...w3] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>w3 : (string | number)[], Symbol(w3, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 17, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [r, s, ...t] = [1, 2, "string"]; +>r : string | number, Symbol(r, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 5)) +>s : string | number, Symbol(s, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 7)) +>t : (string | number)[], Symbol(t, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 10)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [r1, s1, t1] = [1, 2, "string"]; +>r1 : number, Symbol(r1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 5)) +>s1 : number, Symbol(s1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 8)) +>t1 : string, Symbol(t1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js new file mode 100644 index 0000000000..67cfaef96d --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -0,0 +1,25 @@ +//// [destructuringArrayBindingPatternAndAssignment2.ts] +function foo() { + return [1, 2, 3]; +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +var [j, k] = foo(); +var [...p] = foo(); + + +//// [destructuringArrayBindingPatternAndAssignment2.js] +function foo() { + return [1, 2, 3]; +} +function bar() { + return [1, 2, 3]; +} +var _a = foo(), j = _a[0], k = _a[1]; +var _b = foo(), p = _b.slice(0); diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types new file mode 100644 index 0000000000..f6b40e5fc9 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts === +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} +interface J extends Array { +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) +>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + + 2: number; +} + +function bar(): J { +>bar : () => J, Symbol(bar, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 5, 1)) +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) + + return <[number, number, number]>[1, 2, 3]; +><[number, number, number]>[1, 2, 3] : [number, number, number] +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number +} + +var [j, k] = foo(); +>j : number, Symbol(j, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 5)) +>k : number, Symbol(k, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 7)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + +var [...p] = foo(); +>p : number[], Symbol(p, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 12, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt new file mode 100644 index 0000000000..8cb1d9eb8c --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2322: Type 'undefined[]' is not assignable to type 'H'. + Property '0' is missing in type 'undefined[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2461: Type 'H' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,13): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(21,13): error TS2462: A rest element must be last in an array destructuring pattern +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(22,6): error TS2322: Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(23,5): error TS2461: Type '{}' is not an array type. + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (7 errors) ==== + interface H { + 0: number, + 1: string + } + interface J extends Array { + 2: number; + } + + function bar(): J { + return <[number, number, number]>[1, 2, 3]; + } + + function gg(idx: number) { + return { + [idx]: true + } + } + + var [h, g, i]: H = []; + ~~~~~~~~~ +!!! error TS2322: Type 'undefined[]' is not assignable to type 'H'. +!!! error TS2322: Property '0' is missing in type 'undefined[]'. + ~~~~~~~~~ +!!! error TS2461: Type 'H' is not an array type. + var [[[y]], [[[[z]]]]] = [] + ~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + var [, , ...w4, , ] = [] + ~~ +!!! error TS2462: A rest element must be last in an array destructuring pattern + var [a = "string", b, c] = bar(); + ~ +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + var [r, s, t] = gg(1); + ~~~~~~~~~ +!!! error TS2461: Type '{}' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js new file mode 100644 index 0000000000..ad5d1c5c05 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js @@ -0,0 +1,41 @@ +//// [destructuringArrayBindingPatternAndAssignment3.ts] +interface H { + 0: number, + 1: string +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +function gg(idx: number) { + return { + [idx]: true + } +} + +var [h, g, i]: H = []; +var [[[y]], [[[[z]]]]] = [] +var [, , ...w4, , ] = [] +var [a = "string", b, c] = bar(); +var [r, s, t] = gg(1); + +//// [destructuringArrayBindingPatternAndAssignment3.js] +function bar() { + return [1, 2, 3]; +} +function gg(idx) { + return (_a = {}, + _a[idx] = true, + _a + ); + var _a; +} +var _a = [], h = _a[0], g = _a[1], i = _a[2]; +var _b = [], y = _b[0][0][0], z = _b[1][0][0][0][0]; +var _c = []; +var _d = bar(), _e = _d[0], a = _e === void 0 ? "string" : _e, b = _d[1], c = _d[2]; +var _f = gg(1), r = _f[0], s = _f[1], t = _f[2]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js new file mode 100644 index 0000000000..375cfd8f57 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js @@ -0,0 +1,27 @@ +//// [destructuringObjectBindingPatternAndAssignment1.ts] +var c = 0; +var { a, } = { a:1, }; +var { b: { c } } = { b: { c } }; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +var { d1 }: any = undefined; +var { e1 }: any = {}; +var { f: {f1} = { f1: "string" } }: any = {}; +var { f2: {f21} = { f21: "string" } }: any = undefined; +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +var {g = 1}: any = { g: 100000 }; +var {1: x} = { 1: "string" }; + +//// [destructuringObjectBindingPatternAndAssignment1.js] +var c = 0; +var a = ({ a: 1 }).a; +var c = ({ b: { c: c } }).b.c; +var _a = ({ b1: { c1: "world" } }).b1, c1 = (_a === void 0 ? { c1: "string" } : _a).c1; +var d1 = undefined.d1; +var e1 = ({}).e1; +var _b = ({}).f, f1 = (_b === void 0 ? { f1: "string" } : _b).f1; +var _c = undefined.f2, f21 = (_c === void 0 ? { f21: "string" } : _c).f21; +var _d = undefined.e1, e2 = (_d === void 0 ? { e2: "string" } : _d).e2; +var _e = ({}).e2, e3 = (_e === void 0 ? { e3: "string" } : _e).e3; +var _f = ({ g: 100000 }).g, g = _f === void 0 ? 1 : _f; +var x = ({ 1: "string" })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types new file mode 100644 index 0000000000..46fbe3a963 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types @@ -0,0 +1,87 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts === +var c = 0; +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) +>0 : number + +var { a, } = { a:1, }; +>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 5)) +>{ a:1, } : { a: number; } +>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 14)) +>1 : number + +var { b: { c } } = { b: { c } }; +>b : any +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) +>{ b: { c } } : { b: { c: number; }; } +>b : { c: number; }, Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 21)) +>{ c } : { c: number; } +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 26)) + +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +>b1 : any +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 11)) +>{ c1: "string" } : { c1: string; } +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 20)) +>"string" : string +>{ b1: { c1: "world" } } : { b1: { c1: string; }; } +>b1 : { c1: string; }, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 42)) +>{ c1: "world" } : { c1: string; } +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 48)) +>"world" : string + +var { d1 }: any = undefined; +>d1 : any, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 4, 5)) +>undefined : undefined, Symbol(undefined) + +var { e1 }: any = {}; +>e1 : any, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 5, 5)) +>{} : {} + +var { f: {f1} = { f1: "string" } }: any = {}; +>f : any +>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 10)) +>{ f1: "string" } : { f1: string; } +>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 17)) +>"string" : string +>{} : {} + +var { f2: {f21} = { f21: "string" } }: any = undefined; +>f2 : any +>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 11)) +>{ f21: "string" } : { f21: string; } +>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 19)) +>"string" : string +>undefined : undefined, Symbol(undefined) + +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +>e1 : any +>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 11)) +>{ e2: "string" } : { e2: string; } +>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 18)) +>"string" : string +>e1 : { e2: any; }, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 42)) +>e2 : any, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 48)) +>undefined : undefined, Symbol(undefined) + +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +>e2 : any +>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 11)) +>{ e3: "string" } : { e3: string; } +>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 18)) +>"string" : string +>e2 : { e3: any; }, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 42)) +>e3 : any, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 48)) +>{} : {} + +var {g = 1}: any = { g: 100000 }; +>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 5)) +>1 : number +>{ g: 100000 } : { g: number; } +>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 20)) +>100000 : number + +var {1: x} = { 1: "string" }; +>x : string, Symbol(x, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 11, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js new file mode 100644 index 0000000000..32ce0ab0c3 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js @@ -0,0 +1,76 @@ +//// [destructuringObjectBindingPatternAndAssignment2.ts] +interface I { + j: number; + [str: string]: number; +} +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog", + } +} + +function zz1(): J { + return { + "cat": 1, + } +} + +function yy() { + return {} +} + +var {j}: I| J = { j: 1000 }; +var {cat} = zz(); +var {"cat":cart} = zz(); + +var {can}: J = {}; +var {can1}: J = zz1(); + + +function f() { + var { z }: { z: number } = { z }; +} + +interface K { + [idx: number]: boolean +} + +var {1: boo}: K = { 1: true }; +var {1: boo1}: K = { }; + +function bar(): K { + return { }; +} +var {1: baz} = bar(); + +//// [destructuringObjectBindingPatternAndAssignment2.js] +function zz() { + return { + "cat": "dog" + }; +} +function zz1() { + return { + "cat": 1 + }; +} +function yy() { + return {}; +} +var j = ({ j: 1000 }).j; +var cat = (zz()).cat; +var cart = (zz())["cat"]; +var can = ({}).can; +var can1 = (zz1()).can1; +function f() { + var z = ({ z: z }).z; +} +var boo = ({ 1: true })[1]; +var boo1 = ({})[1]; +function bar() { + return {}; +} +var baz = (bar())[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types new file mode 100644 index 0000000000..a46f240660 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types @@ -0,0 +1,116 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts === +interface I { +>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) + + j: number; +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 13)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 2, 5)) +} +interface J { +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 5, 5)) +} +function zz() { +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + + return { +>{ "cat": "dog", } : { "cat": string; } + + "cat": "dog", +>"dog" : string + } +} + +function zz1(): J { +>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) + + return { +>{ "cat": 1, } : { [x: string]: number; "cat": number; } + + "cat": 1, +>1 : number + } +} + +function yy() { +>yy : () => {}, Symbol(yy, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 17, 1)) + + return {} +>{} : {} +} + +var {j}: I| J = { j: 1000 }; +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 5)) +>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>{ j: 1000 } : { [x: string]: number; j: number; } +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 17)) +>1000 : number + +var {cat} = zz(); +>cat : string, Symbol(cat, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 24, 5)) +>zz() : { "cat": string; } +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + +var {"cat":cart} = zz(); +>cart : string, Symbol(cart, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 25, 5)) +>zz() : { "cat": string; } +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + +var {can}: J = {}; +>can : number, Symbol(can, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 27, 5)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>{} : { [x: string]: undefined; } + +var {can1}: J = zz1(); +>can1 : number, Symbol(can1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 5)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>zz1() : J +>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) + + +function f() { +>f : () => void, Symbol(f, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 22)) + + var { z }: { z: number } = { z }; +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 9)) +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 16)) +>{ z } : { z: number; } +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 32)) +} + +interface K { +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) + + [idx: number]: boolean +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 36, 5)) +} + +var {1: boo}: K = { 1: true }; +>boo : boolean, Symbol(boo, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 39, 5)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) +>{ 1: true } : { [x: number]: boolean; 1: boolean; } +>true : boolean + +var {1: boo1}: K = { }; +>boo1 : boolean, Symbol(boo1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 5)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) +>{ } : { [x: number]: undefined; } + +function bar(): K { +>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) + + return { }; +>{ } : { [x: number]: undefined; } +} +var {1: baz} = bar(); +>baz : boolean, Symbol(baz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 45, 5)) +>bar() : K +>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt new file mode 100644 index 0000000000..de4dcee1bf --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(1,7): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. + Type '{ i: number; }' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,54): error TS2304: Cannot find name 'c'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,7): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,15): error TS1005: ':' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== + var {h?} = { h?: 1 }; + ~ +!!! error TS1005: ',' expected. + var {i}: string | number = { i: 2 }; + ~~~ +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'number'. + ~ +!!! error TS2459: Type 'string | number' has no property 'i' and no string index signature. + var {i1}: string | number| {} = { i1: 2 }; + ~~ +!!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. + var { f2: {f21} = { f212: "string" } }: any = undefined; + ~~~ +!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. + var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; + ~ +!!! error TS2304: Cannot find name 'c'. + var { d }: any; + var { ...d1 } = { + ~~~ +!!! error TS1180: Property destructuring pattern expected. + a: 1, b: 1, d1: 9, e: 10 + } + var {1} = { 1 }; + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js new file mode 100644 index 0000000000..d53afcbb97 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -0,0 +1,23 @@ +//// [destructuringObjectBindingPatternAndAssignment3.ts] +var {h?} = { h?: 1 }; +var {i}: string | number = { i: 2 }; +var {i1}: string | number| {} = { i1: 2 }; +var { f2: {f21} = { f212: "string" } }: any = undefined; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; +var { d }: any; +var { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +var {1} = { 1 }; + +//// [destructuringObjectBindingPatternAndAssignment3.js] +var h = ({ h: 1 }).h; +var i = ({ i: 2 }).i; +var i1 = ({ i1: 2 }).i1; +var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; +var _b = ({ b1: { c1: c } }).b1, c1 = (_b === void 0 ? { c1: "string" } : _b).c1; +var d = (void 0).d; +var d1 = ({ + a: 1, b: 1, d1: 9, e: 10 +}).d1; +var = ({ 1: })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt new file mode 100644 index 0000000000..f0b7977a44 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,6): error TS2459: Type 'K | K1' has no property 'k' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(12,6): error TS2459: Type '{}' has no property '2' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(23,5): error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. + Index signature is missing in type '{ "cat": string; }'. + + +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (3 errors) ==== + interface K { + [str: string]: string; + } + interface K1 { + k: string; + } + var {k}: K|K1 = { k: "string" }; + ~ +!!! error TS2459: Type 'K | K1' has no property 'k' and no string index signature. + + function barn() { + return {}; + } + var {2: baz1} = barn() + ~ +!!! error TS2459: Type '{}' has no property '2' and no string index signature. + + interface J { + [str: string]: number; + } + function zz() { + return { + "cat": "dog" + } + } + + var {"can": can}: J = zz(); + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. +!!! error TS2322: Index signature is missing in type '{ "cat": string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js new file mode 100644 index 0000000000..7abf9f3b84 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js @@ -0,0 +1,37 @@ +//// [destructuringObjectBindingPatternAndAssignment4.ts] +interface K { + [str: string]: string; +} +interface K1 { + k: string; +} +var {k}: K|K1 = { k: "string" }; + +function barn() { + return {}; +} +var {2: baz1} = barn() + +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog" + } +} + +var {"can": can}: J = zz(); + +//// [destructuringObjectBindingPatternAndAssignment4.js] +var k = ({ k: "string" }).k; +function barn() { + return {}; +} +var baz1 = (barn())[2]; +function zz() { + return { + "cat": "dog" + }; +} +var can = (zz())["can"]; diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt new file mode 100644 index 0000000000..a455ee862c --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,23): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,33): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,44): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. + + +==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts (3 errors) ==== + var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; + var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; + var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; + ~~~ +!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. + ~~~ +!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js new file mode 100644 index 0000000000..b089d2ab4f --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js @@ -0,0 +1,9 @@ +//// [destructuringVariableDeclarationAndAssignment.ts] +var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; +var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; +var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; + +//// [destructuringVariableDeclarationAndAssignment.js] +var _a = ({ o: [1, 2, { b1: 4, b4: 0 }] }).o, a1 = _a[0], a2 = _a[1], _b = _a[2], a3 = _b === void 0 ? { b1: 1000, b4: 200 } : _b; +var _c = ({ o0: [1, 2, { e: 4, f: 0 }] }).o0, c = _c[0], d = _c[1], _d = _c[2], e1 = _d.e, f = _d.f; +var _e = ({ o1: [1, 2, { b12: 4, b42: 0 }] }).o1, a11 = _e[0], a21 = _e[1], _f = _e[2], b22 = _f.b12, b42 = _f.b42, c = _e.slice(4); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts new file mode 100644 index 0000000000..4e6c46d267 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts @@ -0,0 +1,22 @@ +var [p0,p1, p2] : any = [2, 3, 4]; +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +var [d, e]: any = undefined; +var [f = false, g = 1]: any = undefined; +g = 10; +f = true; + +var [x] = [] +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +var [[w], m]: [[string|number], boolean] = [[1], true]; +interface J extends Array { + 2: number; +} + +var [, w1] = [1, 2, 3]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,,...w3] = [1, 2, 3, 4, "hello"]; + +var [r, s, ...t] = [1, 2, "string"]; +var [r1, s1, t1] = [1, 2, "string"]; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts new file mode 100644 index 0000000000..3b094541d3 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts @@ -0,0 +1,13 @@ +function foo() { + return [1, 2, 3]; +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +var [j, k] = foo(); +var [...p] = foo(); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts new file mode 100644 index 0000000000..43f8c3546d --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts @@ -0,0 +1,23 @@ +interface H { + 0: number, + 1: string +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +function gg(idx: number) { + return { + [idx]: true + } +} + +var [h, g, i]: H = []; +var [[[y]], [[[[z]]]]] = [] +var [, , ...w4, , ] = [] +var [a = "string", b, c] = bar(); +var [r, s, t] = gg(1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts new file mode 100644 index 0000000000..f15541aaf9 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts @@ -0,0 +1,12 @@ +var c = 0; +var { a, } = { a:1, }; +var { b: { c } } = { b: { c } }; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +var { d1 }: any = undefined; +var { e1 }: any = {}; +var { f: {f1} = { f1: "string" } }: any = {}; +var { f2: {f21} = { f21: "string" } }: any = undefined; +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +var {g = 1}: any = { g: 100000 }; +var {1: x} = { 1: "string" }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts new file mode 100644 index 0000000000..026c901dbe --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts @@ -0,0 +1,46 @@ +interface I { + j: number; + [str: string]: number; +} +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog", + } +} + +function zz1(): J { + return { + "cat": 1, + } +} + +function yy() { + return {} +} + +var {j}: I| J = { j: 1000 }; +var {cat} = zz(); +var {"cat":cart} = zz(); + +var {can}: J = {}; +var {can1}: J = zz1(); + + +function f() { + var { z }: { z: number } = { z }; +} + +interface K { + [idx: number]: boolean +} + +var {1: boo}: K = { 1: true }; +var {1: boo1}: K = { }; + +function bar(): K { + return { }; +} +var {1: baz} = bar(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts new file mode 100644 index 0000000000..524728dc9d --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -0,0 +1,10 @@ +var {h?} = { h?: 1 }; +var {i}: string | number = { i: 2 }; +var {i1}: string | number| {} = { i1: 2 }; +var { f2: {f21} = { f212: "string" } }: any = undefined; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; +var { d }: any; +var { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +var {1} = { 1 }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts new file mode 100644 index 0000000000..3cb7ae0658 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts @@ -0,0 +1,23 @@ +interface K { + [str: string]: string; +} +interface K1 { + k: string; +} +var {k}: K|K1 = { k: "string" }; + +function barn() { + return {}; +} +var {2: baz1} = barn() + +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog" + } +} + +var {"can": can}: J = zz(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts new file mode 100644 index 0000000000..a3377dfb8f --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts @@ -0,0 +1,3 @@ +var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; +var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; +var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; \ No newline at end of file From 31da11656edfb4f168f4317f5893d973e9d7ea9b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 18:53:16 -0700 Subject: [PATCH 2/3] Add spec description --- ...turingArrayBindingPatternAndAssignment1.js | 41 ---- ...ingArrayBindingPatternAndAssignment1.types | 133 ------------ ...ingArrayBindingPatternAndAssignment1ES5.js | 100 +++++++++ ...ArrayBindingPatternAndAssignment1ES5.types | 177 ++++++++++++++++ ...ingArrayBindingPatternAndAssignment1ES6.js | 99 +++++++++ ...ArrayBindingPatternAndAssignment1ES6.types | 177 ++++++++++++++++ ...rayBindingPatternAndAssignment2.errors.txt | 71 +++++++ ...turingArrayBindingPatternAndAssignment2.js | 59 ++++-- ...ingArrayBindingPatternAndAssignment2.types | 41 ---- ...rayBindingPatternAndAssignment3.errors.txt | 51 ----- ...turingArrayBindingPatternAndAssignment3.js | 41 ---- ...uringObjectBindingPatternAndAssignment1.js | 27 --- ...ngObjectBindingPatternAndAssignment1.types | 87 -------- ...ngObjectBindingPatternAndAssignment1ES5.js | 90 ++++++++ ...bjectBindingPatternAndAssignment1ES5.types | 133 ++++++++++++ ...ngObjectBindingPatternAndAssignment1ES6.js | 90 ++++++++ ...bjectBindingPatternAndAssignment1ES6.types | 133 ++++++++++++ ...uringObjectBindingPatternAndAssignment2.js | 76 ------- ...ngObjectBindingPatternAndAssignment2.types | 116 ---------- ...ectBindingPatternAndAssignment3.errors.txt | 26 +-- ...uringObjectBindingPatternAndAssignment3.js | 10 +- ...ectBindingPatternAndAssignment4.errors.txt | 37 ---- ...uringObjectBindingPatternAndAssignment4.js | 37 ---- .../destructuringVariableDeclaration1ES5.js | 77 +++++++ ...destructuringVariableDeclaration1ES5.types | 200 ++++++++++++++++++ .../destructuringVariableDeclaration1ES6.js | 77 +++++++ ...destructuringVariableDeclaration1ES6.types | 200 ++++++++++++++++++ ...structuringVariableDeclaration2.errors.txt | 62 ++++++ .../destructuringVariableDeclaration2.js | 38 ++++ ...ariableDeclarationAndAssignment.errors.txt | 15 -- ...cturingVariableDeclarationAndAssignment.js | 9 - ...turingArrayBindingPatternAndAssignment1.ts | 22 -- ...ingArrayBindingPatternAndAssignment1ES5.ts | 52 +++++ ...ingArrayBindingPatternAndAssignment1ES6.ts | 53 +++++ ...turingArrayBindingPatternAndAssignment2.ts | 33 ++- ...turingArrayBindingPatternAndAssignment3.ts | 23 -- ...uringObjectBindingPatternAndAssignment1.ts | 12 -- ...ngObjectBindingPatternAndAssignment1ES5.ts | 54 +++++ ...ngObjectBindingPatternAndAssignment1ES6.ts | 55 +++++ ...uringObjectBindingPatternAndAssignment2.ts | 46 ---- ...uringObjectBindingPatternAndAssignment3.ts | 8 +- ...uringObjectBindingPatternAndAssignment4.ts | 23 -- .../destructuringVariableDeclaration1ES5.ts | 40 ++++ .../destructuringVariableDeclaration1ES6.ts | 41 ++++ .../destructuringVariableDeclaration2.ts | 19 ++ ...cturingVariableDeclarationAndAssignment.ts | 3 - 46 files changed, 2134 insertions(+), 880 deletions(-) delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.types create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.types create mode 100644 tests/baselines/reference/destructuringVariableDeclaration2.errors.txt create mode 100644 tests/baselines/reference/destructuringVariableDeclaration2.js delete mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt delete mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js deleted file mode 100644 index f6c84b011d..0000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js +++ /dev/null @@ -1,41 +0,0 @@ -//// [destructuringArrayBindingPatternAndAssignment1.ts] -var [p0,p1, p2] : any = [2, 3, 4]; -var [a, b, c]: [number, number, string] = [1, 2, "string"]; -var [d, e]: any = undefined; -var [f = false, g = 1]: any = undefined; -g = 10; -f = true; - -var [x] = [] -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] -var [[w], m]: [[string|number], boolean] = [[1], true]; -interface J extends Array { - 2: number; -} - -var [, w1] = [1, 2, 3]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,,...w3] = [1, 2, 3, 4, "hello"]; - -var [r, s, ...t] = [1, 2, "string"]; -var [r1, s1, t1] = [1, 2, "string"]; - - - -//// [destructuringArrayBindingPatternAndAssignment1.js] -var _a = [2, 3, 4], p0 = _a[0], p1 = _a[1], p2 = _a[2]; -var _b = [1, 2, "string"], a = _b[0], b = _b[1], c = _b[2]; -var d = undefined[0], e = undefined[1]; -var _c = undefined[0], f = _c === void 0 ? false : _c, _d = undefined[1], g = _d === void 0 ? 1 : _d; -g = 10; -f = true; -var x = ([])[0]; -var _e = [[[]], [[[[]]]]], y = _e[0][0][0], z = _e[1][0][0][0][0]; -var _f = [[1], true], w = _f[0][0], m = _f[1]; -var _g = [1, 2, 3], w1 = _g[1]; -var _h = [1, 2, 3, 4], w2 = _h[3]; -var _j = [1, 2, 3, 4], w2 = _j[3]; -var _k = [1, 2, 3, 4, "hello"], w3 = _k.slice(3); -var _l = [1, 2, "string"], r = _l[0], s = _l[1], t = _l.slice(2); -var _m = [1, 2, "string"], r1 = _m[0], s1 = _m[1], t1 = _m[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types deleted file mode 100644 index f4abb8953f..0000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types +++ /dev/null @@ -1,133 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts === -var [p0,p1, p2] : any = [2, 3, 4]; ->p0 : any, Symbol(p0, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 5)) ->p1 : any, Symbol(p1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 8)) ->p2 : any, Symbol(p2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 11)) ->[2, 3, 4] : number[] ->2 : number ->3 : number ->4 : number - -var [a, b, c]: [number, number, string] = [1, 2, "string"]; ->a : number, Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 5)) ->b : number, Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 7)) ->c : string, Symbol(c, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 10)) ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -var [d, e]: any = undefined; ->d : any, Symbol(d, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 5)) ->e : any, Symbol(e, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 7)) ->undefined : undefined, Symbol(undefined) - -var [f = false, g = 1]: any = undefined; ->f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) ->false : boolean ->g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) ->1 : number ->undefined : undefined, Symbol(undefined) - -g = 10; ->g = 10 : number ->g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) ->10 : number - -f = true; ->f = true : boolean ->f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) ->true : boolean - -var [x] = [] ->x : any, Symbol(x, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 7, 5)) ->[] : undefined[] - -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] ->y : any, Symbol(y, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 7)) ->z : any, Symbol(z, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 16)) ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] - -var [[w], m]: [[string|number], boolean] = [[1], true]; ->w : string | number, Symbol(w, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 6)) ->m : boolean, Symbol(m, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 9)) ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -interface J extends Array { ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 55)) ->Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) - - 2: number; -} - -var [, w1] = [1, 2, 3]; -> : undefined ->w1 : number, Symbol(w1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 14, 6)) ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, w2] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, w2] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...w3] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->w3 : (string | number)[], Symbol(w3, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 17, 8)) ->[1, 2, 3, 4, "hello"] : (string | number)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [r, s, ...t] = [1, 2, "string"]; ->r : string | number, Symbol(r, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 5)) ->s : string | number, Symbol(s, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 7)) ->t : (string | number)[], Symbol(t, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 10)) ->[1, 2, "string"] : (string | number)[] ->1 : number ->2 : number ->"string" : string - -var [r1, s1, t1] = [1, 2, "string"]; ->r1 : number, Symbol(r1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 5)) ->s1 : number, Symbol(s1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 8)) ->t1 : string, Symbol(t1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 12)) ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js new file mode 100644 index 0000000000..6a94b0d2a7 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -0,0 +1,100 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES5.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"]; + + + +//// [destructuringArrayBindingPatternAndAssignment1ES5.js] +/* 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 = undefined[0], a1 = undefined[1]; +var _a = undefined[0], a2 = _a === void 0 ? false : _a, _b = undefined[1], a3 = _b === void 0 ? 1 : _b; +// 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 _c = [2, 3, 4], b0 = _c[0], b1 = _c[1], b2 = _c[2]; +var _d = [1, 2, "string"], b3 = _d[0], b4 = _d[1], b5 = _d[2]; +function foo() { + return [1, 2, 3]; +} +var _e = foo(), b6 = _e[0], b7 = _e[1]; +var _f = foo(), b8 = _f.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 _g = temp, c0 = _g[0], c1 = _g[1]; +var c2 = ([])[0]; +var _h = [[[]], [[[[]]]]], c3 = _h[0][0][0], c4 = _h[1][0][0][0][0]; +var _j = [[1], true], c5 = _j[0][0], c6 = _j[1]; +var _k = [1, 2, 3], c7 = _k[1]; +var _l = [1, 2, 3, 4], c8 = _l[3]; +var _m = [1, 2, 3, 4], c9 = _m[3]; +var _o = [1, 2, 3, 4, "hello"], c10 = _o.slice(3); +var _p = [1, 2, "string"], c11 = _p[0], c12 = _p[1], c13 = _p.slice(2); +var _q = [1, 2, "string"], c14 = _q[0], c15 = _q[1], c16 = _q[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types new file mode 100644 index 0000000000..6508581d89 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.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; +>a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) +>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) +>undefined : undefined, Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>false : boolean +>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>1 : number +>undefined : undefined, Symbol(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]; +>b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) +>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) +>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) +>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) +>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) +>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +var [...b8] = foo(); +>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +// 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] +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) +>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>[...temp] : number[] +>...temp : number +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c2] = []; +>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) +>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) +>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) +>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) +>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) +>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) +>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js new file mode 100644 index 0000000000..d3a5c9ff5a --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js @@ -0,0 +1,99 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES6.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"]; + +//// [destructuringArrayBindingPatternAndAssignment1ES6.js] +/* 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] = undefined; +var [a2 = false, a3 = 1] = 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] = [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] = [[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/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types new file mode 100644 index 0000000000..4c999c9468 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.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; +>a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) +>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) +>undefined : undefined, Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>false : boolean +>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>1 : number +>undefined : undefined, Symbol(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]; +>b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) +>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) +>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) +>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) +>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) +>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +var [...b8] = foo(); +>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +// 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] +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) +>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>[...temp] : number[] +>...temp : number +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c2] = []; +>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) +>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) +>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) +>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) +>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) +>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) +>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt new file mode 100644 index 0000000000..a2e5cb7e17 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -0,0 +1,71 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. + Types of property '1' are incompatible. + Type 'number' is not assignable to type 'boolean'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(17,6): error TS2322: Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(22,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(23,5): error TS2322: Type 'number[]' is not assignable to type '[string, string]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== + // 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]]] = [] // Error + ~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + var [[a2], [[a3]]] = undefined // Error + ~~~~~~~~~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + + // 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]: [number, boolean, string] = [1, 2, "string"]; // Error + ~~~~~~~~~~~~ +!!! error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. + interface J extends Array { + 2: number; + } + + function bar(): J { + return <[number, number, number]>[1, 2, 3]; + } + var [b3 = "string", b4, b5] = bar(); // Error + ~~ +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + + // 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 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]: [number, number] = [...temp]; // Error + ~~~~~~~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + var [c2, c3]: [string, string] = [...temp]; // Error + ~~~~~~~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[string, string]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + + interface F { + [idx: number]: boolean + } + + function foo(idx: number): F { + return { + 2: true + } + } + var [c4, c5, c6] = foo(1); // Error + ~~~~~~~~~~~~ +!!! error TS2461: Type 'F' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js index 67cfaef96d..fdbf47fd97 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -1,25 +1,60 @@ //// [destructuringArrayBindingPatternAndAssignment2.ts] -function foo() { - return [1, 2, 3]; -} +// 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]]] = [] // Error +var [[a2], [[a3]]] = undefined // Error + +// 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]: [number, boolean, string] = [1, 2, "string"]; // Error interface J extends Array { 2: number; } function bar(): J { - return <[number, number, number]>[1, 2, 3]; + return <[number, number, number]>[1, 2, 3]; +} +var [b3 = "string", b4, b5] = bar(); // Error + +// 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 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]: [number, number] = [...temp]; // Error +var [c2, c3]: [string, string] = [...temp]; // Error + +interface F { + [idx: number]: boolean } -var [j, k] = foo(); -var [...p] = foo(); - +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error //// [destructuringArrayBindingPatternAndAssignment2.js] -function foo() { - return [1, 2, 3]; -} +// 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 = [], a0 = _a[0][0], a1 = _a[1][0][0]; // Error +var a2 = undefined[0][0], a3 = undefined[1][0][0]; // Error +// 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 _b = [1, 2, "string"], b0 = _b[0], b1 = _b[1], b2 = _b[2]; // Error function bar() { return [1, 2, 3]; } -var _a = foo(), j = _a[0], k = _a[1]; -var _b = foo(), p = _b.slice(0); +var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 = _c[2]; // Error +// 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 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 _e = temp, c0 = _e[0], c1 = _e[1]; // Error +var _f = temp, c2 = _f[0], c3 = _f[1]; // Error +function foo(idx) { + return { + 2: true + }; +} +var _g = foo(1), c4 = _g[0], c5 = _g[1], c6 = _g[2]; // Error diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types deleted file mode 100644 index f6b40e5fc9..0000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types +++ /dev/null @@ -1,41 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts === -function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} -interface J extends Array { ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) ->Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) - - 2: number; -} - -function bar(): J { ->bar : () => J, Symbol(bar, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 5, 1)) ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) - - return <[number, number, number]>[1, 2, 3]; -><[number, number, number]>[1, 2, 3] : [number, number, number] ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number -} - -var [j, k] = foo(); ->j : number, Symbol(j, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 5)) ->k : number, Symbol(k, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 7)) ->foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - -var [...p] = foo(); ->p : number[], Symbol(p, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 12, 5)) ->foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt deleted file mode 100644 index 8cb1d9eb8c..0000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt +++ /dev/null @@ -1,51 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2322: Type 'undefined[]' is not assignable to type 'H'. - Property '0' is missing in type 'undefined[]'. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2461: Type 'H' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,13): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(21,13): error TS2462: A rest element must be last in an array destructuring pattern -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(22,6): error TS2322: Type 'string' is not assignable to type 'Number'. - Property 'toFixed' is missing in type 'String'. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(23,5): error TS2461: Type '{}' is not an array type. - - -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (7 errors) ==== - interface H { - 0: number, - 1: string - } - interface J extends Array { - 2: number; - } - - function bar(): J { - return <[number, number, number]>[1, 2, 3]; - } - - function gg(idx: number) { - return { - [idx]: true - } - } - - var [h, g, i]: H = []; - ~~~~~~~~~ -!!! error TS2322: Type 'undefined[]' is not assignable to type 'H'. -!!! error TS2322: Property '0' is missing in type 'undefined[]'. - ~~~~~~~~~ -!!! error TS2461: Type 'H' is not an array type. - var [[[y]], [[[[z]]]]] = [] - ~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - ~~~~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - var [, , ...w4, , ] = [] - ~~ -!!! error TS2462: A rest element must be last in an array destructuring pattern - var [a = "string", b, c] = bar(); - ~ -!!! error TS2322: Type 'string' is not assignable to type 'Number'. -!!! error TS2322: Property 'toFixed' is missing in type 'String'. - var [r, s, t] = gg(1); - ~~~~~~~~~ -!!! error TS2461: Type '{}' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js deleted file mode 100644 index ad5d1c5c05..0000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js +++ /dev/null @@ -1,41 +0,0 @@ -//// [destructuringArrayBindingPatternAndAssignment3.ts] -interface H { - 0: number, - 1: string -} -interface J extends Array { - 2: number; -} - -function bar(): J { - return <[number, number, number]>[1, 2, 3]; -} - -function gg(idx: number) { - return { - [idx]: true - } -} - -var [h, g, i]: H = []; -var [[[y]], [[[[z]]]]] = [] -var [, , ...w4, , ] = [] -var [a = "string", b, c] = bar(); -var [r, s, t] = gg(1); - -//// [destructuringArrayBindingPatternAndAssignment3.js] -function bar() { - return [1, 2, 3]; -} -function gg(idx) { - return (_a = {}, - _a[idx] = true, - _a - ); - var _a; -} -var _a = [], h = _a[0], g = _a[1], i = _a[2]; -var _b = [], y = _b[0][0][0], z = _b[1][0][0][0][0]; -var _c = []; -var _d = bar(), _e = _d[0], a = _e === void 0 ? "string" : _e, b = _d[1], c = _d[2]; -var _f = gg(1), r = _f[0], s = _f[1], t = _f[2]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js deleted file mode 100644 index 375cfd8f57..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment1.ts] -var c = 0; -var { a, } = { a:1, }; -var { b: { c } } = { b: { c } }; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; -var { d1 }: any = undefined; -var { e1 }: any = {}; -var { f: {f1} = { f1: "string" } }: any = {}; -var { f2: {f21} = { f21: "string" } }: any = undefined; -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; -var {g = 1}: any = { g: 100000 }; -var {1: x} = { 1: "string" }; - -//// [destructuringObjectBindingPatternAndAssignment1.js] -var c = 0; -var a = ({ a: 1 }).a; -var c = ({ b: { c: c } }).b.c; -var _a = ({ b1: { c1: "world" } }).b1, c1 = (_a === void 0 ? { c1: "string" } : _a).c1; -var d1 = undefined.d1; -var e1 = ({}).e1; -var _b = ({}).f, f1 = (_b === void 0 ? { f1: "string" } : _b).f1; -var _c = undefined.f2, f21 = (_c === void 0 ? { f21: "string" } : _c).f21; -var _d = undefined.e1, e2 = (_d === void 0 ? { e2: "string" } : _d).e2; -var _e = ({}).e2, e3 = (_e === void 0 ? { e3: "string" } : _e).e3; -var _f = ({ g: 100000 }).g, g = _f === void 0 ? 1 : _f; -var x = ({ 1: "string" })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types deleted file mode 100644 index 46fbe3a963..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types +++ /dev/null @@ -1,87 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts === -var c = 0; ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) ->0 : number - -var { a, } = { a:1, }; ->a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 5)) ->{ a:1, } : { a: number; } ->a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 14)) ->1 : number - -var { b: { c } } = { b: { c } }; ->b : any ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) ->{ b: { c } } : { b: { c: number; }; } ->b : { c: number; }, Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 21)) ->{ c } : { c: number; } ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 26)) - -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; ->b1 : any ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 11)) ->{ c1: "string" } : { c1: string; } ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 20)) ->"string" : string ->{ b1: { c1: "world" } } : { b1: { c1: string; }; } ->b1 : { c1: string; }, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 42)) ->{ c1: "world" } : { c1: string; } ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 48)) ->"world" : string - -var { d1 }: any = undefined; ->d1 : any, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 4, 5)) ->undefined : undefined, Symbol(undefined) - -var { e1 }: any = {}; ->e1 : any, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 5, 5)) ->{} : {} - -var { f: {f1} = { f1: "string" } }: any = {}; ->f : any ->f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 10)) ->{ f1: "string" } : { f1: string; } ->f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 17)) ->"string" : string ->{} : {} - -var { f2: {f21} = { f21: "string" } }: any = undefined; ->f2 : any ->f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 11)) ->{ f21: "string" } : { f21: string; } ->f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 19)) ->"string" : string ->undefined : undefined, Symbol(undefined) - -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; ->e1 : any ->e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 11)) ->{ e2: "string" } : { e2: string; } ->e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 18)) ->"string" : string ->e1 : { e2: any; }, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 42)) ->e2 : any, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 48)) ->undefined : undefined, Symbol(undefined) - -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; ->e2 : any ->e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 11)) ->{ e3: "string" } : { e3: string; } ->e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 18)) ->"string" : string ->e2 : { e3: any; }, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 42)) ->e3 : any, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 48)) ->{} : {} - -var {g = 1}: any = { g: 100000 }; ->g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 5)) ->1 : number ->{ g: 100000 } : { g: number; } ->g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 20)) ->100000 : number - -var {1: x} = { 1: "string" }; ->x : string, Symbol(x, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 11, 5)) ->{ 1: "string" } : { 1: string; } ->"string" : string - diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js new file mode 100644 index 0000000000..2b12c2a54a --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js @@ -0,0 +1,90 @@ +//// [destructuringObjectBindingPatternAndAssignment1ES5.ts] +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); + +//// [destructuringObjectBindingPatternAndAssignment1ES5.js] +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var a1 = undefined.a1; +var a2 = ({}).a2; +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var b1 = ({ b1: 1 }).b1; +var _a = ({ b2: { b21: "world" } }).b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; +var b3 = ({ 1: "string" })[1]; +var _b = ({ b4: 100000 }).b4, b4 = _b === void 0 ? 1 : _b; +var b52 = ({ b5: { b52: b52 } }).b5.b52; +function foo() { + return { + 1: true + }; +} +function bar() { + return { + 2: true + }; +} +var c0 = (foo())[1]; +var c1 = (bar())[1]; +function foo1() { + return { + "prop1": 2 + }; +} +var d1 = (foo1())["prop1"]; +var d1 = (foo1())["prop2"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types new file mode 100644 index 0000000000..3642f6c6ab --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts === +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) +>undefined : undefined, Symbol(undefined) + +var { a2 }: any = {}; +>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) +>{} : {} + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>{ b1:1, } : { b1: number; } +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>{ b21: "string" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>{ b21: "world" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>{ b52 } : { b52: any; } +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + [idx: number]: boolean; +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +} + +function foo(): F { +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>foo() : F +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>bar() : F +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js new file mode 100644 index 0000000000..0173645d8a --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js @@ -0,0 +1,90 @@ +//// [destructuringObjectBindingPatternAndAssignment1ES6.ts] +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); + +//// [destructuringObjectBindingPatternAndAssignment1ES6.js] +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 } = undefined; +var { a2 } = {}; +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1: 1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var { 1: b3 } = { 1: "string" }; +var { b4 = 1 } = { b4: 100000 }; +var { b5: { b52 } } = { b5: { b52 } }; +function foo() { + return { + 1: true + }; +} +function bar() { + return { + 2: true + }; +} +var { 1: c0 } = foo(); +var { 1: c1 } = bar(); +function foo1() { + return { + "prop1": 2 + }; +} +var { "prop1": d1 } = foo1(); +var { "prop2": d1 } = foo1(); diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types new file mode 100644 index 0000000000..afb24e6331 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts === +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) +>undefined : undefined, Symbol(undefined) + +var { a2 }: any = {}; +>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) +>{} : {} + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>{ b1:1, } : { b1: number; } +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>{ b21: "string" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>{ b21: "world" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>{ b52 } : { b52: any; } +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + [idx: number]: boolean; +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +} + +function foo(): F { +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>foo() : F +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>bar() : F +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js deleted file mode 100644 index 32ce0ab0c3..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment2.ts] -interface I { - j: number; - [str: string]: number; -} -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog", - } -} - -function zz1(): J { - return { - "cat": 1, - } -} - -function yy() { - return {} -} - -var {j}: I| J = { j: 1000 }; -var {cat} = zz(); -var {"cat":cart} = zz(); - -var {can}: J = {}; -var {can1}: J = zz1(); - - -function f() { - var { z }: { z: number } = { z }; -} - -interface K { - [idx: number]: boolean -} - -var {1: boo}: K = { 1: true }; -var {1: boo1}: K = { }; - -function bar(): K { - return { }; -} -var {1: baz} = bar(); - -//// [destructuringObjectBindingPatternAndAssignment2.js] -function zz() { - return { - "cat": "dog" - }; -} -function zz1() { - return { - "cat": 1 - }; -} -function yy() { - return {}; -} -var j = ({ j: 1000 }).j; -var cat = (zz()).cat; -var cart = (zz())["cat"]; -var can = ({}).can; -var can1 = (zz1()).can1; -function f() { - var z = ({ z: z }).z; -} -var boo = ({ 1: true })[1]; -var boo1 = ({})[1]; -function bar() { - return {}; -} -var baz = (bar())[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types deleted file mode 100644 index a46f240660..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types +++ /dev/null @@ -1,116 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts === -interface I { ->I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) - - j: number; ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 13)) - - [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 2, 5)) -} -interface J { ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) - - [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 5, 5)) -} -function zz() { ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - - return { ->{ "cat": "dog", } : { "cat": string; } - - "cat": "dog", ->"dog" : string - } -} - -function zz1(): J { ->zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) - - return { ->{ "cat": 1, } : { [x: string]: number; "cat": number; } - - "cat": 1, ->1 : number - } -} - -function yy() { ->yy : () => {}, Symbol(yy, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 17, 1)) - - return {} ->{} : {} -} - -var {j}: I| J = { j: 1000 }; ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 5)) ->I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->{ j: 1000 } : { [x: string]: number; j: number; } ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 17)) ->1000 : number - -var {cat} = zz(); ->cat : string, Symbol(cat, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 24, 5)) ->zz() : { "cat": string; } ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - -var {"cat":cart} = zz(); ->cart : string, Symbol(cart, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 25, 5)) ->zz() : { "cat": string; } ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - -var {can}: J = {}; ->can : number, Symbol(can, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 27, 5)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->{} : { [x: string]: undefined; } - -var {can1}: J = zz1(); ->can1 : number, Symbol(can1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 5)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->zz1() : J ->zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) - - -function f() { ->f : () => void, Symbol(f, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 22)) - - var { z }: { z: number } = { z }; ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 9)) ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 16)) ->{ z } : { z: number; } ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 32)) -} - -interface K { ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) - - [idx: number]: boolean ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 36, 5)) -} - -var {1: boo}: K = { 1: true }; ->boo : boolean, Symbol(boo, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 39, 5)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) ->{ 1: true } : { [x: number]: boolean; 1: boolean; } ->true : boolean - -var {1: boo1}: K = { }; ->boo1 : boolean, Symbol(boo1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 5)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) ->{ } : { [x: number]: undefined; } - -function bar(): K { ->bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) - - return { }; ->{ } : { [x: number]: undefined; } -} -var {1: baz} = bar(); ->baz : boolean, Symbol(baz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 45, 5)) ->bar() : K ->bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) - diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index de4dcee1bf..9025f24f99 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -1,16 +1,17 @@ -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(1,7): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,7): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. Type '{ i: number; }' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,54): error TS2304: Cannot find name 'c'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,7): error TS1180: Property destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,7): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,15): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected. ==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== + // Error var {h?} = { h?: 1 }; ~ !!! error TS1005: ',' expected. @@ -26,10 +27,6 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ !!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. - var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; - ~ -!!! error TS2304: Cannot find name 'c'. - var { d }: any; var { ...d1 } = { ~~~ !!! error TS1180: Property destructuring pattern expected. @@ -39,4 +36,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs ~ !!! error TS1005: ':' expected. ~ +!!! error TS1005: ':' expected. + var {"prop"} = { "prop": 1 }; + ~ !!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js index d53afcbb97..3c617ec9b8 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -1,23 +1,23 @@ //// [destructuringObjectBindingPatternAndAssignment3.ts] +// Error var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; -var { d }: any; var { ...d1 } = { a: 1, b: 1, d1: 9, e: 10 } -var {1} = { 1 }; +var {1} = { 1 }; +var {"prop"} = { "prop": 1 }; //// [destructuringObjectBindingPatternAndAssignment3.js] +// Error var h = ({ h: 1 }).h; var i = ({ i: 2 }).i; var i1 = ({ i1: 2 }).i1; var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; -var _b = ({ b1: { c1: c } }).b1, c1 = (_b === void 0 ? { c1: "string" } : _b).c1; -var d = (void 0).d; var d1 = ({ a: 1, b: 1, d1: 9, e: 10 }).d1; var = ({ 1: })[1]; +var = ({ "prop": 1 })["prop"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt deleted file mode 100644 index f0b7977a44..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,6): error TS2459: Type 'K | K1' has no property 'k' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(12,6): error TS2459: Type '{}' has no property '2' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(23,5): error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. - Index signature is missing in type '{ "cat": string; }'. - - -==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (3 errors) ==== - interface K { - [str: string]: string; - } - interface K1 { - k: string; - } - var {k}: K|K1 = { k: "string" }; - ~ -!!! error TS2459: Type 'K | K1' has no property 'k' and no string index signature. - - function barn() { - return {}; - } - var {2: baz1} = barn() - ~ -!!! error TS2459: Type '{}' has no property '2' and no string index signature. - - interface J { - [str: string]: number; - } - function zz() { - return { - "cat": "dog" - } - } - - var {"can": can}: J = zz(); - ~~~~~~~~~~~~ -!!! error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. -!!! error TS2322: Index signature is missing in type '{ "cat": string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js deleted file mode 100644 index 7abf9f3b84..0000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment4.ts] -interface K { - [str: string]: string; -} -interface K1 { - k: string; -} -var {k}: K|K1 = { k: "string" }; - -function barn() { - return {}; -} -var {2: baz1} = barn() - -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog" - } -} - -var {"can": can}: J = zz(); - -//// [destructuringObjectBindingPatternAndAssignment4.js] -var k = ({ k: "string" }).k; -function barn() { - return {}; -} -var baz1 = (barn())[2]; -function zz() { - return { - "cat": "dog" - }; -} -var can = (zz())["can"]; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js new file mode 100644 index 0000000000..2d1f0c101b --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -0,0 +1,77 @@ +//// [destructuringVariableDeclaration1ES5.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] } }; + + + +//// [destructuringVariableDeclaration1ES5.js] +// 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 = [1, [["hello"]], true], a3 = _b[0], a4 = _b[1][0][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 _c = ({ b1: { b11: "world" } }).b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; +var temp = { t1: true, t2: "false" }; +var _d = [3, false, { t1: false, t2: "hello" }], _e = _d[0], b2 = _e === void 0 ? 3 : _e, _f = _d[1], b3 = _f === void 0 ? true : _f, _g = _d[2], b4 = _g === void 0 ? temp : _g; +var _h = [undefined, undefined, undefined], _j = _h[0], b5 = _j === void 0 ? 3 : _j, _k = _h[1], b6 = _k === void 0 ? true : _k, _l = _h[2], b7 = _l === void 0 ? temp : _l; +// 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 _m = [1, 2, 3], c1 = _m.slice(0); +var _o = [1, 2, 3, "string"], c2 = _o.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 _p = [1, "string"], d1 = _p[0], d2 = _p[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 _q = [1, "string"].concat(temp1), d3 = _q[0], d4 = _q[1]; +// Combining both forms of destructuring, +var _r = ({ e: [1, 2, { b1: 4, b4: 0 }] }).e, e1 = _r[0], e2 = _r[1], _s = _r[2], e3 = _s === void 0 ? { b1: 1000, b4: 200 } : _s; +var _t = ({ f: [1, 2, { f3: 4, f5: 0 }] }).f, f1 = _t[0], f2 = _t[1], _u = _t[2], f4 = _u.f3, f5 = _u.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 _v = ({ g: { g1: [1, 2] } }).g.g1, g1 = _v === void 0 ? [undefined, null] : _v; +var _w = ({ h: { h1: [1, 2] } }).h.h1, h1 = _w === void 0 ? [undefined, null] : _w; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types new file mode 100644 index 0000000000..18966569d3 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.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, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>10 : number +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) +>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) +>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) +>[1, [["hello"]], true] : [number, [[string]], boolean] +>1 : number +>[["hello"]] : [[string]] +>["hello"] : [string] +>"hello" : string +>true : boolean + +// 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, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>{ b11: "string" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>{ b11: "world" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>true : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>3 : number +>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>true : boolean +>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] +>3 : number +>false : boolean +>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>false : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>3 : number +>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>true : boolean +>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) +>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 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) +>[1,2,3, "string"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>"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, Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) +>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) +>[1,"string"] : [number, string] +>1 : number +>"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[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) +>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.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 : any +>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) +>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) +>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>1000 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] +>1 : number +>2 : number +>{ b1: 4, b4: 0 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>4 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) +>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f3 : any +>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>1 : number +>2 : number +>{ f3: 4, f5: 0 } : { f3: number; f5: number; } +>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>4 : number +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) +>0 : number + +// 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[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.js b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js new file mode 100644 index 0000000000..53b888471a --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js @@ -0,0 +1,77 @@ +//// [destructuringVariableDeclaration1ES6.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] } }; + + + +//// [destructuringVariableDeclaration1ES6.js] +// 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: 10, a2: "world" }; +var [a3, [[a4]], a5] = [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: [1, 2] } }; +var { h: { h1 = [undefined, null] } } = { h: { h1: [1, 2] } }; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types new file mode 100644 index 0000000000..71e08134e6 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.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, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>10 : number +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) +>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) +>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) +>[1, [["hello"]], true] : [number, [[string]], boolean] +>1 : number +>[["hello"]] : [[string]] +>["hello"] : [string] +>"hello" : string +>true : boolean + +// 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, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>{ b11: "string" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>{ b11: "world" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>true : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>3 : number +>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>true : boolean +>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] +>3 : number +>false : boolean +>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>false : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>3 : number +>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>true : boolean +>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) +>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 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) +>[1,2,3, "string"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>"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, Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) +>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) +>[1,"string"] : [number, string] +>1 : number +>"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[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) +>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.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 : any +>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) +>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) +>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>1000 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] +>1 : number +>2 : number +>{ b1: 4, b4: 0 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>4 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) +>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f3 : any +>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>1 : number +>2 : number +>{ f3: 4, f5: 0 } : { f3: number; f5: number; } +>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>4 : number +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) +>0 : number + +// 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[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt new file mode 100644 index 0000000000..1a65583774 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt @@ -0,0 +1,62 @@ +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(3,5): error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'. + Types of property 'a1' are incompatible. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(4,5): error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'. + Types of property '1' are incompatible. + Type '[[boolean]]' is not assignable to type '[[string]]'. + Types of property '0' are incompatible. + Type '[boolean]' is not assignable to type '[string]'. + Types of property '0' are incompatible. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(9,25): error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'. + Types of property 't2' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,16): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,24): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(19,10): error TS2322: Type 'string[]' is not assignable to type 'number[]'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts (6 errors) ==== + // 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: true, a2: 1 } // Error + ~~~~~~~~ +!!! error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'. +!!! error TS2322: Types of property 'a1' are incompatible. +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type '[[boolean]]' is not assignable to type '[[string]]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type '[boolean]' is not assignable to type '[string]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + // 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 temp = { t1: true, t2: "false" }; + var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + ~~ +!!! error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'. +!!! error TS2322: Types of property 't2' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + // 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, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + ~~ +!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. + ~~ +!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. + + // 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 {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error + ~~ +!!! error TS2322: Type 'string[]' is not assignable to type 'number[]'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.js b/tests/baselines/reference/destructuringVariableDeclaration2.js new file mode 100644 index 0000000000..b3d4152892 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.js @@ -0,0 +1,38 @@ +//// [destructuringVariableDeclaration2.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: true, a2: 1 } // Error +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + +// 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 temp = { t1: true, t2: "false" }; +var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + +// 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, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + +// 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 {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error + +//// [destructuringVariableDeclaration2.js] +// 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: true, a2: 1 }, a1 = _a.a1, a2 = _a.a2; // Error +var _b = [1, [[false]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2]; // Error +// 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 temp = { t1: true, t2: "false" }; +var _c = [3, false, { t1: false, t2: 5 }], _d = _c[0], b0 = _d === void 0 ? 3 : _d, _e = _c[1], b1 = _e === void 0 ? true : _e, _f = _c[2], b2 = _f === void 0 ? temp : _f; // Error +// 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 _g = [1, 2, { c3: 4, c5: 0 }], c1 = _g[0], c2 = _g[1], _h = _g[2], c4 = _h.c3, c5 = _h.c5, c6 = _g.slice(4); // Error +// 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 _j = ({ d: { d1: [1, 2] } }).d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt deleted file mode 100644 index a455ee862c..0000000000 --- a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,23): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,33): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,44): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. - - -==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts (3 errors) ==== - var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; - var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; - var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; - ~~~ -!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. - ~~~ -!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js deleted file mode 100644 index b089d2ab4f..0000000000 --- a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js +++ /dev/null @@ -1,9 +0,0 @@ -//// [destructuringVariableDeclarationAndAssignment.ts] -var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; -var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; -var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; - -//// [destructuringVariableDeclarationAndAssignment.js] -var _a = ({ o: [1, 2, { b1: 4, b4: 0 }] }).o, a1 = _a[0], a2 = _a[1], _b = _a[2], a3 = _b === void 0 ? { b1: 1000, b4: 200 } : _b; -var _c = ({ o0: [1, 2, { e: 4, f: 0 }] }).o0, c = _c[0], d = _c[1], _d = _c[2], e1 = _d.e, f = _d.f; -var _e = ({ o1: [1, 2, { b12: 4, b42: 0 }] }).o1, a11 = _e[0], a21 = _e[1], _f = _e[2], b22 = _f.b12, b42 = _f.b42, c = _e.slice(4); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts deleted file mode 100644 index 4e6c46d267..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts +++ /dev/null @@ -1,22 +0,0 @@ -var [p0,p1, p2] : any = [2, 3, 4]; -var [a, b, c]: [number, number, string] = [1, 2, "string"]; -var [d, e]: any = undefined; -var [f = false, g = 1]: any = undefined; -g = 10; -f = true; - -var [x] = [] -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] -var [[w], m]: [[string|number], boolean] = [[1], true]; -interface J extends Array { - 2: number; -} - -var [, w1] = [1, 2, 3]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,,...w3] = [1, 2, 3, 4, "hello"]; - -var [r, s, ...t] = [1, 2, "string"]; -var [r1, s1, t1] = [1, 2, "string"]; - diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts new file mode 100644 index 0000000000..5b594e3cad --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts @@ -0,0 +1,52 @@ +/* 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/destructuringArrayBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts new file mode 100644 index 0000000000..9b631706bf --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts @@ -0,0 +1,53 @@ +// @target: es6 + +/* 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"]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts index 3b094541d3..bc5a2da176 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts @@ -1,13 +1,34 @@ -function foo() { - return [1, 2, 3]; -} +// 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]]] = [] // Error +var [[a2], [[a3]]] = undefined // Error + +// 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]: [number, boolean, string] = [1, 2, "string"]; // Error interface J extends Array { 2: number; } function bar(): J { - return <[number, number, number]>[1, 2, 3]; + return <[number, number, number]>[1, 2, 3]; +} +var [b3 = "string", b4, b5] = bar(); // Error + +// 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 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]: [number, number] = [...temp]; // Error +var [c2, c3]: [string, string] = [...temp]; // Error + +interface F { + [idx: number]: boolean } -var [j, k] = foo(); -var [...p] = foo(); +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts deleted file mode 100644 index 43f8c3546d..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts +++ /dev/null @@ -1,23 +0,0 @@ -interface H { - 0: number, - 1: string -} -interface J extends Array { - 2: number; -} - -function bar(): J { - return <[number, number, number]>[1, 2, 3]; -} - -function gg(idx: number) { - return { - [idx]: true - } -} - -var [h, g, i]: H = []; -var [[[y]], [[[[z]]]]] = [] -var [, , ...w4, , ] = [] -var [a = "string", b, c] = bar(); -var [r, s, t] = gg(1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts deleted file mode 100644 index f15541aaf9..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts +++ /dev/null @@ -1,12 +0,0 @@ -var c = 0; -var { a, } = { a:1, }; -var { b: { c } } = { b: { c } }; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; -var { d1 }: any = undefined; -var { e1 }: any = {}; -var { f: {f1} = { f1: "string" } }: any = {}; -var { f2: {f21} = { f21: "string" } }: any = undefined; -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; -var {g = 1}: any = { g: 100000 }; -var {1: x} = { 1: "string" }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts new file mode 100644 index 0000000000..e25a11ba5b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts @@ -0,0 +1,54 @@ +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts new file mode 100644 index 0000000000..a99b48d75d --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts @@ -0,0 +1,55 @@ +// @target: es6 +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts deleted file mode 100644 index 026c901dbe..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts +++ /dev/null @@ -1,46 +0,0 @@ -interface I { - j: number; - [str: string]: number; -} -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog", - } -} - -function zz1(): J { - return { - "cat": 1, - } -} - -function yy() { - return {} -} - -var {j}: I| J = { j: 1000 }; -var {cat} = zz(); -var {"cat":cart} = zz(); - -var {can}: J = {}; -var {can1}: J = zz1(); - - -function f() { - var { z }: { z: number } = { z }; -} - -interface K { - [idx: number]: boolean -} - -var {1: boo}: K = { 1: true }; -var {1: boo1}: K = { }; - -function bar(): K { - return { }; -} -var {1: baz} = bar(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts index 524728dc9d..2b3192bc9a 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -1,10 +1,10 @@ -var {h?} = { h?: 1 }; +// Error +var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; -var { d }: any; var { ...d1 } = { a: 1, b: 1, d1: 9, e: 10 } -var {1} = { 1 }; \ No newline at end of file +var {1} = { 1 }; +var {"prop"} = { "prop": 1 }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts deleted file mode 100644 index 3cb7ae0658..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts +++ /dev/null @@ -1,23 +0,0 @@ -interface K { - [str: string]: string; -} -interface K1 { - k: string; -} -var {k}: K|K1 = { k: "string" }; - -function barn() { - return {}; -} -var {2: baz1} = barn() - -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog" - } -} - -var {"can": can}: J = zz(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts new file mode 100644 index 0000000000..6121c00a78 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts @@ -0,0 +1,40 @@ +// 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/destructuringVariableDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts new file mode 100644 index 0000000000..dee06e000c --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts @@ -0,0 +1,41 @@ +// @target: es6 +// 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/destructuringVariableDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts new file mode 100644 index 0000000000..8ffd3bddd5 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts @@ -0,0 +1,19 @@ +// 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: true, a2: 1 } // Error +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + +// 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 temp = { t1: true, t2: "false" }; +var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + +// 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, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + +// 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 {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts deleted file mode 100644 index a3377dfb8f..0000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts +++ /dev/null @@ -1,3 +0,0 @@ -var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; -var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; -var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; \ No newline at end of file From 5ba01f3149c748dea0e295e51b77351447778fc3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 19:20:08 -0700 Subject: [PATCH 3/3] Update baselines from merging master --- ...ingArrayBindingPatternAndAssignment1ES5.js | 22 +-- ...rayBindingPatternAndAssignment1ES5.symbols | 105 ++++++++++++++ ...ArrayBindingPatternAndAssignment1ES5.types | 74 +++++----- ...rayBindingPatternAndAssignment1ES6.symbols | 105 ++++++++++++++ ...ArrayBindingPatternAndAssignment1ES6.types | 74 +++++----- ...ngObjectBindingPatternAndAssignment1ES5.js | 20 +-- ...ectBindingPatternAndAssignment1ES5.symbols | 101 ++++++++++++++ ...bjectBindingPatternAndAssignment1ES5.types | 66 ++++----- ...ectBindingPatternAndAssignment1ES6.symbols | 101 ++++++++++++++ ...bjectBindingPatternAndAssignment1ES6.types | 66 ++++----- ...uringObjectBindingPatternAndAssignment3.js | 14 +- .../destructuringVariableDeclaration1ES5.js | 18 +-- ...structuringVariableDeclaration1ES5.symbols | 114 ++++++++++++++++ ...destructuringVariableDeclaration1ES5.types | 128 +++++++++--------- ...structuringVariableDeclaration1ES6.symbols | 114 ++++++++++++++++ ...destructuringVariableDeclaration1ES6.types | 128 +++++++++--------- .../destructuringVariableDeclaration2.js | 2 +- 17 files changed, 946 insertions(+), 306 deletions(-) create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js index 6a94b0d2a7..bf71064264 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -85,16 +85,16 @@ function foo() { return [1, 2, 3]; } var _e = foo(), b6 = _e[0], b7 = _e[1]; -var _f = foo(), b8 = _f.slice(0); +var b8 = foo().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 _g = temp, c0 = _g[0], c1 = _g[1]; -var c2 = ([])[0]; -var _h = [[[]], [[[[]]]]], c3 = _h[0][0][0], c4 = _h[1][0][0][0][0]; -var _j = [[1], true], c5 = _j[0][0], c6 = _j[1]; -var _k = [1, 2, 3], c7 = _k[1]; -var _l = [1, 2, 3, 4], c8 = _l[3]; -var _m = [1, 2, 3, 4], c9 = _m[3]; -var _o = [1, 2, 3, 4, "hello"], c10 = _o.slice(3); -var _p = [1, 2, "string"], c11 = _p[0], c12 = _p[1], c13 = _p.slice(2); -var _q = [1, 2, "string"], c14 = _q[0], c15 = _q[1], c16 = _q[2]; +var _f = temp, c0 = _f[0], c1 = _f[1]; +var c2 = [][0]; +var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0]; +var _h = [[1], true], c5 = _h[0][0], c6 = _h[1]; +var _j = [1, 2, 3], c7 = _j[1]; +var _k = [1, 2, 3, 4], c8 = _k[3]; +var _l = [1, 2, 3, 4], c9 = _l[3]; +var _m = [1, 2, 3, 4, "hello"], c10 = _m.slice(3); +var _o = [1, 2, "string"], c11 = _o[0], c12 = _o[1], c13 = _o.slice(2); +var _p = [1, 2, "string"], c14 = _p[0], c15 = _p[1], c16 = _p[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 0000000000..d8e319f412 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.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; +>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>undefined : Symbol(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]; +>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +// 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] +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 6508581d89..bde9c867e2 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -23,40 +23,40 @@ // S is the type Any, or var [a0, a1]: any = undefined; ->a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) ->a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) ->undefined : undefined, Symbol(undefined) +>a0 : any +>a1 : any +>undefined : undefined var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>a2 : boolean >false : boolean ->a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>a3 : number >1 : number ->undefined : undefined, Symbol(undefined) +>undefined : 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]; ->b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) ->b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) ->b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) +>b0 : number +>b1 : number +>b2 : number >[2, 3, 4] : [number, number, number] >2 : number >3 : number >4 : number var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) ->b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) ->b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) +>b3 : number +>b4 : number +>b5 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number >"string" : string function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] return [1, 2, 3]; >[1, 2, 3] : number[] @@ -66,38 +66,38 @@ function foo() { } var [b6, b7] = foo(); ->b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) ->b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>b6 : number +>b7 : number >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] var [...b8] = foo(); ->b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>b8 : number[] >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] // 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] ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>temp : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [c0, c1] = [...temp]; ->c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) ->c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>c0 : number +>c1 : number >[...temp] : number[] >...temp : number ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>temp : number[] var [c2] = []; ->c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) +>c2 : any >[] : undefined[] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) ->c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) +>c3 : any +>c4 : any >[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] >[[]] : [undefined[]] >[] : undefined[] @@ -107,8 +107,8 @@ var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >[] : undefined[] var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) ->c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) +>c5 : string | number +>c6 : boolean >[[1], true] : [[number], boolean] >[1] : [number] >1 : number @@ -116,7 +116,7 @@ var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; > : undefined ->c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) +>c7 : number >[1, 2, 3] : [number, number, number] >1 : number >2 : number @@ -126,7 +126,7 @@ var [,,, c8] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) +>c8 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -137,7 +137,7 @@ var [,,, c9] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) +>c9 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -148,7 +148,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) +>c10 : (string | number)[] >[1, 2, 3, 4, "hello"] : (string | number)[] >1 : number >2 : number @@ -157,18 +157,18 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) ->c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) ->c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] >[1, 2, "string"] : (string | number)[] >1 : number >2 : number >"string" : string var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) ->c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) ->c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) +>c14 : number +>c15 : number +>c16 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 0000000000..33f9b4e88b --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.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; +>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>undefined : Symbol(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]; +>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +// 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] +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 4c999c9468..2d5d82c5ef 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -24,40 +24,40 @@ // S is the type Any, or var [a0, a1]: any = undefined; ->a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) ->a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) ->undefined : undefined, Symbol(undefined) +>a0 : any +>a1 : any +>undefined : undefined var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>a2 : boolean >false : boolean ->a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>a3 : number >1 : number ->undefined : undefined, Symbol(undefined) +>undefined : 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]; ->b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) ->b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) ->b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) +>b0 : number +>b1 : number +>b2 : number >[2, 3, 4] : [number, number, number] >2 : number >3 : number >4 : number var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) ->b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) ->b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) +>b3 : number +>b4 : number +>b5 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number >"string" : string function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] return [1, 2, 3]; >[1, 2, 3] : number[] @@ -67,38 +67,38 @@ function foo() { } var [b6, b7] = foo(); ->b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) ->b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>b6 : number +>b7 : number >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] var [...b8] = foo(); ->b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>b8 : number[] >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] // 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] ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>temp : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [c0, c1] = [...temp]; ->c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) ->c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>c0 : number +>c1 : number >[...temp] : number[] >...temp : number ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>temp : number[] var [c2] = []; ->c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) +>c2 : any >[] : undefined[] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) ->c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) +>c3 : any +>c4 : any >[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] >[[]] : [undefined[]] >[] : undefined[] @@ -108,8 +108,8 @@ var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >[] : undefined[] var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) ->c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) +>c5 : string | number +>c6 : boolean >[[1], true] : [[number], boolean] >[1] : [number] >1 : number @@ -117,7 +117,7 @@ var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; > : undefined ->c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) +>c7 : number >[1, 2, 3] : [number, number, number] >1 : number >2 : number @@ -127,7 +127,7 @@ var [,,, c8] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) +>c8 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -138,7 +138,7 @@ var [,,, c9] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) +>c9 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -149,7 +149,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) +>c10 : (string | number)[] >[1, 2, 3, 4, "hello"] : (string | number)[] >1 : number >2 : number @@ -158,18 +158,18 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) ->c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) ->c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] >[1, 2, "string"] : (string | number)[] >1 : number >2 : number >"string" : string var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) ->c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) ->c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) +>c14 : number +>c15 : number +>c16 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js index 2b12c2a54a..f201b17ded 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js @@ -60,15 +60,15 @@ var {"prop2": d1} = foo1(); // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var a1 = undefined.a1; -var a2 = ({}).a2; +var a2 = {}.a2; // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or -var b1 = ({ b1: 1 }).b1; -var _a = ({ b2: { b21: "world" } }).b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; -var b3 = ({ 1: "string" })[1]; -var _b = ({ b4: 100000 }).b4, b4 = _b === void 0 ? 1 : _b; -var b52 = ({ b5: { b52: b52 } }).b5.b52; +var b1 = { b1: 1 }.b1; +var _a = { b2: { b21: "world" } }.b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; +var b3 = { 1: "string" }[1]; +var _b = { b4: 100000 }.b4, b4 = _b === void 0 ? 1 : _b; +var b52 = { b5: { b52: b52 } }.b5.b52; function foo() { return { 1: true @@ -79,12 +79,12 @@ function bar() { 2: true }; } -var c0 = (foo())[1]; -var c1 = (bar())[1]; +var c0 = foo()[1]; +var c1 = bar()[1]; function foo1() { return { "prop1": 2 }; } -var d1 = (foo1())["prop1"]; -var d1 = (foo1())["prop2"]; +var d1 = foo1()["prop1"]; +var d1 = foo1()["prop2"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 0000000000..017a7f71e6 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts === +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index 3642f6c6ab..f44adab359 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -5,68 +5,68 @@ // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var { a1 }: any = undefined; ->a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) ->undefined : undefined, Symbol(undefined) +>a1 : any +>undefined : undefined var { a2 }: any = {}; ->a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) +>a2 : any >{} : {} // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or var { b1, } = { b1:1, }; ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>b1 : number >{ b1:1, } : { b1: number; } ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) +>b1 : number >1 : number var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >b2 : any ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>b21 : string >{ b21: "string" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>b21 : string >"string" : string >{ b2: { b21: "world" } } : { b2: { b21: string; }; } ->b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>b2 : { b21: string; } >{ b21: "world" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) +>b21 : string >"world" : string var {1: b3} = { 1: "string" }; ->b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) +>b3 : string >{ 1: "string" } : { 1: string; } >"string" : string var {b4 = 1}: any = { b4: 100000 }; ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>b4 : number >1 : number >{ b4: 100000 } : { b4: number; } ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) +>b4 : number >100000 : number var {b5: { b52 } } = { b5: { b52 } }; >b5 : any ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>b52 : any >{ b5: { b52 } } : { b5: { b52: any; }; } ->b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) +>b52 : any // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature // of a type that is assignable to the target given in P, or interface F { ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>F : F [idx: number]: boolean; ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +>idx : number } function foo(): F { ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>foo : () => F +>F : F return { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -78,8 +78,8 @@ function foo(): F { } function bar(): F { ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>bar : () => F +>F : F return { >{ 2: true } : { [x: number]: boolean; 2: boolean; } @@ -90,28 +90,28 @@ function bar(): F { }; } var {1: c0} = foo(); ->c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>c0 : boolean >foo() : F ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>foo : () => F var {1: c1} = bar(); ->c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>c1 : boolean >bar() : F ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>bar : () => F // V is an object assignment pattern and, for each assignment property P in V, // S has a string index signature of a type that is assignable to the target given in P interface F1 { ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) +>F1 : F1 [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +>str : string } function foo1(): F1 { ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) +>foo1 : () => F1 +>F1 : F1 return { >{ "prop1": 2 } : { [x: string]: number; "prop1": number; } @@ -122,12 +122,12 @@ function foo1(): F1 { } var {"prop1": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>foo1 : () => F1 var {"prop2": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>foo1 : () => F1 diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 0000000000..11289210ee --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts === +// 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 object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index afb24e6331..47d4474b63 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -5,68 +5,68 @@ // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var { a1 }: any = undefined; ->a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) ->undefined : undefined, Symbol(undefined) +>a1 : any +>undefined : undefined var { a2 }: any = {}; ->a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) +>a2 : any >{} : {} // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or var { b1, } = { b1:1, }; ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>b1 : number >{ b1:1, } : { b1: number; } ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) +>b1 : number >1 : number var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >b2 : any ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>b21 : string >{ b21: "string" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>b21 : string >"string" : string >{ b2: { b21: "world" } } : { b2: { b21: string; }; } ->b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>b2 : { b21: string; } >{ b21: "world" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) +>b21 : string >"world" : string var {1: b3} = { 1: "string" }; ->b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) +>b3 : string >{ 1: "string" } : { 1: string; } >"string" : string var {b4 = 1}: any = { b4: 100000 }; ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>b4 : number >1 : number >{ b4: 100000 } : { b4: number; } ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) +>b4 : number >100000 : number var {b5: { b52 } } = { b5: { b52 } }; >b5 : any ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>b52 : any >{ b5: { b52 } } : { b5: { b52: any; }; } ->b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) +>b52 : any // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature // of a type that is assignable to the target given in P, or interface F { ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>F : F [idx: number]: boolean; ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +>idx : number } function foo(): F { ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>foo : () => F +>F : F return { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -78,8 +78,8 @@ function foo(): F { } function bar(): F { ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>bar : () => F +>F : F return { >{ 2: true } : { [x: number]: boolean; 2: boolean; } @@ -90,28 +90,28 @@ function bar(): F { }; } var {1: c0} = foo(); ->c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>c0 : boolean >foo() : F ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>foo : () => F var {1: c1} = bar(); ->c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>c1 : boolean >bar() : F ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>bar : () => F // V is an object assignment pattern and, for each assignment property P in V, // S has a string index signature of a type that is assignable to the target given in P interface F1 { ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) +>F1 : F1 [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +>str : string } function foo1(): F1 { ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) +>foo1 : () => F1 +>F1 : F1 return { >{ "prop1": 2 } : { [x: string]: number; "prop1": number; } @@ -122,12 +122,12 @@ function foo1(): F1 { } var {"prop1": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>foo1 : () => F1 var {"prop2": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>foo1 : () => F1 diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js index 3c617ec9b8..77288e6a54 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -12,12 +12,12 @@ var {"prop"} = { "prop": 1 }; //// [destructuringObjectBindingPatternAndAssignment3.js] // Error -var h = ({ h: 1 }).h; -var i = ({ i: 2 }).i; -var i1 = ({ i1: 2 }).i1; +var h = { h: 1 }.h; +var i = { i: 2 }.i; +var i1 = { i1: 2 }.i1; var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; -var d1 = ({ +var d1 = { a: 1, b: 1, d1: 9, e: 10 -}).d1; -var = ({ 1: })[1]; -var = ({ "prop": 1 })["prop"]; +}.d1; +var = { 1: }[1]; +var = { "prop": 1 }["prop"]; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js index 2d1f0c101b..6d731538d1 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -48,30 +48,30 @@ var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2; var _b = [1, [["hello"]], true], a3 = _b[0], a4 = _b[1][0][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 _c = ({ b1: { b11: "world" } }).b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; +var _c = { b1: { b11: "world" } }.b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; var temp = { t1: true, t2: "false" }; var _d = [3, false, { t1: false, t2: "hello" }], _e = _d[0], b2 = _e === void 0 ? 3 : _e, _f = _d[1], b3 = _f === void 0 ? true : _f, _g = _d[2], b4 = _g === void 0 ? temp : _g; var _h = [undefined, undefined, undefined], _j = _h[0], b5 = _j === void 0 ? 3 : _j, _k = _h[1], b6 = _k === void 0 ? true : _k, _l = _h[2], b7 = _l === void 0 ? temp : _l; // 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 _m = [1, 2, 3], c1 = _m.slice(0); -var _o = [1, 2, 3, "string"], c2 = _o.slice(0); +var c1 = [1, 2, 3].slice(0); +var c2 = [1, 2, 3, "string"].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 _p = [1, "string"], d1 = _p[0], d2 = _p[1]; +var _m = [1, "string"], d1 = _m[0], d2 = _m[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 _q = [1, "string"].concat(temp1), d3 = _q[0], d4 = _q[1]; +var _o = [1, "string"].concat(temp1), d3 = _o[0], d4 = _o[1]; // Combining both forms of destructuring, -var _r = ({ e: [1, 2, { b1: 4, b4: 0 }] }).e, e1 = _r[0], e2 = _r[1], _s = _r[2], e3 = _s === void 0 ? { b1: 1000, b4: 200 } : _s; -var _t = ({ f: [1, 2, { f3: 4, f5: 0 }] }).f, f1 = _t[0], f2 = _t[1], _u = _t[2], f4 = _u.f3, f5 = _u.f5; +var _p = { e: [1, 2, { b1: 4, b4: 0 }] }.e, e1 = _p[0], e2 = _p[1], _q = _p[2], e3 = _q === void 0 ? { b1: 1000, b4: 200 } : _q; +var _r = { f: [1, 2, { f3: 4, f5: 0 }] }.f, f1 = _r[0], f2 = _r[1], _s = _r[2], f4 = _s.f3, f5 = _s.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 _v = ({ g: { g1: [1, 2] } }).g.g1, g1 = _v === void 0 ? [undefined, null] : _v; -var _w = ({ h: { h1: [1, 2] } }).h.h1, h1 = _w === void 0 ? [undefined, null] : _w; +var _t = { g: { g1: [1, 2] } }.g.g1, g1 = _t === void 0 ? [undefined, null] : _t; +var _u = { h: { h1: [1, 2] } }.h.h1, h1 = _u === void 0 ? [undefined, null] : _u; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols new file mode 100644 index 0000000000..2a2f2a358c --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols @@ -0,0 +1,114 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.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(destructuringVariableDeclaration1ES5.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES5.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" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.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(destructuringVariableDeclaration1ES5.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES5.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(destructuringVariableDeclaration1ES5.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES5.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(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.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] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index 18966569d3..ef3507f0f8 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -2,20 +2,20 @@ // 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, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>a1 : number +>a2 : string +>a1 : number +>a2 : string >{ a1: 10, a2: "world" } : { a1: number; a2: string; } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>a1 : number >10 : number ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) +>a2 : string >"world" : string var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; ->a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) ->a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) ->a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) +>a3 : number +>a4 : string +>a5 : boolean >[1, [["hello"]], true] : [number, [[string]], boolean] >1 : number >[["hello"]] : [[string]] @@ -27,64 +27,64 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // 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, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>b11 : string >{ b11: "string" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>b11 : string >"string" : string >{ b1: { b11: "world" } } : { b1: { b11: string; }; } ->b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>b1 : { b11: string; } >{ b11: "world" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) +>b11 : string >"world" : string var temp = { t1: true, t2: "false" }; ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>temp : { t1: boolean; t2: string; } >{ t1: true, t2: "false" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>t1 : boolean >true : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) +>t2 : string >"false" : string var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; ->b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>b2 : number >3 : number ->b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>b3 : boolean >true : boolean ->b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } >[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] >3 : number >false : boolean >{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>t1 : boolean >false : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) +>t2 : string >"hello" : string var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; ->b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>b5 : any >3 : number ->b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>b6 : any >true : boolean ->b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>b7 : any +>temp : { t1: boolean; t2: string; } >[undefined, undefined, undefined] : [undefined, undefined, undefined] ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(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[], Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) +>c1 : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) +>c2 : (string | number)[] >[1,2,3, "string"] : (string | number)[] >1 : number >2 : number @@ -96,8 +96,8 @@ var [...c2] = [1,2,3, "string"]; // 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, Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) ->d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) +>d1 : number +>d2 : string >[1,"string"] : [number, string] >1 : number >"string" : string @@ -106,60 +106,60 @@ var [d1,d2] = [1,"string"] // 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[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>temp1 : boolean[] >[true, false, true] : boolean[] >true : boolean >false : boolean >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) ->d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>d3 : string | number | boolean +>d4 : string | number | boolean >[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>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, Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) ->e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) ->e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>e1 : number +>e2 : number +>e3 : { b1: number; b4: number; } >{ b1: 1000, b4: 200 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>b1 : number >1000 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>b4 : number >200 : number >{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } ->e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>e : [number, number, { b1: number; b4: number; }] >[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] >1 : number >2 : number >{ b1: 4, b4: 0 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>b1 : number >4 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) +>b4 : number >0 : number var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f : any ->f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) ->f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f1 : number +>f2 : number >f3 : any ->f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +>f4 : number +>f5 : number > : undefined >{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>f : [number, number, { f3: number; f5: number; }] >[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } ->f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>f3 : number >4 : number ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) +>f5 : number >0 : number // When a destructuring variable declaration, binding property, or binding element specifies @@ -167,32 +167,32 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // 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[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>g1 : any[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>g : { g1: any[]; } +>g1 : any[] >{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } ->g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>g : { g1: number[]; } >{ g1: [1, 2] } : { g1: number[]; } ->g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) +>g1 : number[] >[1, 2] : number[] >1 : number >2 : number var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; >h : any ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>h1 : number[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>h : { h1: number[]; } +>h1 : number[] >{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>h : { h1: number[]; } >{ h1: [1, 2] } : { h1: number[]; } ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) +>h1 : number[] >[1, 2] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols new file mode 100644 index 0000000000..0350ff3525 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols @@ -0,0 +1,114 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.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(destructuringVariableDeclaration1ES6.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES6.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" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.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(destructuringVariableDeclaration1ES6.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES6.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(destructuringVariableDeclaration1ES6.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES6.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(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.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] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index 71e08134e6..d62574c28f 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -2,20 +2,20 @@ // 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, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>a1 : number +>a2 : string +>a1 : number +>a2 : string >{ a1: 10, a2: "world" } : { a1: number; a2: string; } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>a1 : number >10 : number ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) +>a2 : string >"world" : string var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; ->a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) ->a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) ->a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) +>a3 : number +>a4 : string +>a5 : boolean >[1, [["hello"]], true] : [number, [[string]], boolean] >1 : number >[["hello"]] : [[string]] @@ -27,64 +27,64 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // 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, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>b11 : string >{ b11: "string" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>b11 : string >"string" : string >{ b1: { b11: "world" } } : { b1: { b11: string; }; } ->b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>b1 : { b11: string; } >{ b11: "world" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) +>b11 : string >"world" : string var temp = { t1: true, t2: "false" }; ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>temp : { t1: boolean; t2: string; } >{ t1: true, t2: "false" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>t1 : boolean >true : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) +>t2 : string >"false" : string var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; ->b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>b2 : number >3 : number ->b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>b3 : boolean >true : boolean ->b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } >[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] >3 : number >false : boolean >{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>t1 : boolean >false : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) +>t2 : string >"hello" : string var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; ->b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>b5 : any >3 : number ->b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>b6 : any >true : boolean ->b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>b7 : any +>temp : { t1: boolean; t2: string; } >[undefined, undefined, undefined] : [undefined, undefined, undefined] ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(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[], Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) +>c1 : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) +>c2 : (string | number)[] >[1,2,3, "string"] : (string | number)[] >1 : number >2 : number @@ -96,8 +96,8 @@ var [...c2] = [1,2,3, "string"]; // 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, Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) ->d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) +>d1 : number +>d2 : string >[1,"string"] : [number, string] >1 : number >"string" : string @@ -106,60 +106,60 @@ var [d1,d2] = [1,"string"] // 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[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>temp1 : boolean[] >[true, false, true] : boolean[] >true : boolean >false : boolean >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) ->d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>d3 : string | number | boolean +>d4 : string | number | boolean >[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>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, Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) ->e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) ->e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>e1 : number +>e2 : number +>e3 : { b1: number; b4: number; } >{ b1: 1000, b4: 200 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>b1 : number >1000 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>b4 : number >200 : number >{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } ->e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>e : [number, number, { b1: number; b4: number; }] >[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] >1 : number >2 : number >{ b1: 4, b4: 0 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>b1 : number >4 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) +>b4 : number >0 : number var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f : any ->f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) ->f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f1 : number +>f2 : number >f3 : any ->f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +>f4 : number +>f5 : number > : undefined >{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>f : [number, number, { f3: number; f5: number; }] >[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } ->f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>f3 : number >4 : number ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) +>f5 : number >0 : number // When a destructuring variable declaration, binding property, or binding element specifies @@ -167,32 +167,32 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // 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[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>g1 : any[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>g : { g1: any[]; } +>g1 : any[] >{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } ->g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>g : { g1: number[]; } >{ g1: [1, 2] } : { g1: number[]; } ->g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) +>g1 : number[] >[1, 2] : number[] >1 : number >2 : number var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; >h : any ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>h1 : number[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>h : { h1: number[]; } +>h1 : number[] >{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>h : { h1: number[]; } >{ h1: [1, 2] } : { h1: number[]; } ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) +>h1 : number[] >[1, 2] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.js b/tests/baselines/reference/destructuringVariableDeclaration2.js index b3d4152892..a4fadd850d 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.js +++ b/tests/baselines/reference/destructuringVariableDeclaration2.js @@ -35,4 +35,4 @@ var _g = [1, 2, { c3: 4, c5: 0 }], c1 = _g[0], c2 = _g[1], _h = _g[2], c4 = _h.c // 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 _j = ({ d: { d1: [1, 2] } }).d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error +var _j = { d: { d1: [1, 2] } }.d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error