diff --git a/build.js b/build.js index 2b176ae09..7bafac8f6 100644 --- a/build.js +++ b/build.js @@ -102,7 +102,7 @@ 'compose': [], 'contains': ['basicEach', 'getIndexOf', 'isString'], 'countBy': ['createCallback', 'forEach'], - 'createCallback': ['identity', 'isEqual', 'keys'], + 'createCallback': ['identity', 'keys'], 'debounce': ['isObject'], 'defaults': ['createCallback', 'createIterator'], 'defer': ['bind'], @@ -252,19 +252,19 @@ var varDependencyMap = { 'bind': ['reNative'], 'bindKey': ['indicatorObject'], - 'createCallback': ['indicatorObject'], - 'createIterator': ['indicatorObject', 'iteratorObject', 'objectTypes'], + 'createCallback': ['dependencyObject', 'indicatorObject'], + 'createIterator': ['dependencyObject', 'indicatorObject', 'objectTypes'], 'createObject': ['reNative'], 'defer': ['objectTypes', 'reNative'], 'escape': ['reUnescapedHtml'], 'escapeHtmlChar': ['htmlEscapes'], 'htmlUnescapes': ['htmlEscapes'], 'isArray': ['reNative'], - 'isEqual': ['indicatorObject'], + 'isEqual': ['dependencyObject', 'indicatorObject'], 'isObject': ['objectTypes'], 'isPlainObject': ['reNative'], 'isRegExp': ['objectTypes'], - 'keys': ['iteratorObject', 'reNative'], + 'keys': ['dependencyObject', 'reNative'], 'merge': ['indicatorObject'], 'partialRight': ['indicatorObject'], 'reEscapedHtml': ['htmlUnescapes'], @@ -3285,7 +3285,7 @@ // replace `_.isEqual` if (!isLodash('isEqual')) { source = replaceFunction(source, 'isEqual', [ - 'function isEqual(a, b, stackA, stackB) {', + 'var isEqual = dependencyObject.isEqual = function(a, b, stackA, stackB) {', ' if (a === b) {', ' return a !== 0 || (1 / a == 1 / b);', ' }', diff --git a/build/pre-compile.js b/build/pre-compile.js index e89c640df..a4ecb3bc8 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -338,8 +338,8 @@ 'value' ]; - // minify `iteratorObject.keys` - source = source.replace(/\b(iteratorObject(?:\.|\['))keys\b/g, function(match, prelude) { + // minify `dependencyObject` properties + source = source.replace(/\b(dependencyObject(?:\.|\['))\w+/g, function(match, prelude) { return prelude + minNames[iteratorOptions.length + props.length]; }); diff --git a/lodash.js b/lodash.js index fb577c96e..f6a108e4d 100644 --- a/lodash.js +++ b/lodash.js @@ -21,8 +21,8 @@ /** Used internally to indicate various things */ var indicatorObject = {}; - /** Used to avoid reference errors in `createIterator` */ - var iteratorObject = {}; + /** Used to avoid reference errors and circular dependency errors */ + var dependencyObject = {}; /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */ var keyPrefix = +new Date + ''; @@ -1122,7 +1122,7 @@ */ function createIterator() { var data = getObject(), - keys = iteratorObject.keys; + keys = dependencyObject.keys; // data properties data.shadowedProps = shadowedProps; @@ -1335,7 +1335,7 @@ * _.keys({ 'one': 1, 'two': 2, 'three': 3 }); * // => ['one', 'two', 'three'] (order is not guaranteed) */ - var keys = iteratorObject.keys = !nativeKeys ? shimKeys : function(object) { + var keys = dependencyObject.keys = !nativeKeys ? shimKeys : function(object) { if (!isObject(object)) { return []; } @@ -1917,7 +1917,7 @@ * }); * // => true */ - function isEqual(a, b, callback, thisArg, stackA, stackB) { + var isEqual = dependencyObject.isEqual = function(a, b, callback, thisArg, stackA, stackB) { // used to indicate that when comparing objects, `a` has at least the properties of `b` var whereIndicator = callback === indicatorObject; if (typeof callback == 'function' && !whereIndicator) { @@ -2073,7 +2073,7 @@ releaseArray(stackB); } return result; - } + }; /** * Checks if `value` is, or can be coerced to, a finite number. @@ -4767,7 +4767,7 @@ var length = props.length, result = false; while (length--) { - if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) { + if (!(result = dependencyObject.isEqual(object[props[length]], func[props[length]], indicatorObject))) { break; } } diff --git a/test/index.html b/test/index.html index 944919ef0..0af34d0b7 100644 --- a/test/index.html +++ b/test/index.html @@ -49,40 +49,48 @@ if (window.curl) { var require = curl; } - if (window.require) { + (function() { + if (!window.require) { + return; + } + var isModularize = /modularize/.test(ui.urlParams.build); + + var baseUrl = isModularize + ? '../modularize/' + : ''; + + var modulePath = isModularize + ? 'lodash' + : ui.buildPath.replace(/\.js$/, ''); + + var testPath = ( + (window.curl ? ui.loaderPath.replace(/[\w.-]+$/, 'curl/plugin/js!') : '') + + (isModularize ? '../test/' : '') + + 'test.js' + ); + + console.log(testPath) QUnit.config.autostart = false; // load Lo-Dash as a module - require((function() { - var reModularize = /modularize/; - - var baseUrl = reModularize.test(ui.urlParams.build) - ? '../modularize/' - : ''; - - var modulePath = reModularize.test(ui.urlParams.build) - ? 'lodash' - : ui.buildPath.replace(/\.js$/, ''); - - return { - 'baseUrl': baseUrl, - 'urlArgs': 't=' + (+new Date), - 'paths': { - 'lodash': modulePath, - 'shimmed': './abc/../' + modulePath, - 'underscore': './xyz/../' + modulePath - }, - 'aliases': [ - ['shimmed', 'lodash'], - ['underscore', 'lodash'] - ], - 'shim': { - 'shimmed': { - 'exports': '_' - } + require({ + 'baseUrl': baseUrl, + 'urlArgs': 't=' + (+new Date), + 'paths': { + 'lodash': modulePath, + 'shimmed': './abc/../' + modulePath, + 'underscore': './xyz/../' + modulePath + }, + 'aliases': [ + ['shimmed', 'lodash'], + ['underscore', 'lodash'] + ], + 'shim': { + 'shimmed': { + 'exports': '_' } - }; - }()), + } + }, ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) { if (shimmed && shimmed.noConflict) { shimmedModule = shimmed.noConflict(); @@ -96,17 +104,11 @@ lodashModule = lodash.noConflict(); lodashModule.moduleName = 'lodash'; } - - var testPath = (window.curl - ? ui.loaderPath.replace(/[\w.-]+$/, 'curl/plugin/js!') - : '' - ) + 'test.js'; - require([testPath], function() { QUnit.start(); }); }); - } + }()); // set a more readable browser name window.onload = function() {