Make lodash work with modules by avoiding circular dependencies.

Former-commit-id: 57161fd81b837db22fcfe1d318e220f6ca4b1e21
This commit is contained in:
John-David Dalton
2013-06-29 22:12:12 -07:00
parent 6a74d102a4
commit 913406b568
2 changed files with 18 additions and 9 deletions

View File

@@ -321,7 +321,7 @@
// minify internal properties // minify internal properties
(function() { (function() {
var methods = [ var methodNames = [
'cacheIndexOf', 'cacheIndexOf',
'cachePush', 'cachePush',
'compareAscending', 'compareAscending',
@@ -339,7 +339,12 @@
'value' 'value'
]; ];
var snippets = source.match(RegExp('^( *)(?:var|function) +(?:' + methods.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm')); // minify `iteratorObject.keys`
source.replace(/\b(iteratorObject(?:\.|\['))keys\b/g, function(match, prelude) {
return prelude + minNames[iteratorOptions.length + props.length];
});
var snippets = source.match(RegExp('^( *)(?:var|function) +(?:' + methodNames.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm'));
if (!snippets) { if (!snippets) {
return; return;
} }

View File

@@ -21,6 +21,9 @@
/** Used internally to indicate various things */ /** Used internally to indicate various things */
var indicatorObject = {}; var indicatorObject = {};
/** Used to avoid reference errors in `createIterator` */
var iteratorObject = {};
/** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */ /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
var keyPrefix = +new Date + ''; var keyPrefix = +new Date + '';
@@ -663,7 +666,7 @@
* @memberOf _.support * @memberOf _.support
* @type Boolean * @type Boolean
*/ */
support.argsClass = isArguments(arguments); support.argsClass = toString.call(arguments) == argsClass;
/** /**
* Detect if `name` or `message` properties of `Error.prototype` are * Detect if `name` or `message` properties of `Error.prototype` are
@@ -1044,7 +1047,8 @@
* @returns {Function} Returns the compiled function. * @returns {Function} Returns the compiled function.
*/ */
function createIterator() { function createIterator() {
var data = getObject(); var data = getObject(),
keys = iteratorObject.keys;
// data properties // data properties
data.shadowedProps = shadowedProps; data.shadowedProps = shadowedProps;
@@ -1067,8 +1071,8 @@
// create the function factory // create the function factory
var factory = Function( var factory = Function(
'errorClass, errorProto, hasOwnProperty, isArguments, isArray, ' + 'errorClass, errorProto, hasOwnProperty, indicatorObject, isArguments, ' +
'isString, keys, lodash, objectProto, objectTypes, nonEnumProps, ' + 'isArray, isString, keys, lodash, objectProto, objectTypes, nonEnumProps, ' +
'stringClass, stringProto, toString', 'stringClass, stringProto, toString',
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
); );
@@ -1077,8 +1081,8 @@
// return the compiled function // return the compiled function
return factory( return factory(
errorClass, errorProto, hasOwnProperty, isArguments, isArray, errorClass, errorProto, hasOwnProperty, indicatorObject, isArguments,
isString, keys, lodash, objectProto, objectTypes, nonEnumProps, isArray, isString, keys, lodash, objectProto, objectTypes, nonEnumProps,
stringClass, stringProto, toString stringClass, stringProto, toString
); );
} }
@@ -1280,7 +1284,7 @@
* _.keys({ 'one': 1, 'two': 2, 'three': 3 }); * _.keys({ 'one': 1, 'two': 2, 'three': 3 });
* // => ['one', 'two', 'three'] (order is not guaranteed) * // => ['one', 'two', 'three'] (order is not guaranteed)
*/ */
var keys = !nativeKeys ? shimKeys : function(object) { var keys = iteratorObject.keys = !nativeKeys ? shimKeys : function(object) {
if (!isObject(object)) { if (!isObject(object)) {
return []; return [];
} }