This commit is contained in:
dcode
2019-03-14 07:45:59 +01:00
parent 84ddd97761
commit 3b8c2331f4
9 changed files with 803 additions and 807 deletions

View File

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