mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Remove core-js guard.
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
import isFunction from './isFunction.js';
|
|
||||||
import isMasked from './_isMasked.js';
|
|
||||||
import isObject from './isObject.js';
|
|
||||||
import toSource from './_toSource.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to match `RegExp`
|
|
||||||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
||||||
*/
|
|
||||||
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
||||||
|
|
||||||
/** Used to detect host constructors (Safari). */
|
|
||||||
const reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
||||||
|
|
||||||
/** Used for built-in method references. */
|
|
||||||
const funcProto = Function.prototype;
|
|
||||||
const objectProto = Object.prototype;
|
|
||||||
|
|
||||||
/** Used to resolve the decompiled source of functions. */
|
|
||||||
const funcToString = funcProto.toString;
|
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
|
||||||
const hasOwnProperty = objectProto.hasOwnProperty;
|
|
||||||
|
|
||||||
/** Used to detect if a method is native. */
|
|
||||||
const reIsNative = RegExp(`^${
|
|
||||||
funcToString.call(hasOwnProperty)
|
|
||||||
.replace(reRegExpChar, '\\$&')
|
|
||||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?')
|
|
||||||
}$`);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `isNative` without bad shim checks.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The value to check.
|
|
||||||
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
||||||
* else `false`.
|
|
||||||
*/
|
|
||||||
function baseIsNative(value) {
|
|
||||||
if (!isObject(value) || isMasked(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
|
||||||
return pattern.test(toSource(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
export default baseIsNative;
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import root from './_root.js';
|
|
||||||
|
|
||||||
/** Used to detect overreaching core-js shims. */
|
|
||||||
const coreJsData = root['__core-js_shared__'];
|
|
||||||
|
|
||||||
export default coreJsData;
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseIsNative from './_baseIsNative.js';
|
import isNative from './isNative.js';
|
||||||
import getValue from './_getValue.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the native function at `key` of `object`.
|
* Gets the native function at `key` of `object`.
|
||||||
@@ -10,8 +9,8 @@ import getValue from './_getValue.js';
|
|||||||
* @returns {*} Returns the function if it's native, else `undefined`.
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
||||||
*/
|
*/
|
||||||
function getNative(object, key) {
|
function getNative(object, key) {
|
||||||
const value = getValue(object, key);
|
const value = object == null ? undefined : object[key];
|
||||||
return baseIsNative(value) ? value : undefined;
|
return isNative(value) ? value : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getNative;
|
export default getNative;
|
||||||
|
|||||||
13
_getValue.js
13
_getValue.js
@@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gets the value at `key` of `object`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} [object] The object to query.
|
|
||||||
* @param {string} key The key of the property to get.
|
|
||||||
* @returns {*} Returns the property value.
|
|
||||||
*/
|
|
||||||
function getValue(object, key) {
|
|
||||||
return object == null ? undefined : object[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default getValue;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import coreJsData from './_coreJsData.js';
|
|
||||||
import isFunction from './isFunction.js';
|
|
||||||
import stubFalse from './stubFalse.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if `func` is capable of being masked.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The value to check.
|
|
||||||
* @returns {boolean} Returns `true` if `func` is maskable, else `false`.
|
|
||||||
*/
|
|
||||||
const isMaskable = coreJsData ? isFunction : stubFalse;
|
|
||||||
|
|
||||||
export default isMaskable;
|
|
||||||
20
_isMasked.js
20
_isMasked.js
@@ -1,20 +0,0 @@
|
|||||||
import coreJsData from './_coreJsData.js';
|
|
||||||
|
|
||||||
/** Used to detect methods masquerading as native. */
|
|
||||||
const maskSrcKey = ((() => {
|
|
||||||
const uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
||||||
return uid ? `Symbol(src)_1.${ uid }` : '';
|
|
||||||
})());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if `func` has its source masked.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Function} func The function to check.
|
|
||||||
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
||||||
*/
|
|
||||||
function isMasked(func) {
|
|
||||||
return !!maskSrcKey && (maskSrcKey in func);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default isMasked;
|
|
||||||
47
isNative.js
47
isNative.js
@@ -1,20 +1,36 @@
|
|||||||
import baseIsNative from './_baseIsNative.js';
|
import isFunction from './isFunction.js';
|
||||||
import isMaskable from './_isMaskable.js';
|
import isObject from './isObject.js';
|
||||||
|
import toSource from './_toSource.js';
|
||||||
|
|
||||||
/** Error message constants. */
|
/**
|
||||||
const CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.';
|
* Used to match `RegExp`
|
||||||
|
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
||||||
|
*/
|
||||||
|
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
||||||
|
|
||||||
|
/** Used to detect host constructors (Safari). */
|
||||||
|
const reIsHostCtor = /^\[object .+?Constructor\]$/;
|
||||||
|
|
||||||
|
/** Used for built-in method references. */
|
||||||
|
const funcProto = Function.prototype;
|
||||||
|
const objectProto = Object.prototype;
|
||||||
|
|
||||||
|
/** Used to resolve the decompiled source of functions. */
|
||||||
|
const funcToString = funcProto.toString;
|
||||||
|
|
||||||
|
/** Used to check objects for own properties. */
|
||||||
|
const hasOwnProperty = objectProto.hasOwnProperty;
|
||||||
|
|
||||||
|
/** Used to detect if a method is native. */
|
||||||
|
const reIsNative = RegExp(`^${
|
||||||
|
funcToString.call(hasOwnProperty)
|
||||||
|
.replace(reRegExpChar, '\\$&')
|
||||||
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?')
|
||||||
|
}$`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is a pristine native function.
|
* Checks if `value` is a pristine native function.
|
||||||
*
|
*
|
||||||
* **Note:** This method can't reliably detect native functions in the presence
|
|
||||||
* of the core-js package because core-js circumvents this kind of detection.
|
|
||||||
* Despite multiple requests, the core-js maintainer has made it clear: any
|
|
||||||
* attempt to fix the detection will be obstructed. As a result, we're left
|
|
||||||
* with little choice but to throw an error. Unfortunately, this also affects
|
|
||||||
* packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
|
|
||||||
* which rely on core-js.
|
|
||||||
*
|
|
||||||
* @static
|
* @static
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @category Lang
|
* @category Lang
|
||||||
@@ -30,10 +46,11 @@ const CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=p
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isNative(value) {
|
function isNative(value) {
|
||||||
if (isMaskable(value)) {
|
if (!isObject(value)) {
|
||||||
throw new Error(CORE_ERROR_TEXT);
|
return false;
|
||||||
}
|
}
|
||||||
return baseIsNative(value);
|
const pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
||||||
|
return pattern.test(toSource(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isNative;
|
export default isNative;
|
||||||
|
|||||||
Reference in New Issue
Block a user