Skip to content

Commit 67b3870

Browse files
authored
Add some docs to stblib Symbol (#7336)
1 parent e4d98a7 commit 67b3870

File tree

3 files changed

+128
-15
lines changed

3 files changed

+128
-15
lines changed

packages/artifacts.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,9 @@ lib/ocaml/Stdlib_String.resi
11771177
lib/ocaml/Stdlib_Symbol.cmi
11781178
lib/ocaml/Stdlib_Symbol.cmj
11791179
lib/ocaml/Stdlib_Symbol.cmt
1180+
lib/ocaml/Stdlib_Symbol.cmti
11801181
lib/ocaml/Stdlib_Symbol.res
1182+
lib/ocaml/Stdlib_Symbol.resi
11811183
lib/ocaml/Stdlib_Type.cmi
11821184
lib/ocaml/Stdlib_Type.cmj
11831185
lib/ocaml/Stdlib_Type.cmt

runtime/Stdlib_Symbol.res

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
type t
22

33
@val external make: string => t = "Symbol"
4-
@val external getFor: string => t = "Symbol.for"
5-
@val external keyFor: t => option<string> = "Symbol.keyFor"
4+
@val @scope("Symbol")
5+
external getFor: string => option<t> = "for"
6+
@val @scope("Symbol") external keyFor: t => option<string> = "keyFor"
7+
@get
8+
external description: t => option<string> = "description"
9+
@send external toString: t => string = "toString"
610

7-
@val external asyncIterator: t = "Symbol.asyncIterator"
8-
@val external hasInstance: t = "Symbol.hasInstance"
9-
@val external isConcatSpreadable: t = "Symbol.isConcatSpreadable"
10-
@val external iterator: t = "Symbol.iterator"
11-
@val external match: t = "Symbol.match"
12-
@val external matchAll: t = "Symbol.matchAll"
13-
@val external replace: t = "Symbol.replace"
14-
@val external search: t = "Symbol.search"
15-
@val external species: t = "Symbol.species"
16-
@val external split: t = "Symbol.split"
17-
@val external toPrimitive: t = "Symbol.toPrimitive"
18-
@val external toStringTag: t = "Symbol.toStringTag"
19-
@val external unscopables: t = "Symbol.unscopables"
11+
@val @scope("Symbol")
12+
external asyncIterator: t = "asyncIterator"
13+
@val @scope("Symbol")
14+
external hasInstance: t = "hasInstance"
15+
@val @scope("Symbol") external isConcatSpreadable: t = "isConcatSpreadable"
16+
@val @scope("Symbol") external iterator: t = "iterator"
17+
@val @scope("Symbol") external match: t = "match"
18+
@val @scope("Symbol") external matchAll: t = "matchAll"
19+
@val @scope("Symbol") external replace: t = "replace"
20+
@val @scope("Symbol") external search: t = "search"
21+
@val @scope("Symbol") external species: t = "species"
22+
@val @scope("Symbol") external split: t = "split"
23+
@val @scope("Symbol") external toPrimitive: t = "toPrimitive"
24+
@val @scope("Symbol") external toStringTag: t = "toStringTag"
25+
@val @scope("Symbol") external unscopables: t = "unscopables"

runtime/Stdlib_Symbol.resi

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***
2+
A built-in object that serves as a namespace for globally-unique identifiers.
3+
4+
Compiles to a regular JavaScript Symbol.
5+
*/
6+
7+
/**
8+
Type representing a Symbol.
9+
*/
10+
type t
11+
12+
/**
13+
`make(key)`
14+
15+
Makes a new unique Symbol value.
16+
17+
## Examples
18+
19+
```rescript
20+
Symbol.make("sym1")
21+
->Symbol.description
22+
->assertEqual(Some("sym1"))
23+
```
24+
*/
25+
@val
26+
external make: string => t = "Symbol"
27+
28+
/**
29+
`getFor(key)`
30+
31+
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found.
32+
Otherwise a new Symbol gets created and registered with key.
33+
34+
## Examples
35+
36+
```rescript
37+
Symbol.getFor("sym1")->assertEqual(Symbol.getFor("sym1"))
38+
```
39+
*/
40+
@val
41+
@scope("Symbol")
42+
external getFor: string => option<t> = "for"
43+
44+
/**
45+
`keyFor(key)`
46+
47+
Retrieves a shared Symbol key from the global Symbol registry for the given Symbol.
48+
49+
## Examples
50+
51+
```rescript
52+
let globalSym = Symbol.getFor("sym1") // Global symbol
53+
54+
globalSym->Option.flatMap(Symbol.description)->assertEqual(Some("sym1"))
55+
```
56+
*/
57+
@val
58+
@scope("Symbol")
59+
external keyFor: t => option<string> = "keyFor"
60+
61+
/**
62+
`description`
63+
64+
Returns `Some(string)` containing the description of this symbol, or `None` if the symbol has no description.
65+
## Examples
66+
67+
```rescript
68+
let sym = Symbol.make("sym1")
69+
Symbol.description(sym)->assertEqual(Some("sym1"))
70+
```
71+
*/
72+
@get
73+
external description: t => option<string> = "description"
74+
75+
/**
76+
`toString`
77+
78+
// Returns a string representing this symbol value.
79+
80+
## Examples
81+
82+
```rescript
83+
let sym = Symbol.make("sym1")
84+
85+
Symbol.toString(sym)->assertEqual("Symbol(sym1)")
86+
```
87+
*/
88+
@send
89+
external toString: t => string = "toString"
90+
91+
@val @scope("Symbol")
92+
external asyncIterator: t = "asyncIterator"
93+
@val @scope("Symbol")
94+
external hasInstance: t = "hasInstance"
95+
@val @scope("Symbol") external isConcatSpreadable: t = "isConcatSpreadable"
96+
@val @scope("Symbol") external iterator: t = "iterator"
97+
@val @scope("Symbol") external match: t = "match"
98+
@val @scope("Symbol") external matchAll: t = "matchAll"
99+
@val @scope("Symbol") external replace: t = "replace"
100+
@val @scope("Symbol") external search: t = "search"
101+
@val @scope("Symbol") external species: t = "species"
102+
@val @scope("Symbol") external split: t = "split"
103+
@val @scope("Symbol") external toPrimitive: t = "toPrimitive"
104+
@val @scope("Symbol") external toStringTag: t = "toStringTag"
105+
@val @scope("Symbol") external unscopables: t = "unscopables"

0 commit comments

Comments
 (0)