UNPKG

earljs

Version:

Ergonomic, modern and type-safe assertion library

27 lines (26 loc) 939 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatSymbol = void 0; const toLine_1 = require("./toLine"); const wellKnownSymbols = new Map(); for (const key of Object.getOwnPropertyNames(Symbol)) { const known = Symbol[key]; if (typeof known === 'symbol') { wellKnownSymbols.set(known, `Symbol.${key}`); } } function formatSymbol(value, sibling) { const key = Symbol.keyFor(value); if (key) { return (0, toLine_1.toLine)(`Symbol.for(${JSON.stringify(key)})`); } const wellKnown = wellKnownSymbols.get(value); if (wellKnown) { return (0, toLine_1.toLine)(wellKnown); } if (typeof sibling === 'symbol' && value !== sibling && value.toString() === sibling.toString()) { return (0, toLine_1.toLine)(`${value.toString()} (different)`); } return (0, toLine_1.toLine)(value.toString()); } exports.formatSymbol = formatSymbol;