Rename wrapper function.

This commit is contained in:
John-David Dalton
2016-06-11 20:47:03 -07:00
parent a7a4862491
commit 9a1b3d813a

View File

@@ -4548,14 +4548,14 @@
* *
* @private * @private
* @param {Function} func The function to wrap. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` * @param {number} bitmask The bitmask of wrapper flags. See `createWrap`
* for more details. * for more details.
* @param {*} [thisArg] The `this` binding of `func`. * @param {*} [thisArg] The `this` binding of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createBaseWrapper(func, bitmask, thisArg) { function createBind(func, bitmask, thisArg) {
var isBind = bitmask & BIND_FLAG, var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func); Ctor = createCtor(func);
function wrapper() { function wrapper() {
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
@@ -4612,7 +4612,7 @@
* @param {Function} Ctor The constructor to wrap. * @param {Function} Ctor The constructor to wrap.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createCtorWrapper(Ctor) { function createCtor(Ctor) {
return function() { return function() {
// Use a `switch` statement to work with class constructors. See // Use a `switch` statement to work with class constructors. See
// http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
@@ -4642,13 +4642,13 @@
* *
* @private * @private
* @param {Function} func The function to wrap. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` * @param {number} bitmask The bitmask of wrapper flags. See `createWrap`
* for more details. * for more details.
* @param {number} arity The arity of `func`. * @param {number} arity The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createCurryWrapper(func, bitmask, arity) { function createCurry(func, bitmask, arity) {
var Ctor = createCtorWrapper(func); var Ctor = createCtor(func);
function wrapper() { function wrapper() {
var length = arguments.length, var length = arguments.length,
@@ -4665,8 +4665,8 @@
length -= holders.length; length -= holders.length;
if (length < arity) { if (length < arity) {
return createRecurryWrapper( return createRecurry(
func, bitmask, createHybridWrapper, wrapper.placeholder, undefined, func, bitmask, createHybrid, wrapper.placeholder, undefined,
args, holders, undefined, undefined, arity - length); args, holders, undefined, undefined, arity - length);
} }
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
@@ -4765,7 +4765,7 @@
* *
* @private * @private
* @param {Function|string} func The function or method name to wrap. * @param {Function|string} func The function or method name to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` * @param {number} bitmask The bitmask of wrapper flags. See `createWrap`
* for more details. * for more details.
* @param {*} [thisArg] The `this` binding of `func`. * @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to * @param {Array} [partials] The arguments to prepend to those provided to
@@ -4779,13 +4779,13 @@
* @param {number} [arity] The arity of `func`. * @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
var isAry = bitmask & ARY_FLAG, var isAry = bitmask & ARY_FLAG,
isBind = bitmask & BIND_FLAG, isBind = bitmask & BIND_FLAG,
isBindKey = bitmask & BIND_KEY_FLAG, isBindKey = bitmask & BIND_KEY_FLAG,
isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG), isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
isFlip = bitmask & FLIP_FLAG, isFlip = bitmask & FLIP_FLAG,
Ctor = isBindKey ? undefined : createCtorWrapper(func); Ctor = isBindKey ? undefined : createCtor(func);
function wrapper() { function wrapper() {
var length = arguments.length, var length = arguments.length,
@@ -4808,8 +4808,8 @@
length -= holdersCount; length -= holdersCount;
if (isCurried && length < arity) { if (isCurried && length < arity) {
var newHolders = replaceHolders(args, placeholder); var newHolders = replaceHolders(args, placeholder);
return createRecurryWrapper( return createRecurry(
func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg, func, bitmask, createHybrid, wrapper.placeholder, thisArg,
args, newHolders, argPos, ary, arity - length args, newHolders, argPos, ary, arity - length
); );
} }
@@ -4826,7 +4826,7 @@
args.length = ary; args.length = ary;
} }
if (this && this !== root && this instanceof wrapper) { if (this && this !== root && this instanceof wrapper) {
fn = Ctor || createCtorWrapper(fn); fn = Ctor || createCtor(fn);
} }
return fn.apply(thisBinding, args); return fn.apply(thisBinding, args);
} }
@@ -4931,16 +4931,16 @@
* *
* @private * @private
* @param {Function} func The function to wrap. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` * @param {number} bitmask The bitmask of wrapper flags. See `createWrap`
* for more details. * for more details.
* @param {*} thisArg The `this` binding of `func`. * @param {*} thisArg The `this` binding of `func`.
* @param {Array} partials The arguments to prepend to those provided to * @param {Array} partials The arguments to prepend to those provided to
* the new function. * the new function.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createPartialWrapper(func, bitmask, thisArg, partials) { function createPartial(func, bitmask, thisArg, partials) {
var isBind = bitmask & BIND_FLAG, var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func); Ctor = createCtor(func);
function wrapper() { function wrapper() {
var argsIndex = -1, var argsIndex = -1,
@@ -5009,7 +5009,7 @@
* *
* @private * @private
* @param {Function} func The function to wrap. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` * @param {number} bitmask The bitmask of wrapper flags. See `createWrap`
* for more details. * for more details.
* @param {Function} wrapFunc The function to create the `func` wrapper. * @param {Function} wrapFunc The function to create the `func` wrapper.
* @param {*} placeholder The placeholder value. * @param {*} placeholder The placeholder value.
@@ -5022,7 +5022,7 @@
* @param {number} [arity] The arity of `func`. * @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
var isCurry = bitmask & CURRY_FLAG, var isCurry = bitmask & CURRY_FLAG,
newHolders = isCurry ? holders : undefined, newHolders = isCurry ? holders : undefined,
newHoldersRight = isCurry ? undefined : holders, newHoldersRight = isCurry ? undefined : holders,
@@ -5130,7 +5130,7 @@
* @param {number} [arity] The arity of `func`. * @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG; var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && typeof func != 'function') { if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
@@ -5173,13 +5173,13 @@
bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG); bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
} }
if (!bitmask || bitmask == BIND_FLAG) { if (!bitmask || bitmask == BIND_FLAG) {
var result = createBaseWrapper(func, bitmask, thisArg); var result = createBind(func, bitmask, thisArg);
} else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) { } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
result = createCurryWrapper(func, bitmask, arity); result = createCurry(func, bitmask, arity);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) { } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
result = createPartialWrapper(func, bitmask, thisArg, partials); result = createPartial(func, bitmask, thisArg, partials);
} else { } else {
result = createHybridWrapper.apply(undefined, newData); result = createHybrid.apply(undefined, newData);
} }
var setter = data ? baseSetData : setData; var setter = data ? baseSetData : setData;
return setter(result, newData); return setter(result, newData);
@@ -9450,7 +9450,7 @@
function ary(func, n, guard) { function ary(func, n, guard) {
n = guard ? undefined : n; n = guard ? undefined : n;
n = (func && n == null) ? func.length : n; n = (func && n == null) ? func.length : n;
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
} }
/** /**
@@ -9528,7 +9528,7 @@
var holders = replaceHolders(partials, getHolder(bind)); var holders = replaceHolders(partials, getHolder(bind));
bitmask |= PARTIAL_FLAG; bitmask |= PARTIAL_FLAG;
} }
return createWrapper(func, bitmask, thisArg, partials, holders); return createWrap(func, bitmask, thisArg, partials, holders);
}); });
/** /**
@@ -9582,7 +9582,7 @@
var holders = replaceHolders(partials, getHolder(bindKey)); var holders = replaceHolders(partials, getHolder(bindKey));
bitmask |= PARTIAL_FLAG; bitmask |= PARTIAL_FLAG;
} }
return createWrapper(key, bitmask, object, partials, holders); return createWrap(key, bitmask, object, partials, holders);
}); });
/** /**
@@ -9628,7 +9628,7 @@
*/ */
function curry(func, arity, guard) { function curry(func, arity, guard) {
arity = guard ? undefined : arity; arity = guard ? undefined : arity;
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curry.placeholder; result.placeholder = curry.placeholder;
return result; return result;
} }
@@ -9673,7 +9673,7 @@
*/ */
function curryRight(func, arity, guard) { function curryRight(func, arity, guard) {
arity = guard ? undefined : arity; arity = guard ? undefined : arity;
var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curryRight.placeholder; result.placeholder = curryRight.placeholder;
return result; return result;
} }
@@ -9914,7 +9914,7 @@
* // => ['d', 'c', 'b', 'a'] * // => ['d', 'c', 'b', 'a']
*/ */
function flip(func) { function flip(func) {
return createWrapper(func, FLIP_FLAG); return createWrap(func, FLIP_FLAG);
} }
/** /**
@@ -10118,7 +10118,7 @@
*/ */
var partial = rest(function(func, partials) { var partial = rest(function(func, partials) {
var holders = replaceHolders(partials, getHolder(partial)); var holders = replaceHolders(partials, getHolder(partial));
return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders); return createWrap(func, PARTIAL_FLAG, undefined, partials, holders);
}); });
/** /**
@@ -10155,7 +10155,7 @@
*/ */
var partialRight = rest(function(func, partials) { var partialRight = rest(function(func, partials) {
var holders = replaceHolders(partials, getHolder(partialRight)); var holders = replaceHolders(partials, getHolder(partialRight));
return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
}); });
/** /**
@@ -10181,7 +10181,7 @@
* // => ['a', 'b', 'c'] * // => ['a', 'b', 'c']
*/ */
var rearg = rest(function(func, indexes) { var rearg = rest(function(func, indexes) {
return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1)); return createWrap(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
}); });
/** /**
@@ -16453,7 +16453,7 @@
} }
}); });
realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{
'name': 'wrapper', 'name': 'wrapper',
'func': undefined 'func': undefined
}]; }];