Rename fallback to fork in build.js.

Former-commit-id: f98efe8f0cc3c5440c05ff8fe31cacb742fdddf3
This commit is contained in:
John-David Dalton
2013-06-18 08:26:46 -07:00
parent 512e5b0240
commit f6d9239b37

140
build.js
View File

@@ -831,6 +831,30 @@
});
}
/**
* Gets the `createObject` fork from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `createObject` fork.
*/
function getCreateObjectFork(source) {
var result = source.match(/(?:\s*\/\/.*)*\n( *)if *\((?:!nativeCreate)[\s\S]+?\n *};\n\1}/);
return result ? result[0] : '';
}
/**
* Gets the `_.defer` fork from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `_.defer` fork.
*/
function getDeferFork(source) {
var result = source.match(/(?:\s*\/\/.*)*\n( *)if *\(isV8 *&& *freeModule[\s\S]+?\n\1}/);
return result ? result[0] : '';
}
/**
* Gets an array of depenants for the given method name(s).
*
@@ -922,54 +946,42 @@
}
/**
* Gets the `_.isArguments` fallback from `source`.
* Gets the `_.isArguments` fork from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `isArguments` fallback.
* @returns {String} Returns the `isArguments` fork.
*/
function getIsArgumentsFallback(source) {
function getIsArgumentsFork(source) {
var result = source.match(/(?:\s*\/\/.*)*\n( *)if *\((?:!support\.argsClass|!isArguments)[\s\S]+?\n *};\n\1}/);
return result ? result[0] : '';
}
/**
* Gets the `_.isArray` fallback from `source`.
* Gets the `_.isArray` fork from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `isArray` fallback.
* @returns {String} Returns the `isArray` fork.
*/
function getIsArrayFallback(source) {
function getIsArrayFork(source) {
return matchFunction(source, 'isArray')
.replace(/^[\s\S]+?=\s*nativeIsArray\b/, '')
.replace(/[;\s]+$/, '');
}
/**
* Gets the `_.isFunction` fallback from `source`.
* Gets the `_.isFunction` fork from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `isFunction` fallback.
* @returns {String} Returns the `isFunction` fork.
*/
function getIsFunctionFallback(source) {
function getIsFunctionFork(source) {
var result = source.match(/(?:\s*\/\/.*)*\n( *)if *\(isFunction\(\/x\/[\s\S]+?\n *};\n\1}/);
return result ? result[0] : '';
}
/**
* Gets the `createObject` fallback from `source`.
*
* @private
* @param {String} source The source to inspect.
* @returns {String} Returns the `isArguments` fallback.
*/
function getCreateObjectFallback(source) {
var result = source.match(/(?:\s*\/\/.*)*\n( *)if *\((?:!nativeCreate)[\s\S]+?\n *};\n\1}/);
return result ? result[0] : '';
}
/**
* Gets the `iteratorTemplate` from `source`.
*
@@ -1200,6 +1212,28 @@
return source.replace(/^ *(?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/|\/\/.+)\n/gm, '');
}
/**
* Removes the `createObject` fork from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeCreateObjectFork(source) {
return source.replace(getCreateObjectFork(source), '');
}
/**
* Removes the `_.defer` fork from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeDeferFork(source) {
return source.replace(getDeferFork(source), '');
}
/**
* Removes all references to `identifier` from `createIterator` in `source`.
*
@@ -1310,47 +1344,36 @@
}
/**
* Removes the `_.isArguments` fallback from `source`.
* Removes the `_.isArguments` fork from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeIsArgumentsFallback(source) {
return source.replace(getIsArgumentsFallback(source), '');
function removeIsArgumentsFork(source) {
return source.replace(getIsArgumentsFork(source), '');
}
/**
* Removes the `_.isArray` fallback from `source`.
* Removes the `_.isArray` fork from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeIsArrayFallback(source) {
return source.replace(getIsArrayFallback(source), '');
function removeIsArrayFork(source) {
return source.replace(getIsArrayFork(source), '');
}
/**
* Removes the `_.isFunction` fallback from `source`.
* Removes the `_.isFunction` fork from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeIsFunctionFallback(source) {
return source.replace(getIsFunctionFallback(source), '');
}
/**
* Removes the `createObject` fallback from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeCreateObjectFallback(source) {
return source.replace(getCreateObjectFallback(source), '');
function removeIsFunctionFork(source) {
return source.replace(getIsFunctionFork(source), '');
}
/**
@@ -1448,20 +1471,6 @@
return source;
}
/**
* Removes all `setImmediate` references from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeSetImmediate(source) {
// remove the `setImmediate` fork of `_.defer`.
source = source.replace(/(?:\s*\/\/.*)*\n( *)if *\(isV8 *&& *freeModule[\s\S]+?\n\1}/, '');
return source;
}
/**
* Removes all `support` object references from `source`.
*
@@ -1494,8 +1503,8 @@
function removeSupportArgsClass(source) {
source = removeSupportProp(source, 'argsClass');
// replace `support.argsClass` in the `_.isArguments` fallback
source = source.replace(getIsArgumentsFallback(source), function(match) {
// replace `support.argsClass` in the `_.isArguments` fork
source = source.replace(getIsArgumentsFork(source), function(match) {
return match.replace(/!support\.argsClass/g, '!isArguments(arguments)');
});
@@ -2364,11 +2373,11 @@
return match.replace(/\bnativeIsArray\s*\|\|\s*/, '');
});
// replace `createObject` and `isArguments` with their fallbacks
// replace `createObject` and `isArguments` with their forks
_.each(['createObject', 'isArguments'], function(methodName) {
var capitalized = capitalize(methodName),
get = eval('get' + capitalized + 'Fallback'),
remove = eval('remove' + capitalized + 'Fallback');
get = eval('get' + capitalized + 'Fork'),
remove = eval('remove' + capitalized + 'Fork');
source = source.replace(matchFunction(source, methodName).replace(RegExp('[\\s\\S]+?function ' + methodName), ''), function() {
var snippet = get(source),
@@ -2399,16 +2408,16 @@
}
if (isModern) {
source = removeSupportSpliceObjects(source);
source = removeIsArgumentsFallback(source);
source = removeIsArgumentsFork(source);
if (isMobile) {
source = replaceSupportProp(source, 'enumPrototypes', 'true');
source = replaceSupportProp(source, 'nonEnumArgs', 'true');
}
else {
source = removeIsArrayFallback(source);
source = removeIsFunctionFallback(source);
source = removeCreateObjectFallback(source);
source = removeIsArrayFork(source);
source = removeIsFunctionFork(source);
source = removeCreateObjectFork(source);
// remove `shimIsPlainObject` from `_.isPlainObject`
source = source.replace(matchFunction(source, 'isPlainObject'), function(match) {
@@ -2423,9 +2432,6 @@
if (isMobile || (!useLodashMethod('assign') && !useLodashMethod('defaults') && !useLodashMethod('forIn') && !useLodashMethod('forOwn'))) {
source = removeKeysOptimization(source);
}
if (!useLodashMethod('defer')) {
source = removeSetImmediate(source);
}
}
if (isModern || isUnderscore) {
source = removeSupportArgsClass(source);