Skip to content

Commit ef4b661

Browse files
committed
Adding testcase for function with rest param defined in jsDoc comment
Test case for #7749
1 parent d960200 commit ef4b661

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [_apply.js]
2+
3+
/**
4+
* A faster alternative to `Function#apply`, this function invokes `func`
5+
* with the `this` binding of `thisArg` and the arguments of `args`.
6+
*
7+
* @private
8+
* @param {Function} func The function to invoke.
9+
* @param {*} thisArg The `this` binding of `func`.
10+
* @param {...*} args The arguments to invoke `func` with.
11+
* @returns {*} Returns the result of `func`.
12+
*/
13+
function apply(func, thisArg, args) {
14+
var length = args.length;
15+
switch (length) {
16+
case 0: return func.call(thisArg);
17+
case 1: return func.call(thisArg, args[0]);
18+
case 2: return func.call(thisArg, args[0], args[1]);
19+
case 3: return func.call(thisArg, args[0], args[1], args[2]);
20+
}
21+
return func.apply(thisArg, args);
22+
}
23+
24+
export default apply;
25+
26+
//// [apply.js]
27+
define("_apply", ["require", "exports"], function (require, exports) {
28+
"use strict";
29+
/**
30+
* A faster alternative to `Function#apply`, this function invokes `func`
31+
* with the `this` binding of `thisArg` and the arguments of `args`.
32+
*
33+
* @private
34+
* @param {Function} func The function to invoke.
35+
* @param {*} thisArg The `this` binding of `func`.
36+
* @param {...*} args The arguments to invoke `func` with.
37+
* @returns {*} Returns the result of `func`.
38+
*/
39+
function apply(func, thisArg) {
40+
var args = [];
41+
for (var _i = 2; _i < arguments.length; _i++) {
42+
args[_i - 2] = arguments[_i];
43+
}
44+
var length = args.length;
45+
switch (length) {
46+
case 0: return func.call(thisArg);
47+
case 1: return func.call(thisArg, args[0]);
48+
case 2: return func.call(thisArg, args[0], args[1]);
49+
case 3: return func.call(thisArg, args[0], args[1], args[2]);
50+
}
51+
return func.apply(thisArg, args);
52+
}
53+
exports.__esModule = true;
54+
exports["default"] = apply;
55+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
=== tests/cases/compiler/_apply.js ===
2+
3+
/**
4+
* A faster alternative to `Function#apply`, this function invokes `func`
5+
* with the `this` binding of `thisArg` and the arguments of `args`.
6+
*
7+
* @private
8+
* @param {Function} func The function to invoke.
9+
* @param {*} thisArg The `this` binding of `func`.
10+
* @param {...*} args The arguments to invoke `func` with.
11+
* @returns {*} Returns the result of `func`.
12+
*/
13+
function apply(func, thisArg, args) {
14+
>apply : Symbol(apply, Decl(_apply.js, 0, 0))
15+
>func : Symbol(func, Decl(_apply.js, 11, 15))
16+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
17+
>args : Symbol(args, Decl(_apply.js, 11, 29))
18+
19+
var length = args.length;
20+
>length : Symbol(length, Decl(_apply.js, 12, 7))
21+
>args.length : Symbol(Array.length, Decl(lib.d.ts, --, --))
22+
>args : Symbol(args, Decl(_apply.js, 11, 29))
23+
>length : Symbol(Array.length, Decl(lib.d.ts, --, --))
24+
25+
switch (length) {
26+
>length : Symbol(length, Decl(_apply.js, 12, 7))
27+
28+
case 0: return func.call(thisArg);
29+
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
30+
>func : Symbol(func, Decl(_apply.js, 11, 15))
31+
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
32+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
33+
34+
case 1: return func.call(thisArg, args[0]);
35+
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
36+
>func : Symbol(func, Decl(_apply.js, 11, 15))
37+
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
38+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
39+
>args : Symbol(args, Decl(_apply.js, 11, 29))
40+
41+
case 2: return func.call(thisArg, args[0], args[1]);
42+
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
43+
>func : Symbol(func, Decl(_apply.js, 11, 15))
44+
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
45+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
46+
>args : Symbol(args, Decl(_apply.js, 11, 29))
47+
>args : Symbol(args, Decl(_apply.js, 11, 29))
48+
49+
case 3: return func.call(thisArg, args[0], args[1], args[2]);
50+
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
51+
>func : Symbol(func, Decl(_apply.js, 11, 15))
52+
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
53+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
54+
>args : Symbol(args, Decl(_apply.js, 11, 29))
55+
>args : Symbol(args, Decl(_apply.js, 11, 29))
56+
>args : Symbol(args, Decl(_apply.js, 11, 29))
57+
}
58+
return func.apply(thisArg, args);
59+
>func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
60+
>func : Symbol(func, Decl(_apply.js, 11, 15))
61+
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
62+
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
63+
>args : Symbol(args, Decl(_apply.js, 11, 29))
64+
}
65+
66+
export default apply;
67+
>apply : Symbol(apply, Decl(_apply.js, 0, 0))
68+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
=== tests/cases/compiler/_apply.js ===
2+
3+
/**
4+
* A faster alternative to `Function#apply`, this function invokes `func`
5+
* with the `this` binding of `thisArg` and the arguments of `args`.
6+
*
7+
* @private
8+
* @param {Function} func The function to invoke.
9+
* @param {*} thisArg The `this` binding of `func`.
10+
* @param {...*} args The arguments to invoke `func` with.
11+
* @returns {*} Returns the result of `func`.
12+
*/
13+
function apply(func, thisArg, args) {
14+
>apply : (func: Function, thisArg: any, ...args: any[]) => any
15+
>func : Function
16+
>thisArg : any
17+
>args : any[]
18+
19+
var length = args.length;
20+
>length : number
21+
>args.length : number
22+
>args : any[]
23+
>length : number
24+
25+
switch (length) {
26+
>length : number
27+
28+
case 0: return func.call(thisArg);
29+
>0 : number
30+
>func.call(thisArg) : any
31+
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
32+
>func : Function
33+
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
34+
>thisArg : any
35+
36+
case 1: return func.call(thisArg, args[0]);
37+
>1 : number
38+
>func.call(thisArg, args[0]) : any
39+
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
40+
>func : Function
41+
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
42+
>thisArg : any
43+
>args[0] : any
44+
>args : any[]
45+
>0 : number
46+
47+
case 2: return func.call(thisArg, args[0], args[1]);
48+
>2 : number
49+
>func.call(thisArg, args[0], args[1]) : any
50+
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
51+
>func : Function
52+
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
53+
>thisArg : any
54+
>args[0] : any
55+
>args : any[]
56+
>0 : number
57+
>args[1] : any
58+
>args : any[]
59+
>1 : number
60+
61+
case 3: return func.call(thisArg, args[0], args[1], args[2]);
62+
>3 : number
63+
>func.call(thisArg, args[0], args[1], args[2]) : any
64+
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
65+
>func : Function
66+
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
67+
>thisArg : any
68+
>args[0] : any
69+
>args : any[]
70+
>0 : number
71+
>args[1] : any
72+
>args : any[]
73+
>1 : number
74+
>args[2] : any
75+
>args : any[]
76+
>2 : number
77+
}
78+
return func.apply(thisArg, args);
79+
>func.apply(thisArg, args) : any
80+
>func.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
81+
>func : Function
82+
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
83+
>thisArg : any
84+
>args : any[]
85+
}
86+
87+
export default apply;
88+
>apply : (func: Function, thisArg: any, ...args: any[]) => any
89+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @allowJs: true
2+
// @out: apply.js
3+
// @module: amd
4+
5+
// @filename: _apply.js
6+
/**
7+
* A faster alternative to `Function#apply`, this function invokes `func`
8+
* with the `this` binding of `thisArg` and the arguments of `args`.
9+
*
10+
* @private
11+
* @param {Function} func The function to invoke.
12+
* @param {*} thisArg The `this` binding of `func`.
13+
* @param {...*} args The arguments to invoke `func` with.
14+
* @returns {*} Returns the result of `func`.
15+
*/
16+
function apply(func, thisArg, args) {
17+
var length = args.length;
18+
switch (length) {
19+
case 0: return func.call(thisArg);
20+
case 1: return func.call(thisArg, args[0]);
21+
case 2: return func.call(thisArg, args[0], args[1]);
22+
case 3: return func.call(thisArg, args[0], args[1], args[2]);
23+
}
24+
return func.apply(thisArg, args);
25+
}
26+
27+
export default apply;

0 commit comments

Comments
 (0)