Adding testcase for function with rest param defined in jsDoc comment

Test case for #7749
This commit is contained in:
Sheetal Nandi 2016-04-19 15:43:12 -07:00
parent d960200dac
commit ef4b6613f3
4 changed files with 239 additions and 0 deletions

View File

@ -0,0 +1,55 @@
//// [_apply.js]
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
var length = args.length;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
export default apply;
//// [apply.js]
define("_apply", ["require", "exports"], function (require, exports) {
"use strict";
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var length = args.length;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
exports.__esModule = true;
exports["default"] = apply;
});

View File

@ -0,0 +1,68 @@
=== tests/cases/compiler/_apply.js ===
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
>apply : Symbol(apply, Decl(_apply.js, 0, 0))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
var length = args.length;
>length : Symbol(length, Decl(_apply.js, 12, 7))
>args.length : Symbol(Array.length, Decl(lib.d.ts, --, --))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>length : Symbol(Array.length, Decl(lib.d.ts, --, --))
switch (length) {
>length : Symbol(length, Decl(_apply.js, 12, 7))
case 0: return func.call(thisArg);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
case 1: return func.call(thisArg, args[0]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
case 2: return func.call(thisArg, args[0], args[1]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
case 3: return func.call(thisArg, args[0], args[1], args[2]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
}
return func.apply(thisArg, args);
>func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
}
export default apply;
>apply : Symbol(apply, Decl(_apply.js, 0, 0))

View File

@ -0,0 +1,89 @@
=== tests/cases/compiler/_apply.js ===
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
>apply : (func: Function, thisArg: any, ...args: any[]) => any
>func : Function
>thisArg : any
>args : any[]
var length = args.length;
>length : number
>args.length : number
>args : any[]
>length : number
switch (length) {
>length : number
case 0: return func.call(thisArg);
>0 : number
>func.call(thisArg) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>thisArg : any
case 1: return func.call(thisArg, args[0]);
>1 : number
>func.call(thisArg, args[0]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>thisArg : any
>args[0] : any
>args : any[]
>0 : number
case 2: return func.call(thisArg, args[0], args[1]);
>2 : number
>func.call(thisArg, args[0], args[1]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>thisArg : any
>args[0] : any
>args : any[]
>0 : number
>args[1] : any
>args : any[]
>1 : number
case 3: return func.call(thisArg, args[0], args[1], args[2]);
>3 : number
>func.call(thisArg, args[0], args[1], args[2]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>thisArg : any
>args[0] : any
>args : any[]
>0 : number
>args[1] : any
>args : any[]
>1 : number
>args[2] : any
>args : any[]
>2 : number
}
return func.apply(thisArg, args);
>func.apply(thisArg, args) : any
>func.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>func : Function
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>thisArg : any
>args : any[]
}
export default apply;
>apply : (func: Function, thisArg: any, ...args: any[]) => any

View File

@ -0,0 +1,27 @@
// @allowJs: true
// @out: apply.js
// @module: amd
// @filename: _apply.js
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
var length = args.length;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
export default apply;