Cleanup _.merge.

Former-commit-id: 49c646ff8f199b001cfd8145d7e2076d8d1ceaf0
This commit is contained in:
John-David Dalton
2012-10-14 15:24:28 -07:00
parent b5f2295f37
commit 01ec585a44
2 changed files with 8 additions and 7 deletions

View File

@@ -1636,7 +1636,7 @@
* @param- {Object} [indicator] Internally used to indicate that the `stack`
* argument is an array of traversed objects instead of another source object.
* @param- {Array} [stackA=[]] Internally used to track traversed source objects.
* @param- {Array} [stackB=[]] Internally used to associate clones with their
* @param- {Array} [stackB=[]] Internally used to associate values with their
* source counterparts.
* @returns {Object} Returns the destination object.
* @example
@@ -1668,11 +1668,10 @@
}
while (++index < length) {
forOwn(args[index], function(source, key) {
var isArr, value;
var found, isArr, value;
if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
var found = false,
stackLength = stackA.length;
// avoid merging previously merged cyclic sources
var stackLength = stackA.length;
while (stackLength--) {
if ((found = stackA[stackLength] == source)) {
break;
@@ -1682,11 +1681,13 @@
object[key] = stackB[stackLength];
}
else {
// add `source` and associated `value` to the stack of traversed objects
stackA.push(source);
stackB.push(value = (value = object[key], isArr)
? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {})
);
// recursively merge objects and arrays (susceptible to call stack limits)
object[key] = merge(value, source, compareAscending, stackA, stackB);
}
} else if (source != null) {

4
lodash.min.js vendored
View File

@@ -10,8 +10,8 @@ e.l.h+"}"}if(e.c||e.m)i+="}"}return i+=e.e+";return p",Function("v,e,forIn,g,x,y
n)?_t?(Kt(e,function(e,n,r){return t=!at.call(r,n),i}),t===i):(Kt(e,function(e,n){t=n}),t===i||at.call(e,t)):t}function y(e){var t=[];return Qt(e,function(e,n){t.push(n)}),t}function b(e,t,n,s,o){if(e==r)return e;n&&(t=i);if(n=zt[typeof e]){var u=ht.call(e);if(!Ut[u]||Pt&&v(e))return e;var a=u==Et,n=a||(u==Nt?Yt(e):n)}if(!n||!t)return n?a?ct.call(e):nn({},e):e;n=e.constructor;switch(u){case St:case xt:return new n(+e);case Tt:case kt:return new n(e);case Ct:return n(e.source,G.exec(e))}s||(s=[]),
o||(o=[]);for(u=s.length;u--;)if(s[u]==e)return o[u];var f=a?n(e.length):{};return s.push(e),o.push(f),(a?un:Qt)(e,function(e,n){f[n]=b(e,t,r,s,o)}),f}function w(e){var t=[];return Kt(e,function(e,n){m(e)&&t.push(n)}),t.sort()}function E(e){var t={};return Qt(e,function(e,n){t[e]=n}),t}function S(e,t,s,o){if(e===t)return 0!==e||1/e==1/t;if(e==r||t==r)return e===t;var u=ht.call(e);if(u!=ht.call(t))return i;switch(u){case St:case xt:return+e==+t;case Tt:return e!=+e?t!=+t:0==e?1/e==1/t:e==+t;case Ct
:case kt:return e==t+""}var a=u==Et||u==wt;if(Pt&&!a&&(a=v(e))&&!v(t))return i;if(!a){if(e.__wrapped__||t.__wrapped__)return S(e.__wrapped__||e,t.__wrapped__||t);if(u!=Nt||jt&&("function"!=typeof e.toString&&"string"==typeof (e+"")||"function"!=typeof t.toString&&"string"==typeof (t+"")))return i;var u=e.constructor,f=t.constructor;if(u!=f&&(!m(u)||!(u instanceof u&&m(f)&&f instanceof f)))return i}s||(s=[]),o||(o=[]);for(u=s.length;u--;)if(s[u]==e)return o[u]==t;var u=-1,f=n,l=0;s.push(e),o.push(
t);if(a){l=e.length;if(f=l==t.length)for(;l--&&(f=S(e[l],t[l],s,o)););return f}for(var c in e)if(at.call(e,c)&&(l++,!at.call(t,c)||!S(e[c],t[c],s,o)))return i;for(c in t)if(at.call(t,c)&&!(l--))return i;if(Ot)for(;7>++u;)if(c=rt[u],at.call(e,c)&&(!at.call(t,c)||!S(e[c],t[c],s,o)))return i;return n}function x(e,t,n){var s=arguments,o=0,a=2,f=s[3],l=s[4];n!=u&&(f=[],l=[],a=s.length);for(;++o<a;)Qt(s[o],function(t,n){var s,o;if(t&&((s=Gt(t))||Yt(t))){for(var a=i,c=f.length;c--;)if(a=f[c]==t)break;a?
e[n]=l[c]:(f.push(t),l.push(o=(o=e[n],s)?Gt(o)?o:[]:Yt(o)?o:{}),e[n]=x(o,t,u,f,l))}else t!=r&&(e[n]=t)});return e}function T(e){var t=[];return Qt(e,function(e){t.push(e)}),t}function N(e,t){var n=e?e.length:0;return n===+n?-1<(ht.call(e)==kt?e.indexOf(t):D(e,t)):fn(e,function(e){return e===t})}function C(e,t,r){var i,t=f(t,r);return fn(e,function(e,r,s){return t(e,r,s)&&(i=e,n)}),i}function k(e,t,n){var r=-Infinity,i=-1,s=e?e.length:0,o=r;if(t||s!==+s)t=f(t,n),un(e,function(e,n,i){n=t(e,n,i),n>r&&
t);if(a){l=e.length;if(f=l==t.length)for(;l--&&(f=S(e[l],t[l],s,o)););return f}for(var c in e)if(at.call(e,c)&&(l++,!at.call(t,c)||!S(e[c],t[c],s,o)))return i;for(c in t)if(at.call(t,c)&&!(l--))return i;if(Ot)for(;7>++u;)if(c=rt[u],at.call(e,c)&&(!at.call(t,c)||!S(e[c],t[c],s,o)))return i;return n}function x(e,t,n){var i=arguments,s=0,o=2,a=i[3],f=i[4];n!=u&&(a=[],f=[],o=i.length);for(;++s<o;)Qt(i[s],function(t,n){var i,s,o;if(t&&((s=Gt(t))||Yt(t))){for(var l=a.length;l--;)if(i=a[l]==t)break;i?e[
n]=f[l]:(a.push(t),f.push(o=(o=e[n],s)?Gt(o)?o:[]:Yt(o)?o:{}),e[n]=x(o,t,u,a,f))}else t!=r&&(e[n]=t)});return e}function T(e){var t=[];return Qt(e,function(e){t.push(e)}),t}function N(e,t){var n=e?e.length:0;return n===+n?-1<(ht.call(e)==kt?e.indexOf(t):D(e,t)):fn(e,function(e){return e===t})}function C(e,t,r){var i,t=f(t,r);return fn(e,function(e,r,s){return t(e,r,s)&&(i=e,n)}),i}function k(e,t,n){var r=-Infinity,i=-1,s=e?e.length:0,o=r;if(t||s!==+s)t=f(t,n),un(e,function(e,n,i){n=t(e,n,i),n>r&&
(r=n,o=e)});else for(;++i<s;)e[i]>o&&(o=e[i]);return o}function L(e,t){var n=[];return un(e,function(e){n.push(e[t])}),n}function A(e,t,n,r){var s=3>arguments.length,t=f(t,r);return un(e,function(e,r,o){n=s?(s=i,e):t(n,e,r,o)}),n}function O(e,t,n,r){var s=e,o=e?e.length:0,u=3>arguments.length;if(o!==+o)var a=rn(e),o=a.length;else Bt&&ht.call(e)==kt&&(s=e.split(""));return un(e,function(e,f,l){f=a?a[--o]:--o,n=u?(u=i,s[f]):t.call(r,n,s[f],f,l)}),n}function M(e,t,n){if(e)return t==r||n?e[0]:ct.call
(e,0,t)}function _(e,t){for(var n=-1,r=e?e.length:0,i=[];++n<r;){var s=e[n];Gt(s)?ft.apply(i,t?s:_(s)):i.push(s)}return i}function D(e,t,n){var r=-1,i=e?e.length:0;if("number"==typeof n)r=(0>n?gt(0,i+n):n||0)-1;else if(n)return r=H(e,t),e[r]===t?r:-1;for(;++r<i;)if(e[r]===t)return r;return-1}function P(e,t,n){return e?ct.call(e,t==r||n?1:t):[]}function H(e,t,n,r){var i=0,s=e?e.length:i;if(n){n=f(n,r);for(t=n(t);i<s;)r=i+s>>>1,n(e[r])<t?i=r+1:s=r}else for(;i<s;)r=i+s>>>1,e[r]<t?i=r+1:s=r;return i}
function B(e,t,n,r){var s=-1,o=e?e.length:0,u=[],a=[];"function"==typeof t&&(r=n,n=t,t=i);for(n=f(n,r);++s<o;)if(r=n(e[s],s,e),t?!s||a[a.length-1]!==r:0>D(a,r))a.push(r),u.push(e[s]);return u}function j(e,t){return It||pt&&2<arguments.length?pt.call.apply(pt,arguments):a(e,t,ct.call(arguments,2))}function F(e){return e}function I(e){un(w(e),function(t){var r=s[t]=e[t];s.prototype[t]=function(){var e=[this.__wrapped__];return arguments.length&&ft.apply(e,arguments),e=r.apply(s,e),this.__chain__&&(