- Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathsymbol.ts
114 lines (91 loc) · 3.1 KB
/
symbol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import{Map}from"./map";
// @ts-ignore: decorator
@lazyletstringToId: Map<string,usize>=newMap();
// @ts-ignore: decorator
@lazyletidToString: Map<usize,string>=newMap();
// @ts-ignore: decorator
@lazyletnextId: usize=12;// Symbol.unscopables + 1
@unmanaged @finalabstractclass_Symbol{
// TODO: all of the following default symbols are unused currently yet add to
// binary size if #toString becomes compiled. Ultimately we'll most likely want
// to remove the unsupported ones and only keep what's actually supported.
// @ts-ignore: decorator
@lazy
staticreadonlyhasInstance: symbol=changetype<symbol>(1);
// @ts-ignore: decorator
@lazy
staticreadonlyisConcatSpreadable: symbol=changetype<symbol>(2);
// @ts-ignore: decorator
@lazy
staticreadonlyisRegExp: symbol=changetype<symbol>(3);
// @ts-ignore: decorator
@lazy
staticreadonlyiterator: symbol=changetype<symbol>(3);
// @ts-ignore: decorator
@lazy
staticreadonlymatch: symbol=changetype<symbol>(4);
// @ts-ignore: decorator
@lazy
staticreadonlyreplace: symbol=changetype<symbol>(5);
// @ts-ignore: decorator
@lazy
staticreadonlysearch: symbol=changetype<symbol>(6);
// @ts-ignore: decorator
@lazy
staticreadonlyspecies: symbol=changetype<symbol>(7);
// @ts-ignore: decorator
@lazy
staticreadonlysplit: symbol=changetype<symbol>(8);
// @ts-ignore: decorator
@lazy
staticreadonlytoPrimitive: symbol=changetype<symbol>(9);
// @ts-ignore: decorator
@lazy
staticreadonlytoStringTag: symbol=changetype<symbol>(10);
// @ts-ignore: decorator
@lazy
staticreadonlyunscopables: symbol=changetype<symbol>(11);
staticfor(key: string): symbol{
if(stringToId.has(key))returnchangetype<symbol>(stringToId.get(key));
letid=nextId++;
if(!id)unreachable();// out of ids
stringToId.set(key,id);
idToString.set(id,key);
returnchangetype<symbol>(id);
}
statickeyFor(sym: symbol): string|null{
returnidToString.has(changetype<usize>(sym))
? idToString.get(changetype<usize>(sym))
: null;
}
toString(): string{
letid=changetype<usize>(this);
letstr="";
switch(<u32>id){
case1: {str="hasInstance";break;}
case2: {str="isConcatSpreadable";break;}
case3: {str="isRegExp";break;}
case4: {str="match";break;}
case5: {str="replace";break;}
case6: {str="search";break;}
case7: {str="species";break;}
case8: {str="split";break;}
case9: {str="toPrimitive";break;}
case10: {str="toStringTag";break;}
case11: {str="unscopables";break;}
default: {
if(idToString!=null&&idToString.has(id))str=idToString.get(id);
break;
}
}
return"Symbol("+str+")";
}
}
exportfunctionSymbol(description: string|null=null): symbol{
letid=nextId++;
if(!id)unreachable();// out of ids
returnchangetype<symbol>(id);
}
exporttypeSymbol=_Symbol;
// @ts-ignore: nolib
exporttypesymbol=_Symbol;