Skip to content

Commit d424bb0

Browse files
authored
Merge pull request rescript-lang#61 from reason-association/part_1_release_8_3
part one on release 8.3
2 parents dc3597e + b73260e commit d424bb0

File tree

2 files changed

+299
-0
lines changed

2 files changed

+299
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
author: hongbo
3+
date: "2020-09-23"
4+
previewImg:
5+
category: compiler
6+
title: What's new in ReScript 8.3 (Part 1)
7+
description: |
8+
---
9+
10+
11+
# What's new in ReScript 8.3 (Part 1)
12+
13+
ReScript is a soundly typed language with an optimizing compiler focused on JS platform.
14+
It's focused on type safety, performance and JS interop. It used to be called BuckleScript.
15+
16+
[email protected] is available, people can try it via
17+
18+
```
19+
20+
```
21+
22+
The changes are listed [here](https://github.com/rescript-lang/rescript-compiler/blob/master/Changes.md#83), this is a large release, and we will go through some highlighted changes.
23+
24+
25+
26+
## Lightweight FFI attributes without `bs.` prefix
27+
28+
In this release, we make the `bs.` prefix optional, this will make the FFI less verbose.
29+
30+
For example, the old externals for `readFileAsUtf8Sync` used to be written like this
31+
32+
33+
```ocaml
34+
external readFileAsUtf8Sync : string -> (_[@bs.as "utf8"]) -> string = "readFileSync" [@@bs.val] [@@bs.module "fs"]
35+
```
36+
37+
It can now be simplified as
38+
```ocaml
39+
external readFileAsUtf8Sync : string -> (_[@as "utf8"]) -> string = "readFileSync"
40+
[@@val] [@@module "fs"]
41+
```
42+
43+
Note almost all previous attributes with `bs.xx` can be simplified as `xx`
44+
with the exception of the following two that don't have abbreviations:
45+
46+
- `bs.send.pipe` : this attribute was deprecated in favor of `bs.send`; you can still use the existing one for backward compatibility.
47+
48+
- `bs.splice` : this attribute was deprecated in favor of `bs.variadic`; you can still use the existing one for
49+
backward compatibility.
50+
51+
52+
## default import in Es6 support
53+
54+
If you use es6 module output, the default bindings will be compiled properly now:
55+
56+
```ocaml
57+
external input : string -> string = "default" [@@module "hello"]
58+
59+
let a = input "hello"
60+
```
61+
62+
Will now be compiled properly under es6 format as below:
63+
64+
```js
65+
import Hello from "hello";
66+
var a = Hello("hello");
67+
```
68+
69+
70+
## Customized js file extension support
71+
72+
Now user can pick up their js file extension support per module format:
73+
74+
```json
75+
"package-specs": [{
76+
"module": "es6",
77+
"suffix": ".mjs"
78+
},{
79+
"module": "commonjs",
80+
"suffix": ".cjs"
81+
}],
82+
83+
```
84+
85+
## More flexible filename support
86+
87+
To have better integration with other [JS infrastructures](https://github.com/rescript-lang/rescript-compiler/issues/4624),
88+
for example, Next.js/React Native, we allow file names like `404.res`,
89+
`Button.Android.res` so that it can just be picked up by those tools
90+
91+
92+
93+
## Better type based inference for pattern `let {a,b,c} = value`
94+
95+
Previously, for code like this:
96+
97+
```ocaml
98+
module N = struct
99+
type t = {
100+
x : int
101+
}
102+
end
103+
104+
let f (u : N.t) =
105+
let {x } = u in x + 1 (* type error *)
106+
```
107+
108+
You will get a type error
109+
110+
```
111+
Error: Unbound record field x
112+
```
113+
114+
However, since the compiler already knows the type of `u`, it is capable of looking up the label `x` properly.
115+
In this release, we make the original code style work out of the box without a work-around such as adding a module prefix
116+
like `let {N.x} = ..`
117+
118+
## Build system enhancement
119+
120+
A lot of work is put in improving the build system, we will expand on this topic in the next post!
121+
122+
Happy Hacking!

_blogposts/2020-09-23-release-8-3.mdx

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
author: hongbo
3+
date: "2020-09-23"
4+
previewImg:
5+
category: compiler
6+
title: What's new in ReScript 8.3 (Part 1)
7+
description: |
8+
---
9+
10+
11+
# What's new in ReScript 8.3 (Part 1)
12+
13+
ReScript is a soundly typed language with an optimizing compiler focused on JS platform.
14+
It's focused on type safety, performance and JS interop. It used to be called BuckleScript.
15+
16+
[email protected] is available, people can try it via
17+
18+
```
19+
20+
```
21+
22+
The changes are listed [here](https://github.com/rescript-lang/rescript-compiler/blob/master/Changes.md#83), this is a large release, and we will go through some highlighted changes.
23+
24+
25+
26+
## Lightweight FFI attributes without `bs.` prefix
27+
28+
In this release, we make the `bs.` prefix optional, this will make the FFI less verbose.
29+
30+
For example, the old externals for `readFileAsUtf8Sync` used to be written like this
31+
32+
33+
<CodeTab labels={["ReScript", "Reason", "ML"]}>
34+
```res
35+
@bs.val @bs.module("fs")
36+
external readFileAsUtf8Sync: (string, @bs.as("utf8") _) => string = "readFileSync"
37+
```
38+
```reason
39+
[@bs.val] [@bs.module "fs"]
40+
external readFileAsUtf8Sync: (string, [@bs.as "utf8"] _) => string =
41+
"readFileSync";
42+
```
43+
```ocaml
44+
external readFileAsUtf8Sync : string -> (_[@bs.as "utf8"]) -> string = "readFileSync" [@@bs.val] [@@bs.module "fs"]
45+
```
46+
</CodeTab>
47+
48+
It can now be simplified as
49+
<CodeTab labels={["ReScript", "Reason", "ML"]}>
50+
```res
51+
@val @module("fs") external readFileAsUtf8Sync: (string, @as("utf8") _) => string = "readFileSync"
52+
```
53+
```reason
54+
[@val] [@module "fs"]
55+
external readFileAsUtf8Sync: (string, [@as "utf8"] _) => string =
56+
"readFileSync";
57+
```
58+
```ocaml
59+
external readFileAsUtf8Sync : string -> (_[@as "utf8"]) -> string = "readFileSync"
60+
[@@val] [@@module "fs"]
61+
```
62+
</CodeTab>
63+
64+
Note almost all previous attributes with `bs.xx` can be simplified as `xx`
65+
with the exception of the following two that don't have abbreviations:
66+
67+
- `bs.send.pipe` : this attribute was deprecated in favor of `bs.send`; you can still use the existing one for backward compatibility.
68+
69+
- `bs.splice` : this attribute was deprecated in favor of `bs.variadic`; you can still use the existing one for
70+
backward compatibility.
71+
72+
73+
## default import in Es6 support
74+
75+
If you use es6 module output, the default bindings will be compiled properly now:
76+
77+
<CodeTab labels={["ReScript", "Reason", "ML"]}>
78+
```res
79+
@module("hello") external input: string => string = "default"
80+
81+
let a = input("hello")
82+
```
83+
```reason
84+
[@module "hello"] external input: string => string = "default";
85+
86+
let a = input("hello");
87+
```
88+
```ocaml
89+
external input : string -> string = "default" [@@module "hello"]
90+
91+
let a = input "hello"
92+
```
93+
</CodeTab>
94+
95+
Will now be compiled properly under es6 format as below:
96+
97+
```js
98+
import Hello from "hello";
99+
var a = Hello("hello");
100+
```
101+
102+
103+
## Customized js file extension support
104+
105+
Now user can pick up their js file extension support per module format:
106+
107+
```json
108+
"package-specs": [{
109+
"module": "es6",
110+
"suffix": ".mjs"
111+
},{
112+
"module": "commonjs",
113+
"suffix": ".cjs"
114+
}],
115+
116+
```
117+
118+
## More flexible filename support
119+
120+
To have better integration with other [JS infrastructures](https://github.com/rescript-lang/rescript-compiler/issues/4624),
121+
for example, Next.js/React Native, we allow file names like `404.res`,
122+
`Button.Android.res` so that it can just be picked up by those tools
123+
124+
125+
126+
## Better type based inference for pattern `let {a,b,c} = value`
127+
128+
Previously, for code like this:
129+
130+
<CodeTab labels={["ReScript", "Reason", "ML"]}>
131+
```res
132+
module N = {
133+
type t = {x: int}
134+
}
135+
136+
let f = (u: N.t) => {
137+
let {x} = u
138+
x + 1
139+
} /* type error */
140+
```
141+
```reason
142+
module N = {
143+
type t = {x: int};
144+
};
145+
146+
let f = (u: N.t) => {
147+
let {x} = u;
148+
x + 1;
149+
}; /* type error */
150+
```
151+
```ocaml
152+
module N = struct
153+
type t = {
154+
x : int
155+
}
156+
end
157+
158+
let f (u : N.t) =
159+
let {x } = u in x + 1 (* type error *)
160+
```
161+
</CodeTab>
162+
163+
You will get a type error
164+
165+
```
166+
Error: Unbound record field x
167+
```
168+
169+
However, since the compiler already knows the type of `u`, it is capable of looking up the label `x` properly.
170+
In this release, we make the original code style work out of the box without a work-around such as adding a module prefix
171+
like `let {N.x} = ..`
172+
173+
## Build system enhancement
174+
175+
A lot of work is put in improving the build system, we will expand on this topic in the next post!
176+
177+
Happy Hacking!

0 commit comments

Comments
 (0)