Remove extend as a core dependency, and avoid uncatchable error in Java environments, and ensure templates are inlineable.

Former-commit-id: d7a4de60cf264893d9db68b97940744c6dd3cc3a
This commit is contained in:
John-David Dalton
2012-05-19 23:50:47 -04:00
parent b080cc4d23
commit 8846835ab8

255
lodash.js
View File

@@ -8,11 +8,16 @@
;(function(window, undefined) { ;(function(window, undefined) {
'use strict'; 'use strict';
/** Detect free variable `exports` */
var freeExports = typeof exports == 'object' && exports &&
(typeof global == 'object' && global && global == global.global && (window = global), exports);
/** Used to detect the JavaScript engine's argument length limit */ /** Used to detect the JavaScript engine's argument length limit */
var argsLimit = Math.pow(2, 32) - 1; var argsLimit = Math.pow(2, 32) - 1;
try { try {
(function() { // skip test if running in Java to avoid uncatchable error
window.environment && environment['java.home'] || (function() {
argsLimit = arguments.length; argsLimit = arguments.length;
}).apply(null, Array(argsLimit)); }).apply(null, Array(argsLimit));
} catch(e) { } } catch(e) { }
@@ -28,10 +33,6 @@
'\u2029': 'u2029' '\u2029': 'u2029'
}; };
/** Detect free variable `exports` */
var freeExports = typeof exports == 'object' && exports &&
(typeof global == 'object' && global && global == global.global && (window = global), exports);
/** /**
* Detect the JScript [[DontEnum]] bug: * Detect the JScript [[DontEnum]] bug:
* In IE < 9 an objects own properties, shadowing non-enumerable ones, are * In IE < 9 an objects own properties, shadowing non-enumerable ones, are
@@ -103,7 +104,6 @@
/** Native method shortcuts */ /** Native method shortcuts */
var concat = ArrayProto.concat, var concat = ArrayProto.concat,
hasOwnProperty = ObjectProto.hasOwnProperty, hasOwnProperty = ObjectProto.hasOwnProperty,
join = ArrayProto.join,
push = ArrayProto.push, push = ArrayProto.push,
slice = ArrayProto.slice, slice = ArrayProto.slice,
toString = ObjectProto.toString; toString = ObjectProto.toString;
@@ -123,7 +123,13 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/** The template used to create iterator functions */ /**
* The template used to create iterator functions.
*
* @private
* @param {Obect} data The data object used to populate the text.
* @returns {String} Returns the interpolated text.
*/
var iteratorTemplate = template( var iteratorTemplate = template(
// assign the `result` variable an initial value // assign the `result` variable an initial value
'var index, result<% if (init) { %> = <%= init %><% } %>;\n' + 'var index, result<% if (init) { %> = <%= init %><% } %>;\n' +
@@ -164,7 +170,7 @@
// value to `true`. Because of this Lo-Dash standardizes on skipping // value to `true`. Because of this Lo-Dash standardizes on skipping
// the the `prototype` property of functions regardless of its // the the `prototype` property of functions regardless of its
// [[Enumerable]] value. // [[Enumerable]] value.
' if (!(skipProto && index == "prototype")<% if (useHas) { %> && <%= hasExp %><% } %>) {\n' + ' if (!(skipProto && index == \'prototype\')<% if (useHas) { %> && <%= hasExp %><% } %>) {\n' +
' <%= objectBranch.inLoop %>;\n' + ' <%= objectBranch.inLoop %>;\n' +
' }' + ' }' +
' <% } %>\n' + ' <% } %>\n' +
@@ -177,9 +183,9 @@
' <% if (hasDontEnumBug) { %>\n' + ' <% if (hasDontEnumBug) { %>\n' +
' var ctor = <%= iteratedObject %>.constructor;\n' + ' var ctor = <%= iteratedObject %>.constructor;\n' +
' <% for (var k = 0; k < 7; k++) { %>\n' + ' <% for (var k = 0; k < 7; k++) { %>\n' +
' index = "<%= shadowed[k] %>";\n' + ' index = \'<%= shadowed[k] %>\';\n' +
' if (<%' + ' if (<%' +
' if (shadowed[k] == "constructor") {' + ' if (shadowed[k] == \'constructor\') {' +
' %>!(ctor && ctor.prototype === <%= iteratedObject %>) && <%' + ' %>!(ctor && ctor.prototype === <%= iteratedObject %>) && <%' +
' } %><%= hasExp %>) {\n' + ' } %><%= hasExp %>) {\n' +
' <%= objectBranch.inLoop %>;\n' + ' <%= objectBranch.inLoop %>;\n' +
@@ -477,7 +483,7 @@
*/ */
function tokenizeEscape(match, value) { function tokenizeEscape(match, value) {
var index = tokenized.length; var index = tokenized.length;
tokenized[index] = "'+\n((__t = (" + value + ")) == null ? '' : __e(__t)) +\n'"; tokenized[index] = "'+\n((__t = (" + value + ")) == null ? '' : _.escape(__t)) +\n'";
return token + index; return token + index;
} }
@@ -2892,17 +2898,17 @@
// if `options.variable` is not specified, add `data` to the top of the scope chain // if `options.variable` is not specified, add `data` to the top of the scope chain
if (!variable) { if (!variable) {
variable = defaults.variable; variable = defaults.variable || 'object';
text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n'; text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n';
} }
text = 'function(' + variable + ') {\n' + text = 'function(' + variable + ') {\n' +
'var __p, __t;\n' + 'var __p, __t, __j = Array.prototype.join;\n' +
'function print() { __p += __j.call(arguments, "") }\n' + 'function print() { __p += __j.call(arguments, \'\') }\n' +
text + text +
'return __p\n}'; 'return __p\n}';
result = Function('_, __e, __j', 'return ' + text)(lodash, escape, join); result = Function('_', 'return ' + text)(lodash);
if (data) { if (data) {
return result(data); return result(data);
@@ -3022,8 +3028,6 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
extend(lodash, {
/** /**
* The semantic version number. * The semantic version number.
* *
@@ -3031,7 +3035,7 @@
* @memberOf _ * @memberOf _
* @type String * @type String
*/ */
'VERSION': '0.1.0', lodash.VERSION = '0.1.0';
/** /**
* By default, Lo-Dash uses ERB-style template delimiters, change the * By default, Lo-Dash uses ERB-style template delimiters, change the
@@ -3041,7 +3045,7 @@
* @memberOf _ * @memberOf _
* @type Object * @type Object
*/ */
'templateSettings': { lodash.templateSettings = {
/** /**
* Used to detect `data` property values to be HTML-escaped. * Used to detect `data` property values to be HTML-escaped.
@@ -3078,118 +3082,125 @@
* @type String * @type String
*/ */
'variable': 'object' 'variable': 'object'
}, };
// assign static methods // assign static methods
'after': after, lodash.after = after;
'bind': bind, lodash.bind = bind;
'bindAll': bindAll, lodash.bindAll = bindAll;
'chain': chain, lodash.chain = chain;
'clone': clone, lodash.clone = clone;
'compact': compact, lodash.compact = compact;
'compose': compose, lodash.compose = compose;
'contains': contains, lodash.contains = contains;
'debounce': debounce, lodash.debounce = debounce;
'defaults': defaults, lodash.defaults = defaults;
'defer': defer, lodash.defer = defer;
'delay': delay, lodash.delay = delay;
'difference': difference, lodash.difference = difference;
'escape': escape, lodash.escape = escape;
'every': every, lodash.every = every;
'extend': extend, lodash.extend = extend;
'filter': filter, lodash.filter = filter;
'find': find, lodash.find = find;
'first': first, lodash.first = first;
'flatten': flatten, lodash.flatten = flatten;
'forEach': forEach, lodash.forEach = forEach;
'functions': functions, lodash.functions = functions;
'groupBy': groupBy, lodash.groupBy = groupBy;
'has': has, lodash.has = has;
'identity': identity, lodash.identity = identity;
'indexOf': indexOf, lodash.indexOf = indexOf;
'initial': initial, lodash.initial = initial;
'intersection': intersection, lodash.intersection = intersection;
'invoke': invoke, lodash.invoke = invoke;
'isArguments': isArguments, lodash.isArguments = isArguments;
'isArray': isArray, lodash.isArray = isArray;
'isBoolean': isBoolean, lodash.isBoolean = isBoolean;
'isDate': isDate, lodash.isDate = isDate;
'isElement': isElement, lodash.isElement = isElement;
'isEmpty': isEmpty, lodash.isEmpty = isEmpty;
'isEqual': isEqual, lodash.isEqual = isEqual;
'isFinite': isFinite, lodash.isFinite = isFinite;
'isFunction': isFunction, lodash.isFunction = isFunction;
'isNaN': isNaN, lodash.isNaN = isNaN;
'isNull': isNull, lodash.isNull = isNull;
'isNumber': isNumber, lodash.isNumber = isNumber;
'isObject': isObject, lodash.isObject = isObject;
'isRegExp': isRegExp, lodash.isRegExp = isRegExp;
'isString': isString, lodash.isString = isString;
'isUndefined': isUndefined, lodash.isUndefined = isUndefined;
'keys': keys, lodash.keys = keys;
'last': last, lodash.last = last;
'lastIndexOf': lastIndexOf, lodash.lastIndexOf = lastIndexOf;
'map': map, lodash.map = map;
'max': max, lodash.max = max;
'memoize': memoize, lodash.memoize = memoize;
'min': min, lodash.min = min;
'mixin': mixin, lodash.mixin = mixin;
'noConflict': noConflict, lodash.noConflict = noConflict;
'once': once, lodash.once = once;
'partial': partial, lodash.partial = partial;
'pick': pick, lodash.pick = pick;
'pluck': pluck, lodash.pluck = pluck;
'range': range, lodash.range = range;
'reduce': reduce, lodash.reduce = reduce;
'reduceRight': reduceRight, lodash.reduceRight = reduceRight;
'reject': reject, lodash.reject = reject;
'rest': rest, lodash.rest = rest;
'result': result, lodash.result = result;
'shuffle': shuffle, lodash.shuffle = shuffle;
'size': size, lodash.size = size;
'some': some, lodash.some = some;
'sortBy': sortBy, lodash.sortBy = sortBy;
'sortedIndex': sortedIndex, lodash.sortedIndex = sortedIndex;
'tap': tap, lodash.tap = tap;
'template': template, lodash.template = template;
'throttle': throttle, lodash.throttle = throttle;
'times': times, lodash.times = times;
'toArray': toArray, lodash.toArray = toArray;
'union': union, lodash.union = union;
'uniq': uniq, lodash.uniq = uniq;
'uniqueId': uniqueId, lodash.uniqueId = uniqueId;
'values': values, lodash.values = values;
'without': without, lodash.without = without;
'wrap': wrap, lodash.wrap = wrap;
'zip': zip, lodash.zip = zip;
// assign aliases // assign aliases
'all': every, lodash.all = every;
'any': some, lodash.any = some;
'collect': map, lodash.collect = map;
'detect': find, lodash.detect = find;
'each': forEach, lodash.each = forEach;
'foldl': reduce, lodash.foldl = reduce;
'foldr': reduceRight, lodash.foldr = reduceRight;
'head': first, lodash.head = first;
'include': contains, lodash.include = contains;
'inject': reduce, lodash.inject = reduce;
'intersect': intersection, lodash.intersect = intersection;
'methods': functions, lodash.methods = functions;
'select': filter, lodash.select = filter;
'tail': rest, lodash.tail = rest;
'take': first, lodash.take = first;
'unique': uniq lodash.unique = uniq;
});
// add pseudo private template used and removed in the build process
lodash._iteratorTemplate = iteratorTemplate;
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// assign private `LoDash` constructor's prototype // assign private `LoDash` constructor's prototype
LoDash.prototype = lodash.prototype; LoDash.prototype = lodash.prototype;
// add all of the static functions to `LoDash.prototype` // add all static functions to `LoDash.prototype`
mixin(lodash); mixin(lodash);
// add `LoDash.prototype.chain` after calling `mixin()` to avoid overwriting
// it with the wrapped `lodash.chain`
LoDash.prototype.chain = wrapperChain;
LoDash.prototype.value = wrapperValue;
// add all mutator Array functions to the wrapper. // add all mutator Array functions to the wrapper.
forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
var func = ArrayProto[methodName]; var func = ArrayProto[methodName];
@@ -3233,12 +3244,6 @@
}; };
}); });
// add `chain` and `value` after calling to `mixin()` to avoid getting wrapped
extend(LoDash.prototype, {
'chain': wrapperChain,
'value': wrapperValue
});
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// expose Lo-Dash // expose Lo-Dash