Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 050dd03

Browse files
committedMar 17, 2025·
WIP sync stdlib docs (Js does not work for now)
1 parent 61b4db3 commit 050dd03

File tree

4 files changed

+5120
-4364
lines changed

4 files changed

+5120
-4364
lines changed
 

‎data/api/v12.0.0/belt.json

Lines changed: 508 additions & 285 deletions
Large diffs are not rendered by default.

‎data/api/v12.0.0/core.json

Lines changed: 4583 additions & 4035 deletions
Large diffs are not rendered by default.

‎data/api/v12.0.0/toc_tree.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"js":{"name":"Js","path":["js"],"children":[{"name":"WeakMap","path":["js","weakmap"],"children":[]},{"name":"Map","path":["js","map"],"children":[]},{"name":"WeakSet","path":["js","weakset"],"children":[]},{"name":"Set","path":["js","set"],"children":[]},{"name":"Console","path":["js","console"],"children":[]},{"name":"Vector","path":["js","vector"],"children":[]},{"name":"List","path":["js","list"],"children":[]},{"name":"Result","path":["js","result"],"children":[]},{"name":"Option","path":["js","option"],"children":[]},{"name":"Blob","path":["js","blob"],"children":[]},{"name":"File","path":["js","file"],"children":[]},{"name":"BigInt","path":["js","bigint"],"children":[]},{"name":"Int","path":["js","int"],"children":[]},{"name":"Float","path":["js","float"],"children":[]},{"name":"Types","path":["js","types"],"children":[]},{"name":"TypedArray2","path":["js","typedarray2"],"children":[{"name":"DataView","path":["js","typedarray2","dataview"],"children":[]},{"name":"Float64Array","path":["js","typedarray2","float64array"],"children":[]},{"name":"Float32Array","path":["js","typedarray2","float32array"],"children":[]},{"name":"Uint32Array","path":["js","typedarray2","uint32array"],"children":[]},{"name":"Int32Array","path":["js","typedarray2","int32array"],"children":[]},{"name":"Uint16Array","path":["js","typedarray2","uint16array"],"children":[]},{"name":"Int16Array","path":["js","typedarray2","int16array"],"children":[]},{"name":"Uint8ClampedArray","path":["js","typedarray2","uint8clampedarray"],"children":[]},{"name":"Uint8Array","path":["js","typedarray2","uint8array"],"children":[]},{"name":"Int8Array","path":["js","typedarray2","int8array"],"children":[]},{"name":"ArrayBuffer","path":["js","typedarray2","arraybuffer"],"children":[]}]},{"name":"Typed_array","path":["js","typed_array"],"children":[{"name":"DataView","path":["js","typed_array","dataview"],"children":[]},{"name":"Float64_array","path":["js","typed_array","float64_array"],"children":[]},{"name":"Float64Array","path":["js","typed_array","float64array"],"children":[]},{"name":"Float32_array","path":["js","typed_array","float32_array"],"children":[]},{"name":"Float32Array","path":["js","typed_array","float32array"],"children":[]},{"name":"Uint32Array","path":["js","typed_array","uint32array"],"children":[]},{"name":"Int32_array","path":["js","typed_array","int32_array"],"children":[]},{"name":"Int32Array","path":["js","typed_array","int32array"],"children":[]},{"name":"Uint16Array","path":["js","typed_array","uint16array"],"children":[]},{"name":"Int16Array","path":["js","typed_array","int16array"],"children":[]},{"name":"Uint8ClampedArray","path":["js","typed_array","uint8clampedarray"],"children":[]},{"name":"Uint8Array","path":["js","typed_array","uint8array"],"children":[]},{"name":"Int8Array","path":["js","typed_array","int8array"],"children":[]},{"name":"S","path":["js","typed_array","s"],"children":[]},{"name":"ArrayBuffer","path":["js","typed_array","arraybuffer"],"children":[]},{"name":"Type","path":["js","typed_array","type"],"children":[]}]},{"name":"Obj","path":["js","obj"],"children":[]},{"name":"Math","path":["js","math"],"children":[]},{"name":"Json","path":["js","json"],"children":[{"name":"Kind","path":["js","json","kind"],"children":[]}]},{"name":"Global","path":["js","global"],"children":[]},{"name":"Dict","path":["js","dict"],"children":[]},{"name":"Date","path":["js","date"],"children":[]},{"name":"Promise2","path":["js","promise2"],"children":[]},{"name":"Promise","path":["js","promise"],"children":[]},{"name":"Re","path":["js","re"],"children":[]},{"name":"String2","path":["js","string2"],"children":[]},{"name":"String","path":["js","string"],"children":[]},{"name":"Array2","path":["js","array2"],"children":[]},{"name":"Array","path":["js","array"],"children":[]},{"name":"Exn","path":["js","exn"],"children":[]},{"name":"Null_undefined","path":["js","null_undefined"],"children":[]},{"name":"Nullable","path":["js","nullable"],"children":[]},{"name":"Undefined","path":["js","undefined"],"children":[]},{"name":"Null","path":["js","null"],"children":[]}]},"belt":{"name":"Belt","path":["belt"],"children":[{"name":"Float","path":["belt","float"],"children":[]},{"name":"Int","path":["belt","int"],"children":[]},{"name":"Result","path":["belt","result"],"children":[]},{"name":"Option","path":["belt","option"],"children":[]},{"name":"HashMap","path":["belt","hashmap"],"children":[{"name":"String","path":["belt","hashmap","string"],"children":[]},{"name":"Int","path":["belt","hashmap","int"],"children":[]}]},{"name":"HashSet","path":["belt","hashset"],"children":[{"name":"String","path":["belt","hashset","string"],"children":[]},{"name":"Int","path":["belt","hashset","int"],"children":[]}]},{"name":"MutableMap","path":["belt","mutablemap"],"children":[{"name":"String","path":["belt","mutablemap","string"],"children":[]},{"name":"Int","path":["belt","mutablemap","int"],"children":[]}]},{"name":"MutableSet","path":["belt","mutableset"],"children":[{"name":"String","path":["belt","mutableset","string"],"children":[]},{"name":"Int","path":["belt","mutableset","int"],"children":[]}]},{"name":"Map","path":["belt","map"],"children":[{"name":"Dict","path":["belt","map","dict"],"children":[]},{"name":"String","path":["belt","map","string"],"children":[]},{"name":"Int","path":["belt","map","int"],"children":[]}]},{"name":"Set","path":["belt","set"],"children":[{"name":"Dict","path":["belt","set","dict"],"children":[]},{"name":"String","path":["belt","set","string"],"children":[]},{"name":"Int","path":["belt","set","int"],"children":[]}]},{"name":"Range","path":["belt","range"],"children":[]},{"name":"List","path":["belt","list"],"children":[]},{"name":"MutableStack","path":["belt","mutablestack"],"children":[]},{"name":"MutableQueue","path":["belt","mutablequeue"],"children":[]},{"name":"SortArray","path":["belt","sortarray"],"children":[{"name":"String","path":["belt","sortarray","string"],"children":[]},{"name":"Int","path":["belt","sortarray","int"],"children":[]}]},{"name":"Array","path":["belt","array"],"children":[]},{"name":"Id","path":["belt","id"],"children":[{"name":"MakeHashable","path":["belt","id","makehashable"],"children":[]},{"name":"MakeHashableU","path":["belt","id","makehashableu"],"children":[]},{"name":"MakeComparable","path":["belt","id","makecomparable"],"children":[]},{"name":"MakeComparableU","path":["belt","id","makecomparableu"],"children":[]}]}]},"dom":{"name":"Dom","path":["dom"],"children":[{"name":"Storage2","path":["dom","storage2"],"children":[]},{"name":"Storage","path":["dom","storage"],"children":[]}]},"core":{"name":"Core","path":["core"],"children":[{"name":"Result","path":["core","result"],"children":[]},{"name":"List","path":["core","list"],"children":[]},{"name":"Option","path":["core","option"],"children":[]},{"name":"Exn","path":["core","exn"],"children":[]},{"name":"Intl","path":["core","intl"],"children":[{"name":"Segments","path":["core","intl","segments"],"children":[]},{"name":"Segmenter","path":["core","intl","segmenter"],"children":[]},{"name":"RelativeTimeFormat","path":["core","intl","relativetimeformat"],"children":[]},{"name":"PluralRules","path":["core","intl","pluralrules"],"children":[]},{"name":"NumberFormat","path":["core","intl","numberformat"],"children":[{"name":"Grouping","path":["core","intl","numberformat","grouping"],"children":[]}]},{"name":"Locale","path":["core","intl","locale"],"children":[]},{"name":"ListFormat","path":["core","intl","listformat"],"children":[]},{"name":"DateTimeFormat","path":["core","intl","datetimeformat"],"children":[]},{"name":"Collator","path":["core","intl","collator"],"children":[]},{"name":"Common","path":["core","intl","common"],"children":[]}]},{"name":"BigUint64Array","path":["core","biguint64array"],"children":[{"name":"Constants","path":["core","biguint64array","constants"],"children":[]}]},{"name":"BigInt64Array","path":["core","bigint64array"],"children":[{"name":"Constants","path":["core","bigint64array","constants"],"children":[]}]},{"name":"Uint8ClampedArray","path":["core","uint8clampedarray"],"children":[{"name":"Constants","path":["core","uint8clampedarray","constants"],"children":[]}]},{"name":"Uint32Array","path":["core","uint32array"],"children":[{"name":"Constants","path":["core","uint32array","constants"],"children":[]}]},{"name":"Uint16Array","path":["core","uint16array"],"children":[{"name":"Constants","path":["core","uint16array","constants"],"children":[]}]},{"name":"Uint8Array","path":["core","uint8array"],"children":[{"name":"Constants","path":["core","uint8array","constants"],"children":[]}]},{"name":"Int32Array","path":["core","int32array"],"children":[{"name":"Constants","path":["core","int32array","constants"],"children":[]}]},{"name":"Int16Array","path":["core","int16array"],"children":[{"name":"Constants","path":["core","int16array","constants"],"children":[]}]},{"name":"Int8Array","path":["core","int8array"],"children":[{"name":"Constants","path":["core","int8array","constants"],"children":[]}]},{"name":"Float64Array","path":["core","float64array"],"children":[{"name":"Constants","path":["core","float64array","constants"],"children":[]}]},{"name":"Float32Array","path":["core","float32array"],"children":[{"name":"Constants","path":["core","float32array","constants"],"children":[]}]},{"name":"TypedArray","path":["core","typedarray"],"children":[]},{"name":"ArrayBuffer","path":["core","arraybuffer"],"children":[]},{"name":"WeakSet","path":["core","weakset"],"children":[]},{"name":"Set","path":["core","set"],"children":[]},{"name":"WeakMap","path":["core","weakmap"],"children":[]},{"name":"Map","path":["core","map"],"children":[]},{"name":"AsyncIterator","path":["core","asynciterator"],"children":[]},{"name":"Iterator","path":["core","iterator"],"children":[]},{"name":"JSON","path":["core","json"],"children":[{"name":"Decode","path":["core","json","decode"],"children":[]},{"name":"Encode","path":["core","json","encode"],"children":[]},{"name":"Classify","path":["core","json","classify"],"children":[]}]},{"name":"Type","path":["core","type"],"children":[{"name":"Classify","path":["core","type","classify"],"children":[]}]},{"name":"Symbol","path":["core","symbol"],"children":[]},{"name":"String","path":["core","string"],"children":[]},{"name":"RegExp","path":["core","regexp"],"children":[{"name":"Result","path":["core","regexp","result"],"children":[]}]},{"name":"Promise","path":["core","promise"],"children":[]},{"name":"Ordering","path":["core","ordering"],"children":[]},{"name":"Object","path":["core","object"],"children":[]},{"name":"Nullable","path":["core","nullable"],"children":[]},{"name":"Null","path":["core","null"],"children":[]},{"name":"Math","path":["core","math"],"children":[{"name":"Int","path":["core","math","int"],"children":[]},{"name":"Constants","path":["core","math","constants"],"children":[]}]},{"name":"BigInt","path":["core","bigint"],"children":[]},{"name":"Int","path":["core","int"],"children":[{"name":"Constants","path":["core","int","constants"],"children":[]}]},{"name":"Float","path":["core","float"],"children":[{"name":"Constants","path":["core","float","constants"],"children":[]}]},{"name":"Error","path":["core","error"],"children":[{"name":"URIError","path":["core","error","urierror"],"children":[]},{"name":"TypeError","path":["core","error","typeerror"],"children":[]},{"name":"SyntaxError","path":["core","error","syntaxerror"],"children":[]},{"name":"ReferenceError","path":["core","error","referenceerror"],"children":[]},{"name":"RangeError","path":["core","error","rangeerror"],"children":[]},{"name":"EvalError","path":["core","error","evalerror"],"children":[]}]},{"name":"Dict","path":["core","dict"],"children":[]},{"name":"Date","path":["core","date"],"children":[{"name":"UTC","path":["core","date","utc"],"children":[]}]},{"name":"DataView","path":["core","dataview"],"children":[]},{"name":"Console","path":["core","console"],"children":[]},{"name":"Array","path":["core","array"],"children":[]}]}}
1+
{"belt":{"name":"Belt","path":["belt"],"children":[{"name":"Float","path":["belt","float"],"children":[]},{"name":"Int","path":["belt","int"],"children":[]},{"name":"Result","path":["belt","result"],"children":[]},{"name":"Option","path":["belt","option"],"children":[]},{"name":"HashMap","path":["belt","hashmap"],"children":[{"name":"String","path":["belt","hashmap","string"],"children":[]},{"name":"Int","path":["belt","hashmap","int"],"children":[]}]},{"name":"HashSet","path":["belt","hashset"],"children":[{"name":"String","path":["belt","hashset","string"],"children":[]},{"name":"Int","path":["belt","hashset","int"],"children":[]}]},{"name":"MutableMap","path":["belt","mutablemap"],"children":[{"name":"String","path":["belt","mutablemap","string"],"children":[]},{"name":"Int","path":["belt","mutablemap","int"],"children":[]}]},{"name":"MutableSet","path":["belt","mutableset"],"children":[{"name":"String","path":["belt","mutableset","string"],"children":[]},{"name":"Int","path":["belt","mutableset","int"],"children":[]}]},{"name":"Map","path":["belt","map"],"children":[{"name":"Dict","path":["belt","map","dict"],"children":[]},{"name":"String","path":["belt","map","string"],"children":[]},{"name":"Int","path":["belt","map","int"],"children":[]}]},{"name":"Set","path":["belt","set"],"children":[{"name":"Dict","path":["belt","set","dict"],"children":[]},{"name":"String","path":["belt","set","string"],"children":[]},{"name":"Int","path":["belt","set","int"],"children":[]}]},{"name":"Range","path":["belt","range"],"children":[]},{"name":"List","path":["belt","list"],"children":[]},{"name":"MutableStack","path":["belt","mutablestack"],"children":[]},{"name":"MutableQueue","path":["belt","mutablequeue"],"children":[]},{"name":"SortArray","path":["belt","sortarray"],"children":[{"name":"String","path":["belt","sortarray","string"],"children":[]},{"name":"Int","path":["belt","sortarray","int"],"children":[]}]},{"name":"Array","path":["belt","array"],"children":[]},{"name":"Id","path":["belt","id"],"children":[{"name":"MakeHashable","path":["belt","id","makehashable"],"children":[]},{"name":"MakeHashableU","path":["belt","id","makehashableu"],"children":[]},{"name":"MakeComparable","path":["belt","id","makecomparable"],"children":[]},{"name":"MakeComparableU","path":["belt","id","makecomparableu"],"children":[]}]}]},"dom":{"name":"Dom","path":["dom"],"children":[{"name":"Storage2","path":["dom","storage2"],"children":[]},{"name":"Storage","path":["dom","storage"],"children":[]}]},"core":{"name":"Core","path":["core"],"children":[{"name":"BigUint64Array","path":["core","biguint64array"],"children":[{"name":"Constants","path":["core","biguint64array","constants"],"children":[]}]},{"name":"BigInt64Array","path":["core","bigint64array"],"children":[{"name":"Constants","path":["core","bigint64array","constants"],"children":[]}]},{"name":"Uint8ClampedArray","path":["core","uint8clampedarray"],"children":[{"name":"Constants","path":["core","uint8clampedarray","constants"],"children":[]}]},{"name":"Uint32Array","path":["core","uint32array"],"children":[{"name":"Constants","path":["core","uint32array","constants"],"children":[]}]},{"name":"Uint16Array","path":["core","uint16array"],"children":[{"name":"Constants","path":["core","uint16array","constants"],"children":[]}]},{"name":"Uint8Array","path":["core","uint8array"],"children":[{"name":"Constants","path":["core","uint8array","constants"],"children":[]}]},{"name":"Int32Array","path":["core","int32array"],"children":[{"name":"Constants","path":["core","int32array","constants"],"children":[]}]},{"name":"Int16Array","path":["core","int16array"],"children":[{"name":"Constants","path":["core","int16array","constants"],"children":[]}]},{"name":"Int8Array","path":["core","int8array"],"children":[{"name":"Constants","path":["core","int8array","constants"],"children":[]}]},{"name":"Float64Array","path":["core","float64array"],"children":[{"name":"Constants","path":["core","float64array","constants"],"children":[]}]},{"name":"Float32Array","path":["core","float32array"],"children":[{"name":"Constants","path":["core","float32array","constants"],"children":[]}]},{"name":"TypedArray","path":["core","typedarray"],"children":[]},{"name":"ArrayBuffer","path":["core","arraybuffer"],"children":[]},{"name":"WeakSet","path":["core","weakset"],"children":[]},{"name":"Set","path":["core","set"],"children":[]},{"name":"WeakMap","path":["core","weakmap"],"children":[]},{"name":"Map","path":["core","map"],"children":[]},{"name":"AsyncIterator","path":["core","asynciterator"],"children":[]},{"name":"Iterator","path":["core","iterator"],"children":[]},{"name":"Type","path":["core","type"],"children":[{"name":"Classify","path":["core","type","classify"],"children":[]}]},{"name":"Symbol","path":["core","symbol"],"children":[]},{"name":"String","path":["core","string"],"children":[]},{"name":"Result","path":["core","result"],"children":[]},{"name":"RegExp","path":["core","regexp"],"children":[{"name":"Result","path":["core","regexp","result"],"children":[]}]},{"name":"Promise","path":["core","promise"],"children":[]},{"name":"Ordering","path":["core","ordering"],"children":[]},{"name":"Option","path":["core","option"],"children":[]},{"name":"Object","path":["core","object"],"children":[]},{"name":"Nullable","path":["core","nullable"],"children":[]},{"name":"Null","path":["core","null"],"children":[]},{"name":"Math","path":["core","math"],"children":[{"name":"Int","path":["core","math","int"],"children":[]},{"name":"Constants","path":["core","math","constants"],"children":[]}]},{"name":"List","path":["core","list"],"children":[]},{"name":"JSON","path":["core","json"],"children":[{"name":"Decode","path":["core","json","decode"],"children":[]},{"name":"Encode","path":["core","json","encode"],"children":[]},{"name":"Classify","path":["core","json","classify"],"children":[]}]},{"name":"Intl","path":["core","intl"],"children":[{"name":"Segments","path":["core","intl","segments"],"children":[]},{"name":"Segmenter","path":["core","intl","segmenter"],"children":[]},{"name":"RelativeTimeFormat","path":["core","intl","relativetimeformat"],"children":[]},{"name":"PluralRules","path":["core","intl","pluralrules"],"children":[]},{"name":"NumberFormat","path":["core","intl","numberformat"],"children":[{"name":"Grouping","path":["core","intl","numberformat","grouping"],"children":[]}]},{"name":"Locale","path":["core","intl","locale"],"children":[]},{"name":"ListFormat","path":["core","intl","listformat"],"children":[]},{"name":"DateTimeFormat","path":["core","intl","datetimeformat"],"children":[]},{"name":"Collator","path":["core","intl","collator"],"children":[]},{"name":"Common","path":["core","intl","common"],"children":[]}]},{"name":"Int","path":["core","int"],"children":[{"name":"Bitwise","path":["core","int","bitwise"],"children":[]},{"name":"Constants","path":["core","int","constants"],"children":[]}]},{"name":"Float","path":["core","float"],"children":[{"name":"Constants","path":["core","float","constants"],"children":[]}]},{"name":"Error","path":["core","error"],"children":[{"name":"URIError","path":["core","error","urierror"],"children":[]},{"name":"TypeError","path":["core","error","typeerror"],"children":[]},{"name":"SyntaxError","path":["core","error","syntaxerror"],"children":[]},{"name":"ReferenceError","path":["core","error","referenceerror"],"children":[]},{"name":"RangeError","path":["core","error","rangeerror"],"children":[]},{"name":"EvalError","path":["core","error","evalerror"],"children":[]}]},{"name":"Exn","path":["core","exn"],"children":[]},{"name":"Dict","path":["core","dict"],"children":[]},{"name":"Date","path":["core","date"],"children":[{"name":"UTC","path":["core","date","utc"],"children":[]}]},{"name":"DataView","path":["core","dataview"],"children":[]},{"name":"Console","path":["core","console"],"children":[]},{"name":"BigInt","path":["core","bigint"],"children":[]},{"name":"Array","path":["core","array"],"children":[]}]}}

