diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.js b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.js new file mode 100644 index 00000000000..9e5c53fbe05 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.js @@ -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; +}); diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols new file mode 100644 index 00000000000..62e47c8a3c4 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols @@ -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)) + diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types new file mode 100644 index 00000000000..78d0fd1392b --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types @@ -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 : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func : Function +>call : { (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 : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func : Function +>call : { (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 : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func : Function +>call : { (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 : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func : Function +>call : { (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 : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>func : Function +>apply : { (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 + diff --git a/tests/cases/compiler/jsFileCompilationRestParamJsDocFunction.ts b/tests/cases/compiler/jsFileCompilationRestParamJsDocFunction.ts new file mode 100644 index 00000000000..03ad2d1b2ff --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationRestParamJsDocFunction.ts @@ -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; \ No newline at end of file