Skip to content

Commit 83b5379

Browse files
committed
add part one post
1 parent 9a1533f commit 83b5379

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

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

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

0 commit comments

Comments
 (0)