diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 746693c49..a07a89427 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -6837,7 +6837,8 @@ importsKeys = keys(imports), importsValues = values(imports); - var isEvaluating, + var isEscaping, + isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '"; @@ -6858,6 +6859,7 @@ // replace delimiters with snippets if (escapeValue) { + isEscaping = true; source += "' +\n__e(" + escapeValue + ") +\n'"; } if (evaluateValue) { @@ -6878,12 +6880,9 @@ // if `variable` is not specified, wrap a with-statement around the generated // code to add the data object to the top of the scope chain - var variable = options.variable, - hasVariable = variable; - - if (!hasVariable) { - variable = 'obj'; - source = 'with (' + variable + ') {\n' + source + '\n}\n'; + var variable = options.variable; + if (!variable) { + source = 'with (obj) {\n' + source + '\n}\n'; } // cleanup code by stripping empty strings source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) @@ -6891,9 +6890,16 @@ .replace(reEmptyStringTrailing, '$1;'); // frame code as the function body - source = 'function(' + variable + ') {\n' + - (hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') + - "var __t, __p = '', __e = _.escape" + + source = 'function(' + (variable || 'obj') + ') {\n' + + (variable + ? '' + : 'obj || (obj = {});\n' + ) + + "var __t, __p = ''" + + (isEscaping + ? ', __e = _.escape' + : '' + ) + (isEvaluating ? ', __j = Array.prototype.join;\n' + "function print() { __p += __j.call(arguments, '') }\n" diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 5a48733c9..837d2601c 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -55,9 +55,9 @@ return"boolean"!=u&&null!=t&&(e=r,r=t,t=false,"number"!=u&&"string"!=u||!e||e[r] }),e},u.findLast=function(n,t,r){var e;return t=u.createCallback(t,r,3),vt(n,function(n,r,u){return t(n,r,u)?(e=n,false):void 0}),e},u.findLastIndex=function(n,t,r){var e=n?n.length:0;for(t=u.createCallback(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},u.findLastKey=function(n,t,r){var e;return t=u.createCallback(t,r,3),_t(n,function(n,r,u){return t(n,r,u)?(e=r,false):void 0}),e},u.has=function(n,t){return n?Dr.call(n,t):false},u.identity=sr,u.indexOf=Pt,u.isArguments=Rt,u.isArray=_e,u.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&Tr.call(n)==tt||false },u.isDate=function(n){return n&&typeof n=="object"&&Tr.call(n)==rt||false},u.isElement=or,u.isEmpty=function(n){var t=true;if(!n)return t;var r=Tr.call(n),e=n.length;return r==nt||r==lt||(ce.argsClass?r==Z:Rt(n))||r==at&&typeof e=="number"&&ar(n.splice)?!e:(dt(n,function(){return t=false}),t)},u.isEqual=function(n,t,r,e){return wt(n,t,typeof r=="function"&&H(r,e,2))},u.isFinite=function(n){return Qr(n)&&!Yr(parseFloat(n))},u.isFunction=ar,u.isNaN=function(n){return lr(n)&&n!=+n},u.isNull=function(n){return null===n },u.isNumber=lr,u.isObject=ir,u.isPlainObject=we,u.isRegExp=function(n){var t=typeof n;return n&&("function"==t||"object"==t)&&Tr.call(n)==it||false},u.isString=fr,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?ne(0,e+r):te(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=hr,u.noConflict=function(){return n._=Rr,this},u.noop=vr,u.now=Oe,u.parseInt=Ee,u.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ue(),te(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):xt(n,t) -},u.reduce=Jt,u.reduceRight=Qt,u.result=function(n,t,r){var e=null==n?w:n[t];return typeof e=="undefined"?r:ar(e)?n[t]():e},u.runInContext=_,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:je(n).length},u.some=Zt,u.sortedIndex=$t,u.template=function(n,t,r){var e=u.templateSettings;n=kr(n||""),r=er({},r,e);var o,a=er({},r.imports,e.imports),e=je(a),a=cr(a),i=0,l=r.interpolate||U,c="__p+='",l=Cr((r.escape||U).source+"|"+l.source+"|"+(l===D?W:U).source+"|"+(r.evaluate||U).source+"|$","g"); -n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(X,f),r&&(c+="'+__e("+r+")+'"),a&&(o=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t}),c+="';",l=r=r.variable,l||(r="obj",c="with("+r+"){"+c+"}"),c=(o?c.replace(T,""):c).replace(P,"$1").replace(q,"$1;"),c="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=_r(e,"return "+c).apply(w,a) -}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},u.trim=xe,u.trimLeft=Ce,u.trimRight=ke,u.unescape=function(n){return null==n?"":(n=kr(n),0>n.indexOf(";")?n:n.replace(F,b))},u.uniqueId=function(n){var t=++R;return kr(null==n?"":n)+t},u.all=Kt,u.any=Zt,u.detect=Ut,u.findWhere=Ut,u.foldl=Jt,u.foldr=Qt,u.include=zt,u.inject=Jt,hr(function(){var n={};return dt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Tt,u.last=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; +},u.reduce=Jt,u.reduceRight=Qt,u.result=function(n,t,r){var e=null==n?w:n[t];return typeof e=="undefined"?r:ar(e)?n[t]():e},u.runInContext=_,u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:je(n).length},u.some=Zt,u.sortedIndex=$t,u.template=function(n,t,r){var e=u.templateSettings;n=kr(n||""),r=er({},r,e);var o,a,i=er({},r.imports,e.imports),e=je(i),i=cr(i),l=0,c=r.interpolate||U,p="__p+='",c=Cr((r.escape||U).source+"|"+c.source+"|"+(c===D?W:U).source+"|"+(r.evaluate||U).source+"|$","g"); +n.replace(c,function(t,r,e,u,i,c){return e||(e=u),p+=n.slice(l,c).replace(X,f),r&&(o=true,p+="'+__e("+r+")+'"),i&&(a=true,p+="';"+i+";\n__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),l=c+t.length,t}),p+="';",(r=r.variable)||(p="with(obj){"+p+"}"),p=(a?p.replace(T,""):p).replace(P,"$1").replace(q,"$1;"),p="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+p+"return __p}";try{var s=_r(e,"return "+p).apply(w,i) +}catch(g){throw g.source=p,g}return t?s(t):(s.source=p,s)},u.trim=xe,u.trimLeft=Ce,u.trimRight=ke,u.unescape=function(n){return null==n?"":(n=kr(n),0>n.indexOf(";")?n:n.replace(F,b))},u.uniqueId=function(n){var t=++R;return kr(null==n?"":n)+t},u.all=Kt,u.any=Zt,u.detect=Ut,u.findWhere=Ut,u.foldl=Jt,u.foldr=Qt,u.include=zt,u.inject=Jt,hr(function(){var n={};return dt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Tt,u.last=function(n,t,r){var e=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o; for(t=u.createCallback(t,r,3);a--&&t(n[a],a,n);)e++}else if(e=t,null==e||r)return n?n[o-1]:w;return e=o-e,Ft(n,0"']/g,L=/<%-([\s\S]+?)%>/g,B=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,W=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,z=/\w*$/,K=/^\s*function[ \n\r\t]+\w/,M=/^0[xX]/,U=/($^)/,V=/\bthis\b/,X=/['\n\r\t\u2028\u2029\\]/g,G=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",H=[],J=[],Q="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Y="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Z="[object Arguments]",nt="[object Array]",tt="[object Boolean]",rt="[object Date]",et="[object Error]",ut="[object Function]",ot="[object Number]",at="[object Object]",it="[object RegExp]",lt="[object String]",ft={}; diff --git a/dist/lodash.js b/dist/lodash.js index 2ee535c33..983bed1f2 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -6558,7 +6558,8 @@ importsKeys = keys(imports), importsValues = values(imports); - var isEvaluating, + var isEscaping, + isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '"; @@ -6579,6 +6580,7 @@ // replace delimiters with snippets if (escapeValue) { + isEscaping = true; source += "' +\n__e(" + escapeValue + ") +\n'"; } if (evaluateValue) { @@ -6599,12 +6601,9 @@ // if `variable` is not specified, wrap a with-statement around the generated // code to add the data object to the top of the scope chain - var variable = options.variable, - hasVariable = variable; - - if (!hasVariable) { - variable = 'obj'; - source = 'with (' + variable + ') {\n' + source + '\n}\n'; + var variable = options.variable; + if (!variable) { + source = 'with (obj) {\n' + source + '\n}\n'; } // cleanup code by stripping empty strings source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) @@ -6612,9 +6611,16 @@ .replace(reEmptyStringTrailing, '$1;'); // frame code as the function body - source = 'function(' + variable + ') {\n' + - (hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') + - "var __t, __p = '', __e = _.escape" + + source = 'function(' + (variable || 'obj') + ') {\n' + + (variable + ? '' + : 'obj || (obj = {});\n' + ) + + "var __t, __p = ''" + + (isEscaping + ? ', __e = _.escape' + : '' + ) + (isEvaluating ? ', __j = Array.prototype.join;\n' + "function print() { __p += __j.call(arguments, '') }\n" diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 2e504148d..fe771f3e6 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,57 +5,57 @@ */ ;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202e||13e||8202r||13r||8202=A&&(o=r,e=ae(e));++uo(e,f)&&a.push(f)}return a}function ht(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++r=A,l=[];if(f)var s=ae(),i=r;else s=u?c():l;for(;++oi(s,h))&&((u||f)&&s.push(h),l.push(g)) -}return!f&&u&&p(s),l}function xt(n,t,r){for(var e=t.length,u=-1,o=Jr(r.length-e,0),i=-1,a=n.length,f=vr(o+a);++i=A&&(o=r,e=ae(e));++uo(e,f)&&a.push(f)}return a}function ht(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++r=A,l=[];if(f)var s=ae(),i=r;else s=u?c():l;for(;++oi(s,h))&&((u||f)&&s.push(h),l.push(g)) +}return!f&&u&&p(s),l}function xt(n,t,r){for(var e=t.length,u=-1,o=Jr(r.length-e,0),i=-1,a=n.length,f=vr(o+a);++ir&&(r=0),c&&(i=[]),p&&(a=[]),s=[n,t,r,e,u,o,i,a],t==w||t==(w|C)?S(s):pt(s))}function At(){var n=(n=y.indexOf)===It?t:n;return n}function St(n){return typeof n=="function"&&Rr.test($r.call(n))}function Et(n){var t,r;return n&&Nr.call(n)==et&&(Dr.call(n,"constructor")||(t=n.constructor,!ur(t)||t instanceof t))?(o(n,function(n,t){r=t }),typeof r=="undefined"||Dr.call(n,r)):false}function Nt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n)==Q||false}function Rt(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1;for(t=y.createCallback(t,r,3);++oe?Jr(0,u+e):e||0;else if(e)return e=$t(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Tt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0; -for(t=y.createCallback(t,r,3);++ut?t=Jr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Jr(u+r,0):r>u&&(r=u),u=r-t||0,r=vr(u);++e>>1,r(n[e])t?t=Jr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Jr(u+r,0):r>u&&(r=u),u=r-t||0,r=vr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!he(n)&&ar(n))return Mr?Mr.call(n,t,r):-1r?Jr(0,e+r):r)||0,-1o&&(o=a)}else t=null==t&&ar(n)?e:y.createCallback(t,r,3),ht(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Gt(n,t,r,e){var u=3>arguments.length; -t=y.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=y.createCallback(t,e,4),vt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Jt(n){var t=-1,r=n?n.length:0,e=vr(typeof r=="number"?r:0);return ht(n,function(n){var r=kt(0,++t);e[t]=e[r],e[r]=n}),e}function Qt(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0; +t=y.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=y.createCallback(t,e,4),vt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Jt(n){var t=-1,r=n?n.length:0,e=vr(typeof r=="number"?r:0);return ht(n,function(n){var r=jt(0,++t);e[t]=e[r],e[r]=n}),e}function Qt(n,t,r){var e;t=y.createCallback(t,r,3),r=-1;var u=n?n.length:0; if(typeof u=="number"){for(;++rarguments.length)return Ot(n,w,null,t);if(n)var r=n[N]?n[N][2]:n.length,e=Ft(arguments,2),r=r-e.length;return Ot(n,w|C,r,t,e)}function Zt(n,t,r){function e(){c&&Tr(c),i=c=p=_,(h||g!==t)&&(s=_e(),a=n.apply(l,o),c||i||(o=l=null))}function u(){var r=t-(_e()-f);0>=r||r>t?(i&&Tr(i),r=p,i=c=p=_,r&&(s=_e(),a=n.apply(l,o),c||i||(o=l=null))):c=zr(u,r)}var o,i,a,f,l,c,p,s=0,g=false,h=true; if(!ur(n))throw new xr;if(t=Jr(0,t)||0,true===r)var v=true,h=false;else or(r)&&(v=r.leading,g="maxWait"in r&&(Jr(t,r.maxWait)||0),h="trailing"in r?r.trailing:h);return function(){if(o=arguments,f=_e(),l=this,p=h&&(c||!v),false===g)var r=v&&!c;else{i||v||(s=f);var y=g-(f-s),m=0>=y||y>g;m?(i&&(i=Tr(i)),s=f,a=n.apply(l,o)):i||(i=zr(e,y))}return m&&c?c=Tr(c):c||t===g||(c=zr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function nr(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3--n?t.apply(this,arguments):void 0}},y.assign=nr,y.at=function(n,t){var r=arguments,e=-1,u=mt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=vr(o);++earguments.length?Ot(t,w|k,null,n):Ot(t,w|k|C,null,n,Ft(arguments,2))},y.chain=function(n){return n=new m(n),n.__chain__=true,n},y.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t--n?t.apply(this,arguments):void 0}},y.assign=nr,y.at=function(n,t){var r=arguments,e=-1,u=mt(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=vr(o);++earguments.length?Ot(t,w|j,null,n):Ot(t,w|j|C,null,n,Ft(arguments,2))},y.chain=function(n){return n=new m(n),n.__chain__=true,n},y.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t=A&&ae(e?n[e]:f)))}var a=n[0],s=-1,g=a?a.length:0,h=[]; n:for(;++s(v?r(v,l):i(f,l))){for(e=u,(v||f).push(l);--e;)if(v=o[e],0>(v?r(v,l):i(n[e],l)))continue n;h.push(l)}}return p(o),p(f),h},y.invert=function(n,t){for(var r=-1,e=ye(n),u=e.length,o={};++rarguments.length&&typeof u=="number")for(;++rr?Jr(0,e+r):Qr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=sr,y.noConflict=function(){return n._=Er,this},y.noop=gr,y.now=_e,y.parseInt=we,y.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ne(),Qr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):kt(n,t) -},y.reduce=Gt,y.reduceRight=Ht,y.result=function(n,t,r){var e=null==n?_:n[t];return typeof e=="undefined"?r:ur(e)?n[t]():e},y.runInContext=b,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ye(n).length},y.some=Qt,y.sortedIndex=$t,y.template=function(n,t,r){var e=y.templateSettings;n=jr(n||""),r=tr({},r,e);var u,o=tr({},r.imports,e.imports),e=ye(o),o=fr(o),i=0,a=r.interpolate||M,f="__p+='",a=kr((r.escape||M).source+"|"+a.source+"|"+(a===W?z:M).source+"|"+(r.evaluate||M).source+"|$","g"); -n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(V,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(I,""):f).replace(T,"$1").replace(F,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=dr(e,"return "+f).apply(_,o) -}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},y.trim=me,y.trimLeft=de,y.trimRight=be,y.unescape=function(n){return null==n?"":(n=jr(n),0>n.indexOf(";")?n:n.replace($,d))},y.uniqueId=function(n){var t=++R;return jr(null==n?"":n)+t},y.all=Lt,y.any=Qt,y.detect=Kt,y.findWhere=Kt,y.foldl=Gt,y.foldr=Ht,y.include=zt,y.inject=Gt,sr(function(){var n={};return dt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=Rt,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u; -for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,Ft(n,0"']/g,D=/<%-([\s\S]+?)%>/g,q=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,P=/^\s*function[ \n\r\t]+\w/,K=/^0[xX]/,M=/($^)/,U=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",G=[],H=[],J="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Function]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it={}; +var e=-1,u=vr(n);for(t=ct(t,r,1);++er?Jr(0,e+r):Qr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},y.mixin=sr,y.noConflict=function(){return n._=Er,this},y.noop=gr,y.now=_e,y.parseInt=we,y.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=ne(),Qr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):jt(n,t) +},y.reduce=Gt,y.reduceRight=Ht,y.result=function(n,t,r){var e=null==n?_:n[t];return typeof e=="undefined"?r:ur(e)?n[t]():e},y.runInContext=d,y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ye(n).length},y.some=Qt,y.sortedIndex=$t,y.template=function(n,t,r){var e=y.templateSettings;n=kr(n||""),r=tr({},r,e);var u,o,i=tr({},r.imports,e.imports),e=ye(i),i=fr(i),a=0,f=r.interpolate||M,c="__p+='",f=jr((r.escape||M).source+"|"+f.source+"|"+(f===W?z:M).source+"|"+(r.evaluate||M).source+"|$","g"); +n.replace(f,function(t,r,e,i,f,p){return e||(e=i),c+=n.slice(a,p).replace(V,l),r&&(u=true,c+="'+__e("+r+")+'"),f&&(o=true,c+="';"+f+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),a=p+t.length,t}),c+="';",(r=r.variable)||(c="with(obj){"+c+"}"),c=(o?c.replace(I,""):c).replace(T,"$1").replace(F,"$1;"),c="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(u?",__e=_.escape":"")+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=br(e,"return "+c).apply(_,i) +}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},y.trim=me,y.trimLeft=be,y.trimRight=de,y.unescape=function(n){return null==n?"":(n=kr(n),0>n.indexOf(";")?n:n.replace($,b))},y.uniqueId=function(n){var t=++R;return kr(null==n?"":n)+t},y.all=Lt,y.any=Qt,y.detect=Kt,y.findWhere=Kt,y.foldl=Gt,y.foldr=Ht,y.include=zt,y.inject=Gt,sr(function(){var n={};return bt(y,function(t,r){y.prototype[r]||(n[r]=t)}),n}(),false),y.first=Rt,y.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u; +for(t=y.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:_;return e=u-e,Ft(n,0"']/g,D=/<%-([\s\S]+?)%>/g,q=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,z=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,P=/^\s*function[ \n\r\t]+\w/,K=/^0[xX]/,M=/($^)/,U=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",G=[],H=[],J="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Q="[object Arguments]",Y="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Function]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it={}; it[tt]=false,it[Q]=it[Y]=it[Z]=it[nt]=it[rt]=it[et]=it[ut]=it[ot]=true;var at={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},lt={"&":"&","<":"<",">":">",'"':""","'":"'"},ct={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={"function":true,object:true},st={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},gt=pt[typeof window]&&window||this,ht=pt[typeof exports]&&exports&&!exports.nodeType&&exports,pt=pt[typeof module]&&module&&!module.nodeType&&module,vt=ht&&pt&&typeof global=="object"&&global; -!vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(gt=vt);var vt=pt&&pt.exports===ht&&ht,yt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(gt._=yt, define(function(){return yt})):ht&&pt?vt?(pt.exports=yt)._=yt:ht._=yt:gt._=yt}).call(this); \ No newline at end of file +!vt||vt.global!==vt&&vt.window!==vt&&vt.self!==vt||(gt=vt);var vt=pt&&pt.exports===ht&&ht,yt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(gt._=yt, define(function(){return yt})):ht&&pt?vt?(pt.exports=yt)._=yt:ht._=yt:gt._=yt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 0c42cbe59..a43068bdd 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -4700,10 +4700,9 @@ source += "';\n"; if (!variable) { - variable = 'obj'; - source = 'with (' + variable + ' || {}) {\n' + source + '\n}\n'; + source = 'with (obj || {}) {\n' + source + '\n}\n'; } - source = 'function(' + variable + ') {\n' + + source = 'function(' + (variable || 'obj') + ') {\n' + "var __t, __p = '', __j = Array.prototype.join;\n" + "function print() { __p += __j.call(arguments, '') }\n" + source + diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 5926afd9c..9e667de29 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -36,7 +36,7 @@ return u},f.reject=function(n,r,t){return r=Z(r,t,3),R(n,function(n,t,e){return! for(r||!e||lt(n[0])||(r=[]);++tt?Yr(0,e+t):Zr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},f.mixin=tr,f.noConflict=function(){return Nr._=Mr,this},f.now=pt,f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Cr(rt()*(r-n+1))},f.reduce=W,f.reduceRight=z,f.result=function(n,r){if(null!=n){var t=n[r];return K(t)?n[r]():t}},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:ct(n).length},f.some=P,f.sortedIndex=N,f.template=function(n,r,t){var e=f,u=e.templateSettings; -n=(n||"")+"",t=H({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||yr).source+"|"+(t.interpolate||yr).source+"|"+(t.evaluate||yr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(mr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r}),a+="';",u||(u="obj",a="with("+u+"||{}){"+a+"}"),a="function("+u+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; +n=(n||"")+"",t=H({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||yr).source+"|"+(t.interpolate||yr).source+"|"+(t.evaluate||yr).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(mr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r}),a+="';",u||(a="with(obj||{}){"+a+"}"),a="function("+(u||"obj")+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}"; try{var l=Function("_","return "+a)(e)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(hr,i))},f.uniqueId=function(n){var r=++gr+"";return n?n+r:r},f.all=B,f.any=P,f.detect=$,f.findWhere=$,f.foldl=W,f.foldr=z,f.include=F,f.inject=W,f.first=E,f.last=function(n,r,t){var e=0,u=n?n.length:0;if(typeof r!="number"&&null!=r){var o=u;for(r=Z(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:ur;return e=u-e,S(n,0BC'); - equal(compiled({ 'a': 'A' }), 'ABC'); - }); + test('should escape values in "escape" delimiters', 1, function() { + var escaped = '

