/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { brand, fail } from "../../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
 */
export function symbolFromKey(key) {
    const sym = symbolMap.get(key);
    if (sym !== undefined) {
        return sym;
    }
    const newSym = brand(Symbol(key));
    symbolMap.set(key, newSym);
    keyMap.set(newSym, key);
    return newSym;
}
/**
 * @returns the original {@link GlobalFieldKey} for the symbol.
 * @alpha
 */
export function keyFromSymbol(key) {
    var _a;
    return (_a = keyMap.get(key)) !== null && _a !== void 0 ? _a : fail("missing key for symbol");
}
/**
 * @returns true iff `key` is a {@link GlobalFieldKeySymbol}.
 * @alpha
 */
export function symbolIsFieldKey(key) {
    return keyMap.has(key);
}
//# sourceMappingURL=globalFieldKeySymbol.js.map