"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.symbolIsFieldKey = exports.keyFromSymbol = exports.symbolFromKey = void 0;
const util_1 = require("../../util");
// These maps are used instead of `Symbol.for` and `Symbol.keyFor` to avoid colliding with unrelated symbols.
const symbolMap = new Map();
const keyMap = new Map();
/**
 * @returns a symbol to use for `key`.
 * @alpha
 */
function symbolFromKey(key) {
    const sym = symbolMap.get(key);
    if (sym !== undefined) {
        return sym;
    }
    const newSym = (0, util_1.brand)(Symbol(key));
    symbolMap.set(key, newSym);
    keyMap.set(newSym, key);
    return newSym;
}
exports.symbolFromKey = symbolFromKey;
/**
 * @returns the original {@link GlobalFieldKey} for the symbol.
 * @alpha
 */
function keyFromSymbol(key) {
    var _a;
    return (_a = keyMap.get(key)) !== null && _a !== void 0 ? _a : (0, util_1.fail)("missing key for symbol");
}
exports.keyFromSymbol = keyFromSymbol;
/**
 * @returns true iff `key` is a {@link GlobalFieldKeySymbol}.
 * @alpha
 */
function symbolIsFieldKey(key) {
    return keyMap.has(key);
}
exports.symbolIsFieldKey = symbolIsFieldKey;
//# sourceMappingURL=globalFieldKeySymbol.js.map