Skip to content

Commit bbe51cf

Browse files
committed
Adding tests
1 parent 2494b2d commit bbe51cf

File tree

6 files changed

+583
-0
lines changed

6 files changed

+583
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
tests/cases/conformance/expressions/functionCalls/callWithSpread.ts(52,21): error TS2468: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.
2+
3+
4+
==== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts (1 errors) ====
5+
interface X {
6+
foo(x: number, y: number, ...z: string[]);
7+
}
8+
9+
function foo(x: number, y: number, ...z: string[]) {
10+
}
11+
12+
var a: string[];
13+
var z: number[];
14+
var obj: X;
15+
var xa: X[];
16+
17+
foo(1, 2, "abc");
18+
foo(1, 2, ...a);
19+
foo(1, 2, ...a, "abc");
20+
21+
obj.foo(1, 2, "abc");
22+
obj.foo(1, 2, ...a);
23+
obj.foo(1, 2, ...a, "abc");
24+
25+
(obj.foo)(1, 2, "abc");
26+
(obj.foo)(1, 2, ...a);
27+
(obj.foo)(1, 2, ...a, "abc");
28+
29+
xa[1].foo(1, 2, "abc");
30+
xa[1].foo(1, 2, ...a);
31+
xa[1].foo(1, 2, ...a, "abc");
32+
33+
(<Function>xa[1].foo)(...[1, 2, "abc"]);
34+
35+
class C {
36+
constructor(x: number, y: number, ...z: string[]) {
37+
this.foo(x, y);
38+
this.foo(x, y, ...z);
39+
}
40+
foo(x: number, y: number, ...z: string[]) {
41+
}
42+
}
43+
44+
class D extends C {
45+
constructor() {
46+
super(1, 2);
47+
super(1, 2, ...a);
48+
}
49+
foo() {
50+
super.foo(1, 2);
51+
super.foo(1, 2, ...a);
52+
}
53+
}
54+
55+
// Only supported in when target is ES6
56+
var c = new C(1, 2, ...a);
57+
~~~~
58+
!!! error TS2468: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.
59+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//// [callWithSpread.ts]
2+
interface X {
3+
foo(x: number, y: number, ...z: string[]);
4+
}
5+
6+
function foo(x: number, y: number, ...z: string[]) {
7+
}
8+
9+
var a: string[];
10+
var z: number[];
11+
var obj: X;
12+
var xa: X[];
13+
14+
foo(1, 2, "abc");
15+
foo(1, 2, ...a);
16+
foo(1, 2, ...a, "abc");
17+
18+
obj.foo(1, 2, "abc");
19+
obj.foo(1, 2, ...a);
20+
obj.foo(1, 2, ...a, "abc");
21+
22+
(obj.foo)(1, 2, "abc");
23+
(obj.foo)(1, 2, ...a);
24+
(obj.foo)(1, 2, ...a, "abc");
25+
26+
xa[1].foo(1, 2, "abc");
27+
xa[1].foo(1, 2, ...a);
28+
xa[1].foo(1, 2, ...a, "abc");
29+
30+
(<Function>xa[1].foo)(...[1, 2, "abc"]);
31+
32+
class C {
33+
constructor(x: number, y: number, ...z: string[]) {
34+
this.foo(x, y);
35+
this.foo(x, y, ...z);
36+
}
37+
foo(x: number, y: number, ...z: string[]) {
38+
}
39+
}
40+
41+
class D extends C {
42+
constructor() {
43+
super(1, 2);
44+
super(1, 2, ...a);
45+
}
46+
foo() {
47+
super.foo(1, 2);
48+
super.foo(1, 2, ...a);
49+
}
50+
}
51+
52+
// Only supported in when target is ES6
53+
var c = new C(1, 2, ...a);
54+
55+
56+
//// [callWithSpread.js]
57+
var __extends = this.__extends || function (d, b) {
58+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
59+
function __() { this.constructor = d; }
60+
__.prototype = b.prototype;
61+
d.prototype = new __();
62+
};
63+
function foo(x, y) {
64+
var z = [];
65+
for (var _i = 2; _i < arguments.length; _i++) {
66+
z[_i - 2] = arguments[_i];
67+
}
68+
}
69+
var a;
70+
var z;
71+
var obj;
72+
var xa;
73+
foo(1, 2, "abc");
74+
foo.apply(void 0, [1, 2].concat(a));
75+
foo.apply(void 0, [1, 2].concat(a, ["abc"]));
76+
obj.foo(1, 2, "abc");
77+
obj.foo.apply(obj, [1, 2].concat(a));
78+
obj.foo.apply(obj, [1, 2].concat(a, ["abc"]));
79+
(obj.foo)(1, 2, "abc");
80+
obj.foo.apply(obj, [1, 2].concat(a));
81+
obj.foo.apply(obj, [1, 2].concat(a, ["abc"]));
82+
xa[1].foo(1, 2, "abc");
83+
(_a = xa[1]).foo.apply(_a, [1, 2].concat(a));
84+
(_b = xa[1]).foo.apply(_b, [1, 2].concat(a, ["abc"]));
85+
(_c = xa[1]).foo.apply(_c, [1, 2, "abc"]);
86+
var C = (function () {
87+
function C(x, y) {
88+
var z = [];
89+
for (var _i = 2; _i < arguments.length; _i++) {
90+
z[_i - 2] = arguments[_i];
91+
}
92+
this.foo(x, y);
93+
this.foo.apply(this, [x, y].concat(z));
94+
}
95+
C.prototype.foo = function (x, y) {
96+
var z = [];
97+
for (var _i = 2; _i < arguments.length; _i++) {
98+
z[_i - 2] = arguments[_i];
99+
}
100+
};
101+
return C;
102+
})();
103+
var D = (function (_super) {
104+
__extends(D, _super);
105+
function D() {
106+
_super.call(this, 1, 2);
107+
_super.apply(this, [1, 2].concat(a));
108+
}
109+
D.prototype.foo = function () {
110+
_super.prototype.foo.call(this, 1, 2);
111+
_super.prototype.foo.apply(this, [1, 2].concat(a));
112+
};
113+
return D;
114+
})(C);
115+
// Only supported in when target is ES6
116+
var c = new C(1, 2, ...a);
117+
var _a, _b, _c;
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//// [callWithSpreadES6.ts]
2+
3+
interface X {
4+
foo(x: number, y: number, ...z: string[]);
5+
}
6+
7+
function foo(x: number, y: number, ...z: string[]) {
8+
}
9+
10+
var a: string[];
11+
var z: number[];
12+
var obj: X;
13+
var xa: X[];
14+
15+
foo(1, 2, "abc");
16+
foo(1, 2, ...a);
17+
foo(1, 2, ...a, "abc");
18+
19+
obj.foo(1, 2, "abc");
20+
obj.foo(1, 2, ...a);
21+
obj.foo(1, 2, ...a, "abc");
22+
23+
(obj.foo)(1, 2, "abc");
24+
(obj.foo)(1, 2, ...a);
25+
(obj.foo)(1, 2, ...a, "abc");
26+
27+
xa[1].foo(1, 2, "abc");
28+
xa[1].foo(1, 2, ...a);
29+
xa[1].foo(1, 2, ...a, "abc");
30+
31+
(<Function>xa[1].foo)(...[1, 2, "abc"]);
32+
33+
class C {
34+
constructor(x: number, y: number, ...z: string[]) {
35+
this.foo(x, y);
36+
this.foo(x, y, ...z);
37+
}
38+
foo(x: number, y: number, ...z: string[]) {
39+
}
40+
}
41+
42+
class D extends C {
43+
constructor() {
44+
super(1, 2);
45+
super(1, 2, ...a);
46+
}
47+
foo() {
48+
super.foo(1, 2);
49+
super.foo(1, 2, ...a);
50+
}
51+
}
52+
53+
// Only supported in when target is ES6
54+
var c = new C(1, 2, ...a);
55+
56+
57+
//// [callWithSpreadES6.js]
58+
var __extends = this.__extends || function (d, b) {
59+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
60+
function __() { this.constructor = d; }
61+
__.prototype = b.prototype;
62+
d.prototype = new __();
63+
};
64+
function foo(x, y, ...z) {
65+
}
66+
var a;
67+
var z;
68+
var obj;
69+
var xa;
70+
foo(1, 2, "abc");
71+
foo(1, 2, ...a);
72+
foo(1, 2, ...a, "abc");
73+
obj.foo(1, 2, "abc");
74+
obj.foo(1, 2, ...a);
75+
obj.foo(1, 2, ...a, "abc");
76+
(obj.foo)(1, 2, "abc");
77+
(obj.foo)(1, 2, ...a);
78+
(obj.foo)(1, 2, ...a, "abc");
79+
xa[1].foo(1, 2, "abc");
80+
xa[1].foo(1, 2, ...a);
81+
xa[1].foo(1, 2, ...a, "abc");
82+
xa[1].foo(...[1, 2, "abc"]);
83+
var C = (function () {
84+
function C(x, y, ...z) {
85+
this.foo(x, y);
86+
this.foo(x, y, ...z);
87+
}
88+
C.prototype.foo = function (x, y, ...z) {
89+
};
90+
return C;
91+
})();
92+
var D = (function (_super) {
93+
__extends(D, _super);
94+
function D() {
95+
_super.call(this, 1, 2);
96+
_super.call(this, 1, 2, ...a);
97+
}
98+
D.prototype.foo = function () {
99+
_super.prototype.foo.call(this, 1, 2);
100+
_super.prototype.foo.call(this, 1, 2, ...a);
101+
};
102+
return D;
103+
})(C);
104+
// Only supported in when target is ES6
105+
var c = new C(1, 2, ...a);

0 commit comments

Comments
 (0)