import { Map } from "./map"; var stringToId: Map; var idToString: Map; var nextId: usize = 12; // Symbol.unscopables + 1 @unmanaged export class symbol {} type Symbol = symbol; export function Symbol(description: string | null = null): symbol { var id = nextId++; if (!id) unreachable(); // out of ids return changetype(id); } export namespace Symbol { // well-known symbols export const hasInstance = changetype(1); export const concatSpreadable = changetype(2); export const isRegExp = changetype(3); export const iterator = changetype(3); export const match = changetype(4); export const replace = changetype(5); export const search = changetype(6); export const species = changetype(7); export const split = changetype(8); export const toPrimitive = changetype(9); export const toStringTag = changetype(10); export const unscopables = changetype(11); /* tslint:disable */// not valid TS export function for(key: string): symbol { if (!stringToId) { stringToId = new Map(); idToString = new Map(); } else if (stringToId.has(key)) return changetype(stringToId.get(key)); var id = nextId++; if (!id) unreachable(); // out of ids stringToId.set(key, id); idToString.set(id, key); return changetype(id); } /* tslint:enable */ export function keyFor(sym: symbol): string | null { return idToString !== null && idToString.has(changetype(sym)) ? idToString.get(changetype(sym)) : null; } }