&<>"'\/

', + unescaped = '&<>"\'\/'; - test('should support escaped values in "interpolation" delimiters', 1, function() { - var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'); - equal(compiled({ 'a': true }), 'a="A"'); + var compiled = _.template('

<%- value %>

'); + equal(compiled({ 'value': unescaped }), escaped); }); test('should evaluate JavaScript in "evaluate" delimiters', 1, function() { @@ -7504,12 +7502,14 @@ equal(actual, '
  • A
  • B
'); }); - test('should escape values in "escape" delimiters', 1, function() { - var escaped = '

&<>"'\/

', - unescaped = '&<>"\'\/'; + test('should interpolate data object properties', 1, function() { + var compiled = _.template('<%= a %>BC'); + equal(compiled({ 'a': 'A' }), 'ABC'); + }); - var compiled = _.template('

<%- value %>

'); - equal(compiled({ 'value': unescaped }), escaped); + test('should support escaped values in "interpolation" delimiters', 1, function() { + var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'); + equal(compiled({ 'a': true }), 'a="A"'); }); test('should work with "interpolate" delimiters containing ternary operators', 1, function() { @@ -7568,6 +7568,11 @@ equal(_.template('${"{" + value + "\\}"}', data), '{2}'); }); + test('should not reference `_.escape` when "escape" delimiters are not used', 1, function() { + var compiled = _.template('<%= typeof __e %>'); + equal(compiled({}), 'undefined'); + }); + test('should allow referencing variables declared in "evaluate" delimiters from other delimiters', 1, function() { var compiled = _.template('<% var b = a; %><%= b.value %>'), data = { 'a': { 'value': 1 } };