a752d912733d9ea9d9293898264d83afa6d56d66
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / createRecurryWrapper.js
1 var copyArray = require('./copyArray'),
2     isLaziable = require('./isLaziable'),
3     setData = require('./setData');
4
5 /** Used to compose bitmasks for wrapper metadata. */
6 var BIND_FLAG = 1,
7     BIND_KEY_FLAG = 2,
8     CURRY_BOUND_FLAG = 4,
9     CURRY_FLAG = 8,
10     PARTIAL_FLAG = 32,
11     PARTIAL_RIGHT_FLAG = 64;
12
13 /**
14  * Creates a function that wraps `func` to continue currying.
15  *
16  * @private
17  * @param {Function} func The function to wrap.
18  * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
19  * @param {Function} wrapFunc The function to create the `func` wrapper.
20  * @param {*} placeholder The placeholder to replace.
21  * @param {*} [thisArg] The `this` binding of `func`.
22  * @param {Array} [partials] The arguments to prepend to those provided to the new function.
23  * @param {Array} [holders] The `partials` placeholder indexes.
24  * @param {Array} [argPos] The argument positions of the new function.
25  * @param {number} [ary] The arity cap of `func`.
26  * @param {number} [arity] The arity of `func`.
27  * @returns {Function} Returns the new wrapped function.
28  */
29 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
30   var isCurry = bitmask & CURRY_FLAG,
31       newArgPos = argPos ? copyArray(argPos) : undefined,
32       newsHolders = isCurry ? holders : undefined,
33       newHoldersRight = isCurry ? undefined : holders,
34       newPartials = isCurry ? partials : undefined,
35       newPartialsRight = isCurry ? undefined : partials;
36
37   bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
38   bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
39
40   if (!(bitmask & CURRY_BOUND_FLAG)) {
41     bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
42   }
43   var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, arity],
44       result = wrapFunc.apply(undefined, newData);
45
46   if (isLaziable(func)) {
47     setData(result, newData);
48   }
49   result.placeholder = placeholder;
50   return result;
51 }
52
53 module.exports = createRecurryWrapper;