Add tests for object literals with computed properties

This commit is contained in:
Jason Freeman
2015-01-12 14:04:34 -08:00
parent 7192767a00
commit 4ac2b4b9c8
18 changed files with 336 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
//// [computedPropertyNames4.ts]
var s: string;
var n: number;
var a: any;
var v = {
[s]: 0,
[n]: n,
[s + s]: 1,
[s + n]: 2,
[+s]: s,
[""]: 0,
[0]: 0,
[a]: 1,
[<any>true]: 0,
[`hello bye`]: 0,
[`hello ${a} bye`]: 0
}
//// [computedPropertyNames4.js]
var s;
var n;
var a;
var v = {
[s]: 0,
[n]: n,
[s + s]: 1,
[s + n]: 2,
[+s]: s,
[""]: 0,
[0]: 0,
[a]: 1,
[true]: 0,
[`hello bye`]: 0,
[`hello ${a} bye`]: 0
};

View File

@@ -0,0 +1,48 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts ===
var s: string;
>s : string
var n: number;
>n : number
var a: any;
>a : any
var v = {
>v : {}
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : {}
[s]: 0,
>s : string
[n]: n,
>n : number
>n : number
[s + s]: 1,
>s + s : string
>s : string
>s : string
[s + n]: 2,
>s + n : string
>s : string
>n : number
[+s]: s,
>+s : number
>s : string
>s : string
[""]: 0,
[0]: 0,
[a]: 1,
>a : any
[<any>true]: 0,
><any>true : any
[`hello bye`]: 0,
[`hello ${a} bye`]: 0
>a : any
}

View File

@@ -0,0 +1,30 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(4,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts (6 errors) ====
var b: boolean;
var v = {
[b]: 0,
~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[true]: 1,
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[[]]: 0,
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[{}]: 0,
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[undefined]: undefined,
~~~~~~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[null]: null
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View File

@@ -0,0 +1,21 @@
//// [computedPropertyNames5.ts]
var b: boolean;
var v = {
[b]: 0,
[true]: 1,
[[]]: 0,
[{}]: 0,
[undefined]: undefined,
[null]: null
}
//// [computedPropertyNames5.js]
var b;
var v = {
[b]: 0,
[true]: 1,
[[]]: 0,
[{}]: 0,
[undefined]: undefined,
[null]: null
};

View File

@@ -0,0 +1,20 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (3 errors) ====
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
var v = {
[p1]: 0,
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[p2]: 1,
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[p3]: 2
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View File

@@ -0,0 +1,19 @@
//// [computedPropertyNames6.ts]
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
var v = {
[p1]: 0,
[p2]: 1,
[p3]: 2
}
//// [computedPropertyNames6.js]
var p1;
var p2;
var p3;
var v = {
[p1]: 0,
[p2]: 1,
[p3]: 2
};

View File

@@ -0,0 +1,12 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts (1 errors) ====
enum E {
member
}
var v = {
[E.member]: 0
~~~~~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View File

@@ -0,0 +1,16 @@
//// [computedPropertyNames7.ts]
enum E {
member
}
var v = {
[E.member]: 0
}
//// [computedPropertyNames7.js]
var E;
(function (E) {
E[E["member"] = 0] = "member";
})(E || (E = {}));
var v = {
[0 /* member */]: 0
};

View File

@@ -0,0 +1,17 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts (2 errors) ====
function f<T, U extends string>() {
var t: T;
var u: U;
var v = {
[t]: 0,
~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[u]: 1
~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
};
}

View File

@@ -0,0 +1,19 @@
//// [computedPropertyNames8.ts]
function f<T, U extends string>() {
var t: T;
var u: U;
var v = {
[t]: 0,
[u]: 1
};
}
//// [computedPropertyNames8.js]
function f() {
var t;
var u;
var v = {
[t]: 0,
[u]: 1
};
}

View File

@@ -0,0 +1,16 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts (1 errors) ====
function f(s: string): string;
function f(n: number): number;
function f<T>(x: T): T;
function f(x): any { }
var v = {
[f("")]: 0,
[f(0)]: 0,
[f(true)]: 0
~~~~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View File

@@ -0,0 +1,20 @@
//// [computedPropertyNames9.ts]
function f(s: string): string;
function f(n: number): number;
function f<T>(x: T): T;
function f(x): any { }
var v = {
[f("")]: 0,
[f(0)]: 0,
[f(true)]: 0
}
//// [computedPropertyNames9.js]
function f(x) {
}
var v = {
[f("")]: 0,
[f(0)]: 0,
[f(true)]: 0
};

View File

@@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
var v = {
[s]: 0,
[n]: n,
[s + s]: 1,
[s + n]: 2,
[+s]: s,
[""]: 0,
[0]: 0,
[a]: 1,
[<any>true]: 0,
[`hello bye`]: 0,
[`hello ${a} bye`]: 0
}

View File

@@ -0,0 +1,10 @@
// @target: es6
var b: boolean;
var v = {
[b]: 0,
[true]: 1,
[[]]: 0,
[{}]: 0,
[undefined]: undefined,
[null]: null
}

View File

@@ -0,0 +1,9 @@
// @target: es6
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
var v = {
[p1]: 0,
[p2]: 1,
[p3]: 2
}

View File

@@ -0,0 +1,7 @@
// @target: es6
enum E {
member
}
var v = {
[E.member]: 0
}

View File

@@ -0,0 +1,9 @@
// @target: es6
function f<T, U extends string>() {
var t: T;
var u: U;
var v = {
[t]: 0,
[u]: 1
};
}

View File

@@ -0,0 +1,11 @@
// @target: es6
function f(s: string): string;
function f(n: number): number;
function f<T>(x: T): T;
function f(x): any { }
var v = {
[f("")]: 0,
[f(0)]: 0,
[f(true)]: 0
}