Move "escape" and "evaluate" delimiters to their own regexes. Cleanup the _ docs and iteratorTemplate.

This commit is contained in:
John-David Dalton
2013-12-15 01:19:25 -08:00
parent d2b97d8aea
commit aaaf452fdc
8 changed files with 390 additions and 368 deletions

58
dist/lodash.compat.js vendored
View File

@@ -60,8 +60,10 @@
/** Used to detected named functions */
var reFuncName = /^\s*function[ \n\r\t]+\w/;
/** Used to match "interpolate" template delimiters */
var reInterpolate = /<%=([\s\S]+?)%>/g;
/** Used to match template delimiters */
var reEscape = /<%-([\s\S]+?)%>/g,
reEvaluate = /<%([\s\S]+?)%>/g,
reInterpolate = /<%=([\s\S]+?)%>/g;
/** Used to match leading whitespace and zeros to be removed */
var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
@@ -581,16 +583,16 @@
*
* The chainable wrapper functions are:
* `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
* `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
* `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
* `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
* `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
* `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
* `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
* and `zip`
* `compose`, `concat`, `constant`, `countBy`, `create`, `createCallback`,
* `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`,
* `flatten`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
* `forOwnRight`, `functions`, `groupBy`, `indexBy`, `initial`, `intersection`,
* `invert`, `invoke`, `keys`, `map`, `mapValues`, `max`, `memoize`, `merge`,
* `min`, `noop`, `object`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `pick`, `pluck`, `property`, `pull`, `push`, `range`, `reject`, `remove`,
* `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `tap`,
* `throttle`, `times`, `toArray`, `transform`, `union`, `uniq`, `unshift`,
* `unzip`, `values`, `where`, `without`, `wrap`, `xor`, and `zip`
*
* The non-chainable wrapper functions are:
* `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
@@ -598,12 +600,12 @@
* `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
* `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
* `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
* `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
* `template`, `unescape`, `uniqueId`, and `value`
* `lastIndexOf`, `mixin`, `noConflict`, `now`, `parseInt`, `pop`, `random`,
* `reduce`, `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`,
* `runInContext`, `template`, `unescape`, `uniqueId`, and `value`
*
* The wrapper functions `first` and `last` return wrapped values when `n` is
* provided, otherwise they return unwrapped values.
* The wrapper functions `first`, `last`, and `sample` return wrapped values
* when `n` is provided, otherwise they return unwrapped values.
*
* Explicit chaining can be enabled by using the `_.chain` method.
*
@@ -821,7 +823,7 @@
* @memberOf _.templateSettings
* @type RegExp
*/
'escape': /<%-([\s\S]+?)%>/g,
'escape': reEscape,
/**
* Used to detect code to be evaluated.
@@ -829,7 +831,7 @@
* @memberOf _.templateSettings
* @type RegExp
*/
'evaluate': /<%([\s\S]+?)%>/g,
'evaluate': reEvaluate,
/**
* Used to detect `data` property values to inject.
@@ -878,13 +880,13 @@
var __p = 'var result = ' +
(obj.init) +
';\nif (!(object && objectTypes[typeof object])) return result;\n' +
';\nif (!(object && objectTypes[typeof object])) {\n return result;\n}\n' +
(obj.top) +
';';
if (support.nonEnumArgs) {
__p += '\nvar length = object.length;\nif (length && isArguments(object)) {\n key = -1;\n while (++key < length) {\n key += \'\';\n ' +
(obj.loop) +
';\n }\n return result\n}';
';\n }\n return result;\n}';
}
if (support.enumPrototypes) {
@@ -901,7 +903,7 @@
__p += '\nfor (var key in object) {\n';
if (obj.useHas) { conditions.push('hasOwnProperty.call(object, key)'); }
if (conditions.length) {
__p += ' if (' +
__p += ' if (' +
(conditions.join(' && ')) +
') {\n ';
}
@@ -909,11 +911,11 @@
(obj.loop) +
'; ';
if (conditions.length) {
__p += '\n }';
__p += '\n }';
}
__p += '\n}\n';
if (support.nonEnumShadows) {
__p += '\nif (object !== objectProto) {\n var ctor = object.constructor,\n isProto = object === (ctor && ctor.prototype),\n className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),\n nonEnum = nonEnumProps[className];\n ';
__p += '\nif (object !== objectProto) {\n var ctor = object.constructor,\n isProto = object === (ctor && ctor.prototype),\n className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),\n nonEnum = nonEnumProps[className];\n ';
for (var index = 0; index < 7; index++) {
__p += '\n key = \'' +
(obj.shadowedProps[index]) +
@@ -923,11 +925,11 @@
}
__p += ') {\n ' +
(obj.loop) +
';\n } ';
';\n } ';
}
__p += '\n}';
}
__p += '\nreturn result';
__p += '\nreturn result;';
return __p
};
@@ -1912,7 +1914,7 @@
var shimKeys = createIterator({
'args': 'object',
'init': '[]',
'top': 'if (!(objectTypes[typeof object])) return result',
'top': '',
'loop': 'result.push(key)',
'useHas': true
});
@@ -2337,7 +2339,7 @@
'args': 'object, callback, thisArg',
'init': 'object',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3)",
'loop': 'if (callback(object[key], key, object) === false) return result',
'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }',
'useHas': false
});