Remove dependencyObject.

Former-commit-id: 374611a2f1180402700fad5ba7f86e390150d37b
This commit is contained in:
John-David Dalton
2013-07-15 08:20:16 -07:00
parent 77d323b38c
commit e385b3499b
3 changed files with 38 additions and 40 deletions

View File

@@ -231,6 +231,12 @@
'findWhere': ['where'] 'findWhere': ['where']
}; };
/** Used to track circular dependencies of identifiers */
var circularDependencyMap = {
'createCallback': ['isEqual'],
'createIterator': ['keys']
};
/** Used to track Lo-Dash property dependencies of identifiers */ /** Used to track Lo-Dash property dependencies of identifiers */
var propDependencyMap = { var propDependencyMap = {
'at': ['support'], 'at': ['support'],
@@ -252,19 +258,19 @@
var varDependencyMap = { var varDependencyMap = {
'bind': ['reNative'], 'bind': ['reNative'],
'bindKey': ['indicatorObject'], 'bindKey': ['indicatorObject'],
'createCallback': ['dependencyObject', 'indicatorObject'], 'createCallback': ['indicatorObject'],
'createIterator': ['dependencyObject', 'indicatorObject', 'objectTypes'], 'createIterator': ['indicatorObject', 'objectTypes'],
'createObject': ['reNative'], 'createObject': ['reNative'],
'defer': ['objectTypes', 'reNative'], 'defer': ['objectTypes', 'reNative'],
'escape': ['reUnescapedHtml'], 'escape': ['reUnescapedHtml'],
'escapeHtmlChar': ['htmlEscapes'], 'escapeHtmlChar': ['htmlEscapes'],
'htmlUnescapes': ['htmlEscapes'], 'htmlUnescapes': ['htmlEscapes'],
'isArray': ['reNative'], 'isArray': ['reNative'],
'isEqual': ['dependencyObject', 'indicatorObject'], 'isEqual': ['indicatorObject'],
'isObject': ['objectTypes'], 'isObject': ['objectTypes'],
'isPlainObject': ['reNative'], 'isPlainObject': ['reNative'],
'isRegExp': ['objectTypes'], 'isRegExp': ['objectTypes'],
'keys': ['dependencyObject', 'reNative'], 'keys': ['reNative'],
'merge': ['indicatorObject'], 'merge': ['indicatorObject'],
'partialRight': ['indicatorObject'], 'partialRight': ['indicatorObject'],
'reEscapedHtml': ['htmlUnescapes'], 'reEscapedHtml': ['htmlUnescapes'],
@@ -827,14 +833,14 @@
var getDepPaths = function(dependencies, fromPath) { var getDepPaths = function(dependencies, fromPath) {
fromPath || (fromPath = ''); fromPath || (fromPath = '');
return dependencies.map(function(depName) { return dependencies.map(function(dep) {
var toPath = getPath(depName), var toPath = getPath(dep),
relative = path.relative(fromPath, toPath).replace(RegExp(path.sepEscaped, 'g'), sep); relative = path.relative(fromPath, toPath).replace(RegExp(path.sepEscaped, 'g'), sep);
if (relative.charAt(0) != '.') { if (relative.charAt(0) != '.') {
relative = '.' + (relative ? sep + relative : ''); relative = '.' + (relative ? sep + relative : '');
} }
return relative + sep + depName; return relative + sep + dep;
}); });
}; };
@@ -846,10 +852,14 @@
// create modules for each identifier // create modules for each identifier
identifiers.forEach(function(identifier) { identifiers.forEach(function(identifier) {
var deps = getDependencies(identifier, true) var circDeps = circularDependencyMap[identifier];
.concat(propDependencyMap[identifier] || [])
.concat(varDependencyMap[identifier] || []) var deps = _.difference(
.sort(); getDependencies(identifier, true)
.concat(propDependencyMap[identifier] || [])
.concat(varDependencyMap[identifier] || [])
, circDeps)
.sort();
var modulePath = getPath(identifier), var modulePath = getPath(identifier),
depArgs = deps.join(', '), depArgs = deps.join(', '),
@@ -870,7 +880,16 @@
'include=' + identifier, 'include=' + identifier,
'iife=' + iife.join('\n'), 'iife=' + iife.join('\n'),
'-o', path.join(outputPath, modulePath + identifier + '.js') '-o', path.join(outputPath, modulePath + identifier + '.js')
)); ), function(data) {
// replace deps inline
_.each(circDeps, function(dep) {
// avoid identifiers in strings
data.source = data.source.replace(RegExp('(["\'])(?:(?!\\1)[^\\n\\\\]|\\\\.)*\\1|\\b' + dep + '\\b', 'g'), function(match) {
return /^["']/.test(match) ? match : "require('" + match + "')";
});
});
defaultBuildCallback(data);
});
}); });
// create category modules // create category modules
@@ -2681,11 +2700,6 @@
} }
}); });
} }
if (isNoDep) {
// avoid circular dependencies
funcDependencyMap.createCallback = _.without(funcDependencyMap.createCallback, 'isEqual');
funcDependencyMap.createIterator = _.without(funcDependencyMap.createIterator, 'keys');
}
else if (isModularize) { else if (isModularize) {
_.forOwn(funcDependencyMap, function(deps, funcName) { _.forOwn(funcDependencyMap, function(deps, funcName) {
if (_.contains(deps, 'getIndexOf')) { if (_.contains(deps, 'getIndexOf')) {
@@ -3293,7 +3307,7 @@
// replace `_.isEqual` // replace `_.isEqual`
if (!isLodash('isEqual')) { if (!isLodash('isEqual')) {
source = replaceFunction(source, 'isEqual', [ source = replaceFunction(source, 'isEqual', [
'var isEqual = dependencyObject.isEqual = function(a, b, stackA, stackB) {', 'function isEqual(a, b, stackA, stackB) {',
' if (a === b) {', ' if (a === b) {',
' return a !== 0 || (1 / a == 1 / b);', ' return a !== 0 || (1 / a == 1 / b);',
' }', ' }',
@@ -3389,7 +3403,7 @@
' });', ' });',
' }', ' }',
' return result;', ' return result;',
'};' '}'
].join('\n')); ].join('\n'));
} }
// replace `_.memoize` // replace `_.memoize`

View File

@@ -331,11 +331,6 @@
'sortBy' 'sortBy'
]; ];
var depObjProps = [
'isEqual',
'keys'
];
var props = [ var props = [
'cache', 'cache',
'criteria', 'criteria',
@@ -343,13 +338,6 @@
'value' 'value'
]; ];
// minify `dependencyObject` properties
depObjProps.forEach(function(prop, index) {
source = source.replace(RegExp("\\b(dependencyObject(?:\\.|\\['))" + prop + '\\b', 'g'), function(match, prelude) {
return prelude + minNames[iteratorOptions.length + props.length + index];
});
});
// minify other properties used in functions // minify other properties used in functions
var snippets = source.match(RegExp('^( *)(?:var|function) +(?:' + funcNames.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm')); var snippets = source.match(RegExp('^( *)(?:var|function) +(?:' + funcNames.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm'));
if (!snippets) { if (!snippets) {

View File

@@ -21,9 +21,6 @@
/** Used internally to indicate various things */ /** Used internally to indicate various things */
var indicatorObject = {}; var indicatorObject = {};
/** 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` */ /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
var keyPrefix = +new Date + ''; var keyPrefix = +new Date + '';
@@ -1121,8 +1118,7 @@
* @returns {Function} Returns the compiled function. * @returns {Function} Returns the compiled function.
*/ */
function createIterator() { function createIterator() {
var data = getObject(), var data = getObject();
keys = dependencyObject.keys;
// data properties // data properties
data.shadowedProps = shadowedProps; data.shadowedProps = shadowedProps;
@@ -1335,7 +1331,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 = dependencyObject.keys = !nativeKeys ? shimKeys : function(object) { var keys = !nativeKeys ? shimKeys : function(object) {
if (!isObject(object)) { if (!isObject(object)) {
return []; return [];
} }
@@ -1917,7 +1913,7 @@
* }); * });
* // => true * // => true
*/ */
var isEqual = dependencyObject.isEqual = function(a, b, callback, thisArg, stackA, stackB) { function isEqual(a, b, callback, thisArg, stackA, stackB) {
// used to indicate that when comparing objects, `a` has at least the properties of `b` // used to indicate that when comparing objects, `a` has at least the properties of `b`
var whereIndicator = callback === indicatorObject; var whereIndicator = callback === indicatorObject;
if (typeof callback == 'function' && !whereIndicator) { if (typeof callback == 'function' && !whereIndicator) {
@@ -2073,7 +2069,7 @@
releaseArray(stackB); releaseArray(stackB);
} }
return result; return result;
}; }
/** /**
* Checks if `value` is, or can be coerced to, a finite number. * Checks if `value` is, or can be coerced to, a finite number.
@@ -4767,7 +4763,7 @@
var length = props.length, var length = props.length,
result = false; result = false;
while (length--) { while (length--) {
if (!(result = dependencyObject.isEqual(object[props[length]], func[props[length]], indicatorObject))) { if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) {
break; break;
} }
} }