Remove core-js guard.

This commit is contained in:
John-David Dalton
2017-01-09 18:07:23 -08:00
parent 44950212a0
commit bc4262f901
7 changed files with 35 additions and 120 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,5 +1,4 @@
import baseIsNative from './_baseIsNative.js';
import getValue from './_getValue.js';
import isNative from './isNative.js';
/**
* 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`.
*/
function getNative(object, key) {
const value = getValue(object, key);
return baseIsNative(value) ? value : undefined;
const value = object == null ? undefined : object[key];
return isNative(value) ? value : undefined;
}
export default getNative;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,20 +1,36 @@
import baseIsNative from './_baseIsNative.js';
import isMaskable from './_isMaskable.js';
import isFunction from './isFunction.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.
*
* **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
* @since 3.0.0
* @category Lang
@@ -30,10 +46,11 @@ const CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=p
* // => false
*/
function isNative(value) {
if (isMaskable(value)) {
throw new Error(CORE_ERROR_TEXT);
if (!isObject(value)) {
return false;
}
return baseIsNative(value);
const pattern = isFunction(value) ? reIsNative : reIsHostCtor;
return pattern.test(toSource(value));
}
export default isNative;