r?It(0,e+r):Tt(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},r.mixin=H,r.noConflict=function(){return n._=at,this
+},r.random=function(n,t){return n==W&&t==W&&(t=1),n=+n||0,t==W&&(t=n,n=0),n+Ot(Bt()*((+t||0)-n+1))},r.reduce=T,r.reduceRight=B,r.result=function(n,t){var r=n?n[t]:W;return j(r)?n[t]():r},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:hr(n).length},r.some=M,r.sortedIndex=L,r.template=function(n,e,u){n||(n=""),u||(u={});var o,i=0,a=r.templateSettings,f=u.interpolate||a.interpolate||_t,l="__p+='";n.replace(RegExp((u.escape||a.escape||_t).source+"|"+f.source+"|"+(f===mt?yt:_t).source+"|"+(u.evaluate||a.evaluate||_t).source+"|$","g"),function(t,r,e,u,a,f){return e||(e=u),l+=n.slice(i,f).replace(bt,c),r&&(l+="'+__e("+r+")+'"),a&&(l+="';"+a+";__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),o||(o=a||ft.test(r||e)),i=f+t.length,t
+});var l=l+"';\n",p=u.imports,f=["_"],s=[r];p&&p!=ar&&(o=Q,p=_r({},p,a.imports),f=hr(p),s=S(p)),a=u=u.variable||a.variable,a||(u="obj",o?l="with("+u+"){"+l+"}":(p=RegExp("(\\(\\s*)"+u+"\\."+u+"\\b","g"),l=l.replace(gt,"$&"+u+".").replace(p,"$1__d"))),l=(o?l.replace(lt,""):l).replace(pt,"$1").replace(st,"$1;"),l="function("+u+"){"+(a?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(a?"":",__d="+u+"."+u+"||"+u)+";")+l+"return __p}";
+try{var v=Function(f,"return "+l).apply(t,s)}catch(g){throw g.source=l,g}return e?v(e):(v.source=l,v)},r.unescape=function(n){return n==W?"":(n+"").replace(ct,g)},r.uniqueId=function(n){var t=++ut;return(n==W?"":n+"")+t},r.all=$,r.any=M,r.detect=N,r.foldl=T,r.foldr=B,r.include=k,r.inject=T,gr(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(){var t=[this.__wrapped__];return St.apply(t,arguments),n.apply(r,t)})}),r.first=P,r.last=function(n,t,r){if(n){var e=n.length;return t==W||r?n[e-1]:v(n,It(0,e-t))
+}},r.take=P,r.head=P,gr(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(t,e){var u=n(this.__wrapped__,t,e);return t==W||e?u:new r(u)})}),r.VERSION="1.0.0-rc.3",r.prototype.toString=function(){return this.__wrapped__+""},r.prototype.value=J,r.prototype.valueOf=J,pr(["join","pop","shift"],function(n){var t=rt[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),pr(["push","reverse","sort","unshift"],function(n){var t=rt[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this
+}}),pr(["concat","slice","splice"],function(n){var t=rt[n];r.prototype[n]=function(){return new r(t.apply(this.__wrapped__,arguments))}}),Wt&&pr(["pop","shift","splice"],function(n){var t=rt[n],e="splice"==n;r.prototype[n]=function(){var n=this.__wrapped__,u=t.apply(n,arguments);return 0===n.length&&delete n[0],e?new r(u):u}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=r,define(function(){return r})):Y?typeof module=="object"&&module&&module.exports==Y?(module.exports=r)._=r:Y._=r:n._=r
+})(this);
\ No newline at end of file
diff --git a/lodash.underscore.js b/lodash.underscore.js
index 6922cef2b..4de230df2 100644
--- a/lodash.underscore.js
+++ b/lodash.underscore.js
@@ -282,9 +282,10 @@
var assignIteratorOptions = {
'args': 'object, source, guard',
'top':
- "for (var argsIndex = 1, argsLength = typeof guard == 'number' ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n" +
+ "var argsIndex = 0, argsLength = typeof guard == 'number' ? 2 : arguments.length;\n" +
+ 'while (++argsIndex < argsLength) {\n' +
' if ((iteratee = arguments[argsIndex])) {',
- 'objectLoop': 'result[index] = iteratee[index]',
+ 'loop': 'result[index] = iteratee[index]',
'bottom': ' }\n}'
};
@@ -292,15 +293,15 @@
* Reusable iterator options shared by `each`, `forIn`, and `forOwn`.
*/
var eachIteratorOptions = {
+ 'arrays': true,
'args': 'collection, callback, thisArg',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
- 'arrayLoop': 'if (callback(iteratee[index], index, collection) === false) return result',
- 'objectLoop': 'if (callback(iteratee[index], index, collection) === false) return result'
+ 'loop': 'if (callback(iteratee[index], index, collection) === false) return result'
};
/** Reusable iterator options for `forIn` and `forOwn` */
var forOwnIteratorOptions = {
- 'arrayLoop': null
+ 'arrays': false
};
/*--------------------------------------------------------------------------*/
@@ -424,24 +425,27 @@
*
* @private
* @param {Object} [options1, options2, ...] The compile options object(s).
+ * arrays - A boolean to specify support for iterating arrays and array-like objects.
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
* args - A string of comma separated arguments the iteration function will accept.
* top - A string of code to execute before the iteration branches.
- * arrayLoop - A string of code to execute in the array loop.
- * objectLoop - A string of code to execute in the object loop.
+ * loop - A string of code to execute in the object loop.
* bottom - A string of code to execute after the iteration branches.
*
* @returns {Function} Returns the compiled function.
*/
function createIterator() {
var data = {
- 'arrayLoop': '',
- 'bottom': '',
+ // support properties
'hasDontEnumBug': hasDontEnumBug,
- 'objectLoop': '',
'nonEnumArgs': nonEnumArgs,
'noCharByIndex': noCharByIndex,
'shadowed': shadowed,
+
+ // iterator options
+ 'arrays': false,
+ 'bottom': '',
+ 'loop': '',
'top': '',
'useHas': true
};
@@ -3343,10 +3347,10 @@
* @example
*
* _.random(0, 5);
- * // => a number between 1 and 5
+ * // => a number between 0 and 5
*
* _.random(5);
- * // => also a number between 1 and 5
+ * // => also a number between 0 and 5
*/
function random(min, max) {
if (min == null && max == null) {
diff --git a/test/test-build.js b/test/test-build.js
index 6e4f76447..3dae56ff3 100644
--- a/test/test-build.js
+++ b/test/test-build.js
@@ -351,6 +351,7 @@
object = { 'a': 1, 'b': 2, 'c': 3 },
noop = function() {},
string = 'abc',
+ template = '<%= a %>',
func = lodash[methodName];
try {
@@ -442,6 +443,9 @@
else if (utilityMethods.indexOf(methodName) > -1) {
if (methodName == 'result') {
func(object, 'b');
+ } else if (methodName == 'template') {
+ func(template, object);
+ func(template, null, { 'imports': object })(object);
} else if (methodName == 'times') {
func(2, noop, object);
} else {
@@ -765,6 +769,7 @@
ok(lodash.some([false, true, false]), '_.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);
equal(lodash.uniqueId(0), '1', '_.uniqueId should ignore a prefix of `0`: ' + basename);
start();
diff --git a/test/test.js b/test/test.js
index 8bc19960c..6f0392204 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1768,20 +1768,25 @@
});
test('should tokenize delimiters', function() {
- var compiled = _.template('');
- equal(compiled({ 'type': 1 }), '');
+ var compiled = _.template(''),
+ data = { 'type': 1 };
+
+ equal(compiled(data), '');
});
test('should work with "interpolate" delimiters containing ternary operators', function() {
- var compiled = _.template('<%= value ? value : "b" %>');
- equal(compiled({ 'value': 'a' }), 'a');
+ var compiled = _.template('<%= value ? value : "b" %>'),
+ data = { 'value': 'a' };
+
+ equal(compiled(data), 'a');
});
test('should parse delimiters with newlines', function() {
var expected = '<<\nprint("" + (value ? "yes" : "no") + "
")\n>>',
- compiled = _.template(expected, null, { 'evaluate': /<<(.+?)>>/g });
+ compiled = _.template(expected, null, { 'evaluate': /<<(.+?)>>/g }),
+ data = { 'value': true };
- equal(compiled({ 'value': true }), expected);
+ equal(compiled(data), expected);
});
test('should parse ES6 template delimiters', function() {
@@ -1789,6 +1794,13 @@
equal(_.template('1${value}3', data), '123');
equal(_.template('${"{" + value + "\\}"}', data), '{2}');
});
+
+ test('supports the "imports" option', function() {
+ var options = { 'imports': { 'a': 1 } },
+ compiled = _.template('<%= a %>', null, options);
+
+ equal(compiled({}), '1');
+ });
}());
/*--------------------------------------------------------------------------*/