From e2c2a37221c46ea131f4c621890838dd8a75041c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 5 Jan 2013 00:12:33 -0800 Subject: [PATCH] Make `_.merge` assign `null` values. [closes #151] Former-commit-id: 5a839996db9475182d5957d2f8cb4b3c265b0d9f --- build/post-compile.js | 4 ++-- doc/README.md | 6 +++--- lodash.js | 6 +++--- lodash.min.js | 2 +- lodash.underscore.js | 4 ++-- test/test-build.js | 6 +++--- test/test.js | 10 ++++++++++ 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/build/post-compile.js b/build/post-compile.js index bcb4cc8bb..23d91afe8 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -41,8 +41,8 @@ // flip `typeof` expressions to help optimize Safari and // correct the AMD module definition for AMD build optimizers // (e.g. from `"number" == typeof x` to `typeof x == "number") - source = source.replace(/(return)?("[^"]+")\s*([!=]=)\s*(typeof(?:\s*\([^)]+\)|\s+[\w.]+))/g, function(match, ret, type, equality, expression) { - return (ret ? ret + ' ' : '') + expression + equality + type; + source = source.replace(/(\w)?("[^"]+")\s*([!=]=)\s*(typeof(?:\s*\([^)]+\)|\s+[.\w[\]]+))/g, function(match, other, type, equality, expression) { + return (other ? other + ' ' : '') + expression + equality + type; }); // add trailing semicolon diff --git a/doc/README.md b/doc/README.md index 0c8f8b568..94f6f03c4 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1738,7 +1738,7 @@ Creates a function that is restricted to execute `func` once. Repeat calls to th var initialize = _.once(createApplication); initialize(); initialize(); -// Application is only created once. +// `initialize` executes `createApplication` once ``` * * * @@ -2598,7 +2598,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.merge(object [, source1, source2, ...])` # [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1758 "View in source") [Ⓣ][1] -Recursively merges own enumerable properties of the source object(s), that don't resolve to `null`/`undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. +Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments 1. `object` *(Object)*: The destination object. @@ -3184,4 +3184,4 @@ A reference to the `lodash` function. - [1]: #Arrays "Jump back to the TOC." + [1]: #Arrays "Jump back to the TOC." \ No newline at end of file diff --git a/lodash.js b/lodash.js index 534ab7322..4458143f0 100644 --- a/lodash.js +++ b/lodash.js @@ -1726,7 +1726,7 @@ /** * Recursively merges own enumerable properties of the source object(s), that - * don't resolve to `null`/`undefined`, into the `destination` object. Subsequent + * don't resolve to `undefined`, into the `destination` object. Subsequent * sources will overwrite propery assignments of previous sources. * * @static @@ -1796,7 +1796,7 @@ // recursively merge objects and arrays (susceptible to call stack limits) object[key] = merge(value, source, indicatorObject, stackA, stackB); } - } else if (source != null) { + } else if (typeof source != 'undefined') { object[key] = source; } }); @@ -3682,7 +3682,7 @@ * var initialize = _.once(createApplication); * initialize(); * initialize(); - * // Application is only created once. + * // `initialize` executes `createApplication` once */ function once(func) { var ran, diff --git a/lodash.min.js b/lodash.min.js index eee01f887..7bec0348f 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -11,7 +11,7 @@ var r=n.constructor;return!j(r)&&(!tr||!p(n))||r instanceof r?tt?(sr(n,function( }for(e||(e=[]),u||(u=[]),o=e.length;o--;)if(e[o]==n)return u[o];var a=i?r(n.length):{};return e.push(n),u.push(a),(i?R:vr)(n,function(n,r){a[r]=_(n,t,W,e,u)}),i&&(Et.call(n,"index")&&(a.index=n.index),Et.call(n,"input")&&(a.input=n.input)),a}function d(n){var t=[];return sr(n,function(n,r){j(n)&&t.push(r)}),t.sort()}function b(n){for(var t=-1,r=gr(n),e=r.length,u={};++tr?It(0,u+r):r)||0;return typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):lr(n,function(n){return++er?It(0,u+r):r)||0;return typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):lr(n,function(n){return++eo&&(o=f)}else t=!t&&A(n)?u:a(t,r),lr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function I(n,t){return F(n,t+"")}function T(n,t,r,e){var u=3>arguments.length,t=a(t,e,ot);if(_r(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length; if(typeof o!="number")var f=gr(n),o=f.length;else nr&&A(n)&&(u=n.split(""));return t=a(t,e,ot),R(n,function(n,e,a){e=f?f[--o]:--o,r=i?(i=X,u[e]):t(r,u[e],e,a)}),r}function M(n,t,r){var e,t=a(t,r);if(_r(n))for(var r=-1,u=n.length;++r