You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
852 B

4 years ago
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var callBound = require('./callBound');
  4. var $SyntaxError = GetIntrinsic('%SyntaxError%');
  5. var symToStr = callBound('Symbol.prototype.toString', true);
  6. var getInferredName = require('./getInferredName');
  7. module.exports = function getSymbolDescription(symbol) {
  8. if (!symToStr) {
  9. throw new $SyntaxError('Symbols are not supported in this environment');
  10. }
  11. var str = symToStr(symbol); // will throw if not a symbol
  12. if (getInferredName) {
  13. var name = getInferredName(symbol);
  14. if (name === '') { return; }
  15. // eslint-disable-next-line consistent-return
  16. return name.slice(1, -1); // name.slice('['.length, -']'.length);
  17. }
  18. var desc = str.slice(7, -1); // str.slice('Symbol('.length, -')'.length);
  19. if (desc) {
  20. // eslint-disable-next-line consistent-return
  21. return desc;
  22. }
  23. };