mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 15:12:08 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/internal/_curryN.js
|
|
|
|
|
|
import _arity from './_arity.js';
|
|
import _isPlaceholder from './_isPlaceholder.js';
|
|
|
|
|
|
/**
|
|
* Internal curryN function.
|
|
*
|
|
* @private
|
|
* @category Function
|
|
* @param {Number} length The arity of the curried function.
|
|
* @param {Array} received An array of arguments received thus far.
|
|
* @param {Function} fn The function to curry.
|
|
* @return {Function} The curried function.
|
|
*/
|
|
export default function _curryN(length, received, fn) {
|
|
return function() {
|
|
var combined = [];
|
|
var argsIdx = 0;
|
|
var left = length;
|
|
var combinedIdx = 0;
|
|
while (combinedIdx < received.length || argsIdx < arguments.length) {
|
|
var result;
|
|
if (combinedIdx < received.length &&
|
|
(!_isPlaceholder(received[combinedIdx]) ||
|
|
argsIdx >= arguments.length)) {
|
|
result = received[combinedIdx];
|
|
} else {
|
|
result = arguments[argsIdx];
|
|
argsIdx += 1;
|
|
}
|
|
combined[combinedIdx] = result;
|
|
if (!_isPlaceholder(result)) {
|
|
left -= 1;
|
|
}
|
|
combinedIdx += 1;
|
|
}
|
|
return left <= 0
|
|
? fn.apply(this, combined)
|
|
: _arity(left, _curryN(length, combined, fn));
|
|
};
|
|
}
|