Ensure the lodash underscore version of _.result matches v1.4.4 behavior.

Former-commit-id: c4c1946e49f12ddc4ba2f0f65a9ef7c9727d79ca
This commit is contained in:
John-David Dalton
2013-01-30 08:57:28 -08:00
parent be50df81db
commit 6632241ab5
6 changed files with 20 additions and 15 deletions

View File

@@ -1753,6 +1753,14 @@
' }'
].join('\n'));
// replace `_.result`
source = replaceFunction(source, 'result', [
' function result(object, property) {',
' var value = object ? object[property] : null;',
' return isFunction(value) ? object[property]() : value;',
' }'
].join('\n'));
// replace `_.template`
source = replaceFunction(source, 'template', [
' function template(text, data, options) {',

View File

@@ -756,7 +756,7 @@ The wrapper functions `first` and `last` return wrapped values when `n` is passe
<!-- div -->
### <a id="_tapvalue-interceptor"></a>`_.tap(value, interceptor)`
<a href="#_tapvalue-interceptor">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4481 "View in source") [&#x24C9;][1]
<a href="#_tapvalue-interceptor">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4479 "View in source") [&#x24C9;][1]
Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
@@ -786,7 +786,7 @@ _([1, 2, 3, 4])
<!-- div -->
### <a id="_prototypetostring"></a>`_.prototype.toString()`
<a href="#_prototypetostring">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4498 "View in source") [&#x24C9;][1]
<a href="#_prototypetostring">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4496 "View in source") [&#x24C9;][1]
Produces the `toString` result of the wrapped value.
@@ -807,7 +807,7 @@ _([1, 2, 3]).toString();
<!-- div -->
### <a id="_prototypevalueof"></a>`_.prototype.valueOf()`
<a href="#_prototypevalueof">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4515 "View in source") [&#x24C9;][1]
<a href="#_prototypevalueof">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4513 "View in source") [&#x24C9;][1]
Extracts the wrapped value.
@@ -3056,7 +3056,7 @@ _.result(object, 'stuff');
<!-- div -->
### <a id="_templatetext-data-options"></a>`_.template(text, data, options)`
<a href="#_templatetext-data-options">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4281 "View in source") [&#x24C9;][1]
<a href="#_templatetext-data-options">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4279 "View in source") [&#x24C9;][1]
A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code.
@@ -3134,7 +3134,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\
<!-- div -->
### <a id="_timesn-callback--thisarg"></a>`_.times(n, callback [, thisArg])`
<a href="#_timesn-callback--thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4407 "View in source") [&#x24C9;][1]
<a href="#_timesn-callback--thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4405 "View in source") [&#x24C9;][1]
Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*.
@@ -3166,7 +3166,7 @@ _.times(3, function(n) { this.cast(n); }, mage);
<!-- div -->
### <a id="_unescapestring"></a>`_.unescape(string)`
<a href="#_unescapestring">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4433 "View in source") [&#x24C9;][1]
<a href="#_unescapestring">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4431 "View in source") [&#x24C9;][1]
The opposite of `_.escape`, this method converts the HTML entities `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#x27;` in `string` to their corresponding characters.
@@ -3190,7 +3190,7 @@ _.unescape('Moe, Larry &amp; Curly');
<!-- div -->
### <a id="_uniqueidprefix"></a>`_.uniqueId([prefix])`
<a href="#_uniqueidprefix">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4453 "View in source") [&#x24C9;][1]
<a href="#_uniqueidprefix">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4451 "View in source") [&#x24C9;][1]
Generates a unique ID. If `prefix` is passed, the ID will be appended to it.
@@ -3243,7 +3243,7 @@ A reference to the `lodash` function.
<!-- div -->
### <a id="_version"></a>`_.VERSION`
<a href="#_version">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4683 "View in source") [&#x24C9;][1]
<a href="#_version">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4681 "View in source") [&#x24C9;][1]
*(String)*: The semantic version number.

View File

@@ -4194,8 +4194,6 @@
* // => 'nonsense'
*/
function result(object, property) {
// based on Backbone's private `getValue` function
// https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424
var value = object ? object[property] : undefined;
return isFunction(value) ? object[property]() : value;
}

View File

@@ -3535,9 +3535,7 @@
* // => 'nonsense'
*/
function result(object, property) {
// based on Backbone's private `getValue` function
// https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424
var value = object ? object[property] : undefined;
var value = object ? object[property] : null;
return isFunction(value) ? object[property]() : value;
}

View File

@@ -26,8 +26,8 @@ var e=-1;t=yt(0,ot((t-n)/r));for(var u=Array(t);++e<t;)u[e]=n,n+=r;return u},u.r
},u.tap=function(n,t){return t(n),n},u.throttle=function(n,t){function r(){a=new Date,i=H,u=n.apply(o,e)}var e,u,o,i,a=0;return function(){var f=new Date,c=t-(f-a);return e=arguments,o=this,0<c?i||(i=setTimeout(r,c)):(clearTimeout(i),i=H,a=f,u=n.apply(o,e)),u}},u.times=function(n,t,r){n=+n||0;for(var e=-1,u=Array(n);++e<n;)u[e]=t.call(r,e);return u},u.toArray=function(n){return n&&typeof n.length=="number"?p(n):A(n)},u.union=function(){return P(it.apply(Q,arguments))},u.uniq=P,u.values=A,u.where=function(n,t,r){return(r?k:S)(n,t)
},u.without=function(n){for(var t=-1,r=n.length,e=[];++t<r;){var u=n[t];0>I(arguments,u,1)&&e.push(u)}return e},u.wrap=function(n,t){return function(){var r=[n];return ct.apply(r,arguments),t.apply(this,r)}},u.zip=function(n){for(var t=-1,r=n?R(T(arguments,"length")):0,e=Array(r);++t<r;)e[t]=T(arguments,t);return e},u.collect=F,u.drop=z,u.each=N,u.extend=g,u.methods=_,u.select=S,u.tail=z,u.unique=P,u.clone=function(n){return j(n)?Tt(n)?p(n):g({},n):n},u.contains=E,u.escape=function(n){return n==H?"":(n+"").replace(et,c)
},u.every=O,u.find=k,u.findWhere=k,u.has=function(n,t){return n?ft.call(n,t):J},u.identity=V,u.indexOf=I,u.isArguments=v,u.isArray=Tt,u.isBoolean=function(n){return n===G||n===J||lt.call(n)==jt},u.isDate=function(n){return n instanceof Date||lt.call(n)==wt},u.isElement=function(n){return n?1===n.nodeType:J},u.isEmpty=function(n){if(!n)return G;if(Tt(n)||x(n))return!n.length;for(var t in n)if(ft.call(n,t))return J;return G},u.isEqual=d,u.isFinite=function(n){return vt(n)&&!ht(parseFloat(n))},u.isFunction=b,u.isNaN=function(n){return w(n)&&n!=+n
},u.isNull=function(n){return n===H},u.isNumber=w,u.isObject=j,u.isRegExp=function(n){return n instanceof RegExp||lt.call(n)==Et},u.isString=x,u.isUndefined=function(n){return typeof n=="undefined"},u.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?yt(0,e+r):_t(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=W,u.noConflict=function(){return n._=Z,this},u.random=function(n,t){return n==H&&t==H&&(t=1),n=+n||0,t==H&&(t=n,n=0),n+at(mt()*((+t||0)-n+1))},u.reduce=q,u.reduceRight=B,u.result=function(n,r){var e=n?n[r]:t;
return b(e)?n[r]():e},u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qt(n).length},u.some=D,u.sortedIndex=C,u.template=function(n,t,r){n||(n=""),r=y({},r,u.templateSettings);var e=0,o="__p+='",i=r.variable;n.replace(RegExp((r.escape||rt).source+"|"+(r.interpolate||rt).source+"|"+(r.evaluate||rt).source+"|$","g"),function(t,r,u,i,a){return o+=n.slice(e,a).replace(ut,f),r&&(o+="'+_['escape']("+r+")+'"),i&&(o+="';"+i+";__p+='"),u&&(o+="'+((__t=("+u+"))==null?'':__t)+'"),e=a+t.length,t
},u.isNull=function(n){return n===H},u.isNumber=w,u.isObject=j,u.isRegExp=function(n){return n instanceof RegExp||lt.call(n)==Et},u.isString=x,u.isUndefined=function(n){return typeof n=="undefined"},u.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?yt(0,e+r):_t(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=W,u.noConflict=function(){return n._=Z,this},u.random=function(n,t){return n==H&&t==H&&(t=1),n=+n||0,t==H&&(t=n,n=0),n+at(mt()*((+t||0)-n+1))},u.reduce=q,u.reduceRight=B,u.result=function(n,t){var r=n?n[t]:H;
return b(r)?n[t]():r},u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qt(n).length},u.some=D,u.sortedIndex=C,u.template=function(n,t,r){n||(n=""),r=y({},r,u.templateSettings);var e=0,o="__p+='",i=r.variable;n.replace(RegExp((r.escape||rt).source+"|"+(r.interpolate||rt).source+"|"+(r.evaluate||rt).source+"|$","g"),function(t,r,u,i,a){return o+=n.slice(e,a).replace(ut,f),r&&(o+="'+_['escape']("+r+")+'"),i&&(o+="';"+i+";__p+='"),u&&(o+="'+((__t=("+u+"))==null?'':__t)+'"),e=a+t.length,t
}),o+="';\n",i||(i="obj",o="with("+i+"||{}){"+o+"}"),o="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+o+"return __p}";try{var a=Function("_","return "+o)(u)}catch(c){throw c.source=o,c}return t?a(t):(a.source=o,a)},u.unescape=function(n){return n==H?"":(n+"").replace(nt,s)},u.uniqueId=function(n){var t=++X+"";return n?n+t:t},u.all=O,u.any=D,u.detect=k,u.foldl=q,u.foldr=B,u.include=E,u.inject=q,u.first=M,u.last=function(n,t,r){if(n){var e=0,u=n.length;
if(typeof t=="function"){var o=u;for(t=a(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==H||r)return n[u-1];return p(n,yt(0,u-e))}},u.take=M,u.head=M,u.chain=function(n){return n=new u(n),n.__chain__=G,n},u.VERSION="1.0.0-rc.3",W(u),u.prototype.chain=function(){return this.__chain__=G,this},u.prototype.value=function(){return this.__wrapped__},e("pop push reverse shift sort splice unshift".split(" "),function(n){var t=Q[n];u.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),kt&&0===n.length&&delete n[0],this
}}),e(["concat","join","slice"],function(n){var t=Q[n];u.prototype[n]=function(){var n=t.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new u(n),n.__chain__=G),n}}),K?typeof module=="object"&&module&&module.exports==K?(module.exports=u)._=u:K._=u:n._=u})(this);

View File

@@ -798,6 +798,7 @@
actual = lodash.pick(object, function(value) { return value != 3; });
deepEqual(_.keys(actual), [], '_.pick should not accept a `callback`: ' + basename);
strictEqual(lodash.result(), null, '_.result should return `null` when passed a falsey `object` argument: ' + basename);
strictEqual(lodash.some([false, true, false]), true, '_.some: ' + basename);
equal(lodash.template('${a}', object), '${a}', '_.template should ignore ES6 delimiters: ' + basename);
equal('imports' in lodash.templateSettings, false, '_.templateSettings should not have an "imports" property: ' + basename);