Skip to content

Commit 778c91e

Browse files
author
Yui
committed
Merge pull request #1604 from Microsoft/addTestsForRestAndDefault
Add tests for rest and default
2 parents 8dd81ea + 6d678b7 commit 778c91e

File tree

48 files changed

+1069
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1069
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [emitDefaultParametersFunction.ts]
2+
function foo(x: string, y = 10) { }
3+
function baz(x: string, y = 5, ...rest) { }
4+
function bar(y = 10) { }
5+
function bar1(y = 10, ...rest) { }
6+
7+
//// [emitDefaultParametersFunction.js]
8+
function foo(x, y) {
9+
if (y === void 0) { y = 10; }
10+
}
11+
function baz(x, y) {
12+
if (y === void 0) { y = 5; }
13+
var rest = [];
14+
for (var _i = 2; _i < arguments.length; _i++) {
15+
rest[_i - 2] = arguments[_i];
16+
}
17+
}
18+
function bar(y) {
19+
if (y === void 0) { y = 10; }
20+
}
21+
function bar1(y) {
22+
if (y === void 0) { y = 10; }
23+
var rest = [];
24+
for (var _i = 1; _i < arguments.length; _i++) {
25+
rest[_i - 1] = arguments[_i];
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunction.ts ===
2+
function foo(x: string, y = 10) { }
3+
>foo : (x: string, y?: number) => void
4+
>x : string
5+
>y : number
6+
7+
function baz(x: string, y = 5, ...rest) { }
8+
>baz : (x: string, y?: number, ...rest: any[]) => void
9+
>x : string
10+
>y : number
11+
>rest : any[]
12+
13+
function bar(y = 10) { }
14+
>bar : (y?: number) => void
15+
>y : number
16+
17+
function bar1(y = 10, ...rest) { }
18+
>bar1 : (y?: number, ...rest: any[]) => void
19+
>y : number
20+
>rest : any[]
21+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [emitDefaultParametersFunctionES6.ts]
2+
function foo(x: string, y = 10) { }
3+
function baz(x: string, y = 5, ...rest) { }
4+
function bar(y = 10) { }
5+
function bar1(y = 10, ...rest) { }
6+
7+
//// [emitDefaultParametersFunctionES6.js]
8+
function foo(x, y = 10) {
9+
}
10+
function baz(x, y = 5, ...rest) {
11+
}
12+
function bar(y = 10) {
13+
}
14+
function bar1(y = 10, ...rest) {
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionES6.ts ===
2+
function foo(x: string, y = 10) { }
3+
>foo : (x: string, y?: number) => void
4+
>x : string
5+
>y : number
6+
7+
function baz(x: string, y = 5, ...rest) { }
8+
>baz : (x: string, y?: number, ...rest: any[]) => void
9+
>x : string
10+
>y : number
11+
>rest : any[]
12+
13+
function bar(y = 10) { }
14+
>bar : (y?: number) => void
15+
>y : number
16+
17+
function bar1(y = 10, ...rest) { }
18+
>bar1 : (y?: number, ...rest: any[]) => void
19+
>y : number
20+
>rest : any[]
21+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [emitDefaultParametersFunctionExpression.ts]
2+
var lambda1 = (y = "hello") => { }
3+
var lambda2 = (x: number, y = "hello") => { }
4+
var lambda3 = (x: number, y = "hello", ...rest) => { }
5+
var lambda4 = (y = "hello", ...rest) => { }
6+
7+
var x = function (str = "hello", ...rest) { }
8+
var y = (function (num = 10, boo = false, ...rest) { })()
9+
var z = (function (num: number, boo = false, ...rest) { })(10)
10+
11+
12+
//// [emitDefaultParametersFunctionExpression.js]
13+
var lambda1 = function (y) {
14+
if (y === void 0) { y = "hello"; }
15+
};
16+
var lambda2 = function (x, y) {
17+
if (y === void 0) { y = "hello"; }
18+
};
19+
var lambda3 = function (x, y) {
20+
if (y === void 0) { y = "hello"; }
21+
var rest = [];
22+
for (var _i = 2; _i < arguments.length; _i++) {
23+
rest[_i - 2] = arguments[_i];
24+
}
25+
};
26+
var lambda4 = function (y) {
27+
if (y === void 0) { y = "hello"; }
28+
var rest = [];
29+
for (var _i = 1; _i < arguments.length; _i++) {
30+
rest[_i - 1] = arguments[_i];
31+
}
32+
};
33+
var x = function (str) {
34+
if (str === void 0) { str = "hello"; }
35+
var rest = [];
36+
for (var _i = 1; _i < arguments.length; _i++) {
37+
rest[_i - 1] = arguments[_i];
38+
}
39+
};
40+
var y = (function (num, boo) {
41+
if (num === void 0) { num = 10; }
42+
if (boo === void 0) { boo = false; }
43+
var rest = [];
44+
for (var _i = 2; _i < arguments.length; _i++) {
45+
rest[_i - 2] = arguments[_i];
46+
}
47+
})();
48+
var z = (function (num, boo) {
49+
if (boo === void 0) { boo = false; }
50+
var rest = [];
51+
for (var _i = 2; _i < arguments.length; _i++) {
52+
rest[_i - 2] = arguments[_i];
53+
}
54+
})(10);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpression.ts ===
2+
var lambda1 = (y = "hello") => { }
3+
>lambda1 : (y?: string) => void
4+
>(y = "hello") => { } : (y?: string) => void
5+
>y : string
6+
7+
var lambda2 = (x: number, y = "hello") => { }
8+
>lambda2 : (x: number, y?: string) => void
9+
>(x: number, y = "hello") => { } : (x: number, y?: string) => void
10+
>x : number
11+
>y : string
12+
13+
var lambda3 = (x: number, y = "hello", ...rest) => { }
14+
>lambda3 : (x: number, y?: string, ...rest: any[]) => void
15+
>(x: number, y = "hello", ...rest) => { } : (x: number, y?: string, ...rest: any[]) => void
16+
>x : number
17+
>y : string
18+
>rest : any[]
19+
20+
var lambda4 = (y = "hello", ...rest) => { }
21+
>lambda4 : (y?: string, ...rest: any[]) => void
22+
>(y = "hello", ...rest) => { } : (y?: string, ...rest: any[]) => void
23+
>y : string
24+
>rest : any[]
25+
26+
var x = function (str = "hello", ...rest) { }
27+
>x : (str?: string, ...rest: any[]) => void
28+
>function (str = "hello", ...rest) { } : (str?: string, ...rest: any[]) => void
29+
>str : string
30+
>rest : any[]
31+
32+
var y = (function (num = 10, boo = false, ...rest) { })()
33+
>y : void
34+
>(function (num = 10, boo = false, ...rest) { })() : void
35+
>(function (num = 10, boo = false, ...rest) { }) : (num?: number, boo?: boolean, ...rest: any[]) => void
36+
>function (num = 10, boo = false, ...rest) { } : (num?: number, boo?: boolean, ...rest: any[]) => void
37+
>num : number
38+
>boo : boolean
39+
>rest : any[]
40+
41+
var z = (function (num: number, boo = false, ...rest) { })(10)
42+
>z : void
43+
>(function (num: number, boo = false, ...rest) { })(10) : void
44+
>(function (num: number, boo = false, ...rest) { }) : (num: number, boo?: boolean, ...rest: any[]) => void
45+
>function (num: number, boo = false, ...rest) { } : (num: number, boo?: boolean, ...rest: any[]) => void
46+
>num : number
47+
>boo : boolean
48+
>rest : any[]
49+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [emitDefaultParametersFunctionExpressionES6.ts]
2+
var lambda1 = (y = "hello") => { }
3+
var lambda2 = (x: number, y = "hello") => { }
4+
var lambda3 = (x: number, y = "hello", ...rest) => { }
5+
var lambda4 = (y = "hello", ...rest) => { }
6+
7+
var x = function (str = "hello", ...rest) { }
8+
var y = (function (num = 10, boo = false, ...rest) { })()
9+
var z = (function (num: number, boo = false, ...rest) { })(10)
10+
11+
//// [emitDefaultParametersFunctionExpressionES6.js]
12+
var lambda1 = function (y = "hello") {
13+
};
14+
var lambda2 = function (x, y = "hello") {
15+
};
16+
var lambda3 = function (x, y = "hello", ...rest) {
17+
};
18+
var lambda4 = function (y = "hello", ...rest) {
19+
};
20+
var x = function (str = "hello", ...rest) {
21+
};
22+
var y = (function (num = 10, boo = false, ...rest) {
23+
})();
24+
var z = (function (num, boo = false, ...rest) {
25+
})(10);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionExpressionES6.ts ===
2+
var lambda1 = (y = "hello") => { }
3+
>lambda1 : (y?: string) => void
4+
>(y = "hello") => { } : (y?: string) => void
5+
>y : string
6+
7+
var lambda2 = (x: number, y = "hello") => { }
8+
>lambda2 : (x: number, y?: string) => void
9+
>(x: number, y = "hello") => { } : (x: number, y?: string) => void
10+
>x : number
11+
>y : string
12+
13+
var lambda3 = (x: number, y = "hello", ...rest) => { }
14+
>lambda3 : (x: number, y?: string, ...rest: any[]) => void
15+
>(x: number, y = "hello", ...rest) => { } : (x: number, y?: string, ...rest: any[]) => void
16+
>x : number
17+
>y : string
18+
>rest : any[]
19+
20+
var lambda4 = (y = "hello", ...rest) => { }
21+
>lambda4 : (y?: string, ...rest: any[]) => void
22+
>(y = "hello", ...rest) => { } : (y?: string, ...rest: any[]) => void
23+
>y : string
24+
>rest : any[]
25+
26+
var x = function (str = "hello", ...rest) { }
27+
>x : (str?: string, ...rest: any[]) => void
28+
>function (str = "hello", ...rest) { } : (str?: string, ...rest: any[]) => void
29+
>str : string
30+
>rest : any[]
31+
32+
var y = (function (num = 10, boo = false, ...rest) { })()
33+
>y : void
34+
>(function (num = 10, boo = false, ...rest) { })() : void
35+
>(function (num = 10, boo = false, ...rest) { }) : (num?: number, boo?: boolean, ...rest: any[]) => void
36+
>function (num = 10, boo = false, ...rest) { } : (num?: number, boo?: boolean, ...rest: any[]) => void
37+
>num : number
38+
>boo : boolean
39+
>rest : any[]
40+
41+
var z = (function (num: number, boo = false, ...rest) { })(10)
42+
>z : void
43+
>(function (num: number, boo = false, ...rest) { })(10) : void
44+
>(function (num: number, boo = false, ...rest) { }) : (num: number, boo?: boolean, ...rest: any[]) => void
45+
>function (num: number, boo = false, ...rest) { } : (num: number, boo?: boolean, ...rest: any[]) => void
46+
>num : number
47+
>boo : boolean
48+
>rest : any[]
49+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [emitDefaultParametersFunctionProperty.ts]
2+
var obj2 = {
3+
func1(y = 10, ...rest) { },
4+
func2(x = "hello") { },
5+
func3(x: string, z: number, y = "hello") { },
6+
func4(x: string, z: number, y = "hello", ...rest) { },
7+
}
8+
9+
10+
//// [emitDefaultParametersFunctionProperty.js]
11+
var obj2 = {
12+
func1: function (y) {
13+
if (y === void 0) { y = 10; }
14+
var rest = [];
15+
for (var _i = 1; _i < arguments.length; _i++) {
16+
rest[_i - 1] = arguments[_i];
17+
}
18+
},
19+
func2: function (x) {
20+
if (x === void 0) { x = "hello"; }
21+
},
22+
func3: function (x, z, y) {
23+
if (y === void 0) { y = "hello"; }
24+
},
25+
func4: function (x, z, y) {
26+
if (y === void 0) { y = "hello"; }
27+
var rest = [];
28+
for (var _i = 3; _i < arguments.length; _i++) {
29+
rest[_i - 3] = arguments[_i];
30+
}
31+
},
32+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/conformance/es6/defaultParameters/emitDefaultParametersFunctionProperty.ts ===
2+
var obj2 = {
3+
>obj2 : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; }
4+
>{ func1(y = 10, ...rest) { }, func2(x = "hello") { }, func3(x: string, z: number, y = "hello") { }, func4(x: string, z: number, y = "hello", ...rest) { },} : { func1(y?: number, ...rest: any[]): void; func2(x?: string): void; func3(x: string, z: number, y?: string): void; func4(x: string, z: number, y?: string, ...rest: any[]): void; }
5+
6+
func1(y = 10, ...rest) { },
7+
>func1 : (y?: number, ...rest: any[]) => void
8+
>y : number
9+
>rest : any[]
10+
11+
func2(x = "hello") { },
12+
>func2 : (x?: string) => void
13+
>x : string
14+
15+
func3(x: string, z: number, y = "hello") { },
16+
>func3 : (x: string, z: number, y?: string) => void
17+
>x : string
18+
>z : number
19+
>y : string
20+
21+
func4(x: string, z: number, y = "hello", ...rest) { },
22+
>func4 : (x: string, z: number, y?: string, ...rest: any[]) => void
23+
>x : string
24+
>z : number
25+
>y : string
26+
>rest : any[]
27+
}
28+

0 commit comments

Comments
 (0)