Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conformance test spec change in section 4.17.1 destructuring assignment and 5.1.2 variable declaration conformance tests #2773

Merged
merged 4 commits into from
May 4, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Number> {
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];
Original file line number Diff line number Diff line change
@@ -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<Number> {
>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


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [destructuringArrayBindingPatternAndAssignment2.ts]
function foo() {
return [1, 2, 3];
}
interface J extends Array<Number> {
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);
Original file line number Diff line number Diff line change
@@ -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<Number> {
>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))

Original file line number Diff line number Diff line change
@@ -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<Number> {
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I always forget whether or not we display the undefined type in errors.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//// [destructuringArrayBindingPatternAndAssignment3.ts]
interface H {
0: number,
1: string
}
interface J extends Array<Number> {
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];
Original file line number Diff line number Diff line change
@@ -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];
Loading