save code
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"rules": {
|
||||
"id-length": 0,
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"GetIntrinsic",
|
||||
],
|
||||
}],
|
||||
},
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Inspect JS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {NonNullable<import('./getInferredName')> | undefined} */
|
||||
var getInferredName;
|
||||
try {
|
||||
// eslint-disable-next-line no-new-func, no-extra-parens
|
||||
getInferredName = /** @type {NonNullable<import('./getInferredName')>} */ (Function('s', 'return { [s]() {} }[s].name;'));
|
||||
} catch (e) {}
|
||||
|
||||
var inferred = function () {};
|
||||
|
||||
/** @type {import('./getInferredName')} */
|
||||
module.exports = getInferredName && inferred.name === 'inferred' ? getInferredName : null;
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var callBound = require('call-bound');
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var getGlobalSymbolDescription = GetIntrinsic('%Symbol.keyFor%', true);
|
||||
/** @type {undefined | ((thisArg: symbol | Symbol) => symbol)} */
|
||||
var thisSymbolValue = callBound('%Symbol.prototype.valueOf%', true);
|
||||
/** @type {undefined | ((thisArg: symbol | Symbol) => string)} */
|
||||
var symToStr = callBound('Symbol.prototype.toString', true);
|
||||
/** @type {(thisArg: string, start?: number, end?: number) => string} */
|
||||
var $strSlice = callBound('String.prototype.slice');
|
||||
|
||||
var getInferredName = require('./getInferredName');
|
||||
|
||||
/** @type {import('.')} */
|
||||
/* eslint-disable consistent-return */
|
||||
module.exports = callBound('%Symbol.prototype.description%', true) || function getSymbolDescription(symbol) {
|
||||
if (!thisSymbolValue) {
|
||||
throw new $SyntaxError('Symbols are not supported in this environment');
|
||||
}
|
||||
|
||||
// will throw if not a symbol primitive or wrapper object
|
||||
var sym = thisSymbolValue(symbol);
|
||||
|
||||
if (getInferredName) {
|
||||
var name = getInferredName(sym);
|
||||
if (name === '') {
|
||||
return;
|
||||
}
|
||||
return name.slice(1, -1); // name.slice('['.length, -']'.length);
|
||||
}
|
||||
|
||||
var desc;
|
||||
if (getGlobalSymbolDescription) {
|
||||
desc = getGlobalSymbolDescription(sym);
|
||||
if (typeof desc === 'string') {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-extra-parens
|
||||
desc = $strSlice(/** @type {NonNullable<typeof symToStr>} */ (symToStr)(sym), 7, -1); // str.slice('Symbol('.length, -')'.length);
|
||||
if (desc) {
|
||||
return desc;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user