‎scripts/gendocs.res

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Generate docs from ReScript Compiler
44
## Run
55
66
```bash
7-
node scripts/gendocs.mjs path/to/rescript-compiler path/to/rescript-core/src/RescriptCore.res version forceReWrite
7+
node scripts/gendocs.mjs path/to/rescript-monorepo version forceReWrite
88
```
99
1010
## Examples
1111
1212
```bash
13-
node scripts/gendocs.mjs path/to/rescript-compiler latest true
13+
node scripts/gendocs.mjs path/to/rescript-monorepo latest true
1414
```
1515
*/
1616
@val @scope(("import", "meta")) external url: string = "url"
@@ -25,21 +25,16 @@ let dirname =
2525
->Path.dirname
2626

2727
let compilerLibPath = switch args->Array.get(0) {
28-
| Some(path) => Path.join([path, "jscomp", "others"])
28+
| Some(path) => Path.join([path, "runtime"])
2929
| None => failwith("First argument should be path to rescript-compiler repo")
3030
}
3131

32-
let corePath = switch args->Array.get(1) {
33-
| Some(path) => path
34-
| _ => failwith("Second argument should be path to rescript-core/src/RescriptCore.res")
35-
}
36-
37-
let version = switch args->Array.get(2) {
32+
let version = switch args->Array.get(1) {
3833
| Some(version) => version
39-
| None => failwith("Third argument should be a version, `latest`, `v10`")
34+
| None => failwith("Second argument should be a version, `latest`, `v10`")
4035
}
4136

42-
let forceReWrite = switch args->Array.get(3) {
37+
let forceReWrite = switch args->Array.get(2) {
4338
| Some("true") => true
4439
| _ => false
4540
}
@@ -55,7 +50,8 @@ if Fs.existsSync(dirVersion) {
5550
Fs.mkdirSync(dirVersion)
5651
}
5752

58-
let entryPointFiles = ["js.ml", "belt.res", "dom.res"]
53+
// "Js.res" does not work for some reason
54+
let entryPointFiles = ["Belt.res", "Dom.res", "Stdlib.res"]
5955

6056
let hiddenModules = ["Js.Internal", "Js.MapperRt"]
6157

@@ -79,7 +75,7 @@ let env = Process.env
7975
let docsDecoded = entryPointFiles->Array.map(libFile => {
8076
let entryPointFile = Path.join2(compilerLibPath, libFile)
8177

82-
Dict.set(env, "FROM_COMPILER", "true")
78+
Dict.set(env, "FROM_COMPILER", "false")
8379

8480
let output =
8581
ChildProcess.execSync(
@@ -91,18 +87,10 @@ let docsDecoded = entryPointFiles->Array.map(libFile => {
9187
->Docgen.decodeFromJson
9288
})
9389

94-
let coreDocs = {
95-
Dict.set(env, "FROM_COMPILER", "false")
90+
let isStdlib = (id: string) => String.startsWith(id, "Stdlib")
91+
let replaceIdWithStdlib = (id: string) => isStdlib(id) ? String.replace(id, "Stdlib", "Core") : id
9692

97-
let output =
98-
ChildProcess.execSync(`./node_modules/.bin/rescript-tools doc ${corePath}`)->Buffer.toString
99-
100-
output
101-
->JSON.parseExn
102-
->Docgen.decodeFromJson
103-
}
104-
105-
let docsDecoded = Array.concat(docsDecoded, [coreDocs])
93+
let removeStdlibOrPrimitive = s => s->String.replaceAllRegExp(/Stdlib_|Primitive_js_extern\./g, "")
10694

10795
let docs = docsDecoded->Array.map(doc => {
10896
let topLevelItems = doc.items->Array.filterMap(item =>
@@ -123,9 +111,7 @@ let docs = docsDecoded->Array.map(doc => {
123111
if Array.includes(hiddenModules, id) {
124112
getModules(rest, moduleNames)
125113
} else {
126-
let id = String.startsWith(id, "RescriptCore")
127-
? String.replace(id, "RescriptCore", "Core")
128-
: id
114+
let id = replaceIdWithStdlib(id)
129115
getModules(
130116
list{...rest, ...List.fromArray(items)},
131117
list{{id, items, name, docstrings}, ...moduleNames},
@@ -135,9 +121,7 @@ let docs = docsDecoded->Array.map(doc => {
135121
| list{} => moduleNames
136122
}
137123

138-
let id = String.startsWith(doc.name, "RescriptCore")
139-
? String.replace(doc.name, "RescriptCore", "Core")
140-
: doc.name
124+
let id = replaceIdWithStdlib(doc.name)
141125

142126
let top = {id, name: id, docstrings: doc.docstrings, items: topLevelItems}
143127
let submodules = getModules(doc.items->List.fromArray, list{})->List.toArray
@@ -151,9 +135,7 @@ let allModules = {
151135
let encodeItem = (docItem: Docgen.item) => {
152136
switch docItem {
153137
| Value({id, name, docstrings, signature, ?deprecated}) => {
154-
let id = String.startsWith(id, "RescriptCore")
155-
? String.replace(id, "RescriptCore", "Core")
156-
: id
138+
let id = replaceIdWithStdlib(id)
157139
let dict = Dict.fromArray(
158140
[
159141
("id", id->String),
@@ -162,10 +144,15 @@ let allModules = {
162144
(
163145
"docstrings",
164146
docstrings
165-
->Array.map(s => s->String)
147+
->Array.map(s => s->removeStdlibOrPrimitive->String)
166148
->Array,
167149
),
168-
("signature", signature->String),
150+
(
151+
"signature",
152+
signature
153+
->removeStdlibOrPrimitive
154+
->String,
155+
),
169156
]->Array.concat(
170157
switch deprecated {
171158
| Some(v) => [("deprecated", v->String)]
@@ -177,16 +164,14 @@ let allModules = {
177164
}
178165

179166
| Type({id, name, docstrings, signature, ?deprecated}) =>
180-
let id = String.startsWith(id, "RescriptCore")
181-
? String.replace(id, "RescriptCore", "Core")
182-
: id
167+
let id = replaceIdWithStdlib(id)
183168
let dict = Dict.fromArray(
184169
[
185170
("id", id->String),
186171
("kind", "type"->String),
187172
("name", name->String),
188-
("docstrings", docstrings->Array.map(s => s->String)->Array),
189-
("signature", signature->String),
173+
("docstrings", docstrings->Array.map(s => s->removeStdlibOrPrimitive->String)->Array),
174+
("signature", signature->removeStdlibOrPrimitive->String),
190175
]->Array.concat(
191176
switch deprecated {
192177
| Some(v) => [("deprecated", v->String)]
@@ -209,7 +194,7 @@ let allModules = {
209194
->Array.filterMap(item => encodeItem(item))
210195
->Array
211196

212-
let id = String.startsWith(mod.id, "RescriptCore") ? "Core" : mod.id
197+
let id = replaceIdWithStdlib(mod.id)
213198

214199
let rest = Dict.fromArray([
215200
("id", id->String),
@@ -235,7 +220,7 @@ let () = {
235220
allModules->Array.forEach(((topLevelName, mod)) => {
236221
let json = JSON.Object(mod)
237222

238-
let topLevelName = String.startsWith(topLevelName, "RescriptCore") ? "Core" : topLevelName
223+
let topLevelName = replaceIdWithStdlib(topLevelName)
239224

240225
Fs.writeFileSync(
241226
Path.join([dirVersion, `${topLevelName->String.toLowerCase}.json`]),
@@ -279,7 +264,7 @@ let () = {
279264
}
280265

281266
let tocTree = docsDecoded->Array.map(({name, items}) => {
282-
let name = String.startsWith(name, "RescriptCore") ? "Core" : name
267+
let name = replaceIdWithStdlib(name)
283268
let path = name->String.toLowerCase
284269
(
285270
path,

0 commit comments

Comments
 (0)
Please sign in to comment.