Skip to content

Commit 0559bef

Browse files
authored
Merge pull request #388 from ocsigen/rescript/use-core
rescript: use Core instead of Js
2 parents 2858aa5 + 0e036c0 commit 0559bef

File tree

17 files changed

+256
-131
lines changed

17 files changed

+256
-131
lines changed

dist/res/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"author": "",
1313
"license": "Apache-2.0",
1414
"devDependencies": {
15+
"@rescript/core": "^1.1.0",
1516
"rescript": "11.0.1"
1617
},
1718
"peerDependencies": {
19+
"@rescript/core": "1.1.0",
1820
"rescript": "^11.0.1"
1921
}
2022
}

dist/res/rescript.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"suffix": ".bs.js",
1313
"bs-dependencies": [
14+
"@rescript/core"
1415
],
1516
"warnings": {
1617
"error" : "+101"

dist/res/src/ts2ocaml.res

Lines changed: 207 additions & 111 deletions
Large diffs are not rendered by default.

dist/res/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@rescript/core@^1.1.0":
6+
version "1.1.0"
7+
resolved "https://registry.yarnpkg.com/@rescript/core/-/core-1.1.0.tgz#e228a2635665b6b6a3288f7fd58552d5c361e253"
8+
integrity sha512-pz/CL8+9hBUTeMpUouvZohNsa5rqIwurlXoa1CZWN0ZKuWjMVjaoQ3V+0NB72J/QBbs6/8W82VABKBaDn3fGCA==
9+
510
611
version "11.0.1"
712
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.0.1.tgz#c74af134dc8a16d152169b2456d0720324835f54"

docs/rescript.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
> **Note:** ReScript support is currently available in `2.0.0-beta.0` or later.
2-
>
2+
>
33
> Please install it with `npm install -g @ocsigen/ts2ocaml@beta`.
44
55
# ts2ocaml for ReScript
@@ -18,6 +18,20 @@ The documentation for the `ts2ocaml` command and its options comes after the wal
1818

1919
`ts2ocaml` targets ReScript v11 or later.
2020

21+
Also, `ts2ocaml` depends on ReScript's new standard library `Core`.
22+
You may need to add `@rescript/core` to your project dependencies (`dependencies` in `package.json` and `bs-dependencies` in `rescript.json`).
23+
Please see [ReScript's official documentation](https://rescript-lang.org/docs/manual/latest/api) for details.
24+
25+
> Every code generated by `ts2ocaml` explicitly opens `RescriptCore`, so you don't have to set
26+
>
27+
> ```json
28+
> "bsc-flags": [
29+
> "-open RescriptCore"
30+
> ]
31+
> ```
32+
>
33+
> in your `rescript.json`.
34+
2135
## Adding `ts2ocaml.res`
2236
2337
ReScript has a rich standard library to use JS and DOM APIs and `ts2ocaml` makes use of it as much as possible. In addition to that, `ts2ocaml` uses a small standard library to handle some TypeScript-specific concepts:
@@ -82,7 +96,7 @@ let result = Ts.transpileModule(
8296
),
8397
)
8498
85-
Js.log(result->Ts.TranspileOutput.get_outputText)
99+
Console.log(result->Ts.TranspileOutput.get_outputText)
86100
```
87101

88102
# Conventions

src/Targets/ReScript/ReScriptHelper.fs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,18 @@ module Type =
220220
/// non-primitive types defined in the standard library
221221
let predefinedTypes =
222222
let builtins = [
223-
"RegExp", ("Re.t", 0)
223+
"RegExp", ("RegExp.t", 0)
224224
"PromiseLike", ("Promise.t", 1)
225225
"Array", ("array", 1)
226-
"ArrayLike", ("Array2.array_like", 1)
226+
"ArrayLike", ("Js.Array2.array_like", 1)
227+
"Iterable", ("Js.Array2.array_like", 1)
227228
"ReadonlyArray", ("array", 1)
228-
"ArrayBuffer", ("TypedArray2.ArrayBuffer.t", 0)
229-
"Error", ("Exn.t", 0)
229+
"ArrayBuffer", ("ArrayBuffer.t", 0)
230+
"Error", ("Error.t", 0)
231+
"ReadonlyMap", ("Map.t", 2)
230232
]
231233
let typedArrays =
232-
let typedArray name = name, (sprintf "TypedArray2.%s.t" name, 0)
234+
let typedArray name = name, (sprintf "%s.t" name, 0)
233235
[
234236
typedArray "DataView"
235237
typedArray "Int8Array"
@@ -330,12 +332,12 @@ module Type =
330332

331333
// JS types
332334
// ES5
333-
let object = str "untypedObject"
334-
let function_ = str "untypedFunction"
335-
let symbol = str "symbol"
336-
let regexp = str "Re.t"
335+
let object = str "object"
336+
let function_ = str "function"
337+
let symbol = str "Symbol.t"
338+
let regexp = str "RegExp.t"
337339
// ES2020
338-
let bigint = str "Bigint.t"
340+
let bigint = str "BigInt.t"
339341

340342
// TS types
341343
let never = str "never"

src/Targets/ReScript/Writer.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ let private emitImpl (sources: SourceFile list) (info: PackageInfo option) (ctx:
21022102
let m = emitModule dt flags ctx st
21032103

21042104
let opens = [
2105-
yield Statement.open_ "Js"
2105+
yield Statement.open_ "RescriptCore"
21062106
yield Statement.open_ "Ts2ocaml"
21072107
for src in sources do
21082108
yield! emitReferenceTypeDirectives ctx src

test/res/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@ocsigen/ts2ocaml": "link:../../"
1616
},
1717
"dependencies": {
18+
"@rescript/core": "^1.1.0",
1819
"rescript": "11.0.1"
1920
}
2021
}

test/res/rescript.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"in-source": true
1111
},
1212
"suffix": ".bs.js",
13+
"bs-dependencies": [
14+
"@rescript/core"
15+
],
1316
"uncurried": true
1417
}

test/res/src/main.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
open RescriptCore
2+
13
module Ts = Typescript.Export
24

35
let source = "let x: string = 'hello, world!'"
@@ -9,4 +11,4 @@ let result = Ts.transpileModule(
911
),
1012
)
1113

12-
Js.log(result->Ts.TranspileOutput.get_outputText)
14+
Console.log(result->Ts.TranspileOutput.get_outputText)

0 commit comments

Comments
 (0)