mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Ensure isType methods return false for subclassed values.
Former-commit-id: e300d12eb506c6ae4949bd37cf8eb33c3a4be2e1
This commit is contained in:
45
build.js
45
build.js
@@ -786,6 +786,19 @@
|
||||
return (source.match(/(?:\s*\/\/.*)*\n( *)if *\((?:!support\.argsClass|!isArguments)[\s\S]+?};\n\1}/) || [''])[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `_.isArray` fallback from `source`.
|
||||
*
|
||||
* @private
|
||||
* @param {String} source The source to inspect.
|
||||
* @returns {String} Returns the `isArray` fallback.
|
||||
*/
|
||||
function getIsArrayFallback(source) {
|
||||
return matchFunction(source, 'isArray')
|
||||
.replace(/^[\s\S]+?=\s*nativeIsArray\b/, '')
|
||||
.replace(/[;\s]+$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `_.isFunction` fallback from `source`.
|
||||
*
|
||||
@@ -1016,6 +1029,17 @@
|
||||
return source.replace(getIsArgumentsFallback(source), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the `_.isArray` fallback from `source`.
|
||||
*
|
||||
* @private
|
||||
* @param {String} source The source to process.
|
||||
* @returns {String} Returns the modified source.
|
||||
*/
|
||||
function removeIsArrayFallback(source) {
|
||||
return source.replace(getIsArrayFallback(source), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the `_.isFunction` fallback from `source`.
|
||||
*
|
||||
@@ -1074,11 +1098,6 @@
|
||||
function removeSupportArgsObject(source) {
|
||||
source = removeSupportProp(source, 'argsObject');
|
||||
|
||||
// remove `argsAreObjects` from `_.isArray`
|
||||
source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
||||
return match.replace(/\(support\.argsObject\s*&&\s*([^)]+)\)/g, '$1');
|
||||
});
|
||||
|
||||
// remove `argsAreObjects` from `_.isEqual`
|
||||
source = source.replace(matchFunction(source, 'isEqual'), function(match) {
|
||||
return match.replace(/!support.\argsObject[^:]+:\s*/g, '');
|
||||
@@ -1867,7 +1886,7 @@
|
||||
|
||||
// remove native `Array.isArray` branch in `_.isArray`
|
||||
source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
||||
return match.replace(/\s*\(nativeIsArray.+/, ' toString.call(value) == arrayClass;');
|
||||
return match.replace(/\bnativeIsArray\s*\|\|\s*/, '');
|
||||
});
|
||||
|
||||
// replace `_.keys` with `shimKeys`
|
||||
@@ -1919,6 +1938,7 @@
|
||||
source = removeSupportNodeClass(source);
|
||||
|
||||
if (!isMobile) {
|
||||
source = removeIsArrayFallback(source);
|
||||
source = removeSupportEnumPrototypes(source);
|
||||
source = removeSupportNonEnumArgs(source);
|
||||
|
||||
@@ -2006,11 +2026,6 @@
|
||||
source = source.replace(/^( *)var eachIteratorOptions *= *[\s\S]+?\n\1};\n/m, function(match) {
|
||||
return match.replace(/(^ *'arrays':)[^,]+/m, '$1 false');
|
||||
});
|
||||
|
||||
// remove `toString.call` use from `_.isArray`
|
||||
source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
||||
return match.replace(/\s*\(nativeIsArray.+/, ' nativeIsArray(value);');
|
||||
});
|
||||
}
|
||||
}
|
||||
if (isUnderscore) {
|
||||
@@ -2535,14 +2550,6 @@
|
||||
return match.replace(/\bisEqual\(([^,]+), *([^,]+)[^)]+\)/, '$1 === $2');
|
||||
});
|
||||
|
||||
// remove `instanceof` use from `_.isDate`, `_.isFunction`, and `_.isRegExp`
|
||||
_.each(['isDate', 'isFunction', 'isRegExp'], function(methodName) {
|
||||
var snippet = methodName == 'isFunction' ? getIsFunctionFallback(source) : matchFunction(source, methodName);
|
||||
source = source.replace(snippet, function(match) {
|
||||
return match.replace(/\w+\s+instanceof\s+\w+\s*\|\|\s*/g, '');
|
||||
});
|
||||
});
|
||||
|
||||
// remove conditional `charCodeCallback` use from `_.max` and `_.min`
|
||||
_.each(['max', 'min'], function(methodName) {
|
||||
source = source.replace(matchFunction(source, methodName), function(match) {
|
||||
|
||||
Reference in New Issue
Block a user