-
-
Notifications
You must be signed in to change notification settings - Fork 252
part one on release 8.3 #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
author: hongbo | ||
date: "2020-09-23" | ||
previewImg: | ||
category: compiler | ||
title: What's new in ReScript 8.3 (Part 1) | ||
description: | | ||
--- | ||
|
||
|
||
# What's new in ReScript 8.3 (Part 1) | ||
|
||
ReScript is a soundly typed language with an optimizing compiler focused on JS platform. | ||
It's focused on type safety, performance and JS interop. It used to be called BuckleScript. | ||
|
||
ReScript@8.3 is available, people can try it via | ||
|
||
``` | ||
npm i bs-platform@8.3.0 | ||
``` | ||
|
||
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. | ||
|
||
|
||
|
||
## Lightweight FFI attributes without `bs.` prefix | ||
|
||
In this release, we make the `bs.` prefix optional, this will make the FFI less verbose. | ||
|
||
For example, the old externals for `readFileAsUtf8Sync` used to be written like this | ||
|
||
|
||
```ocaml | ||
external readFileAsUtf8Sync : string -> (_[@bs.as "utf8"]) -> string = "readFileSync" [@@bs.val] [@@bs.module "fs"] | ||
``` | ||
|
||
It can now be simplified as | ||
```ocaml | ||
external readFileAsUtf8Sync : string -> (_[@as "utf8"]) -> string = "readFileSync" | ||
[@@val] [@@module "fs"] | ||
``` | ||
|
||
Note almost all previous attributes with `bs.xx` can be simplified as `xx` | ||
with the exception of the following two that don't have abbreviations: | ||
|
||
- `bs.send.pipe` : this attribute was deprecated in favor of `bs.send`; you can still use the existing one for backward compatibility. | ||
|
||
- `bs.splice` : this attribute was deprecated in favor of `bs.variadic`; you can still use the existing one for | ||
backward compatibility. | ||
|
||
bobzhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## default import in Es6 support | ||
|
||
If you use es6 module output, the default bindings will be compiled properly now: | ||
|
||
```ocaml | ||
external input : string -> string = "default" [@@module "hello"] | ||
|
||
let a = input "hello" | ||
``` | ||
|
||
Will now be compiled properly under es6 format as below: | ||
|
||
```js | ||
import Hello from "hello"; | ||
var a = Hello("hello"); | ||
``` | ||
|
||
|
||
## Customized js file extension support | ||
|
||
Now user can pick up their js file extension support per module format: | ||
|
||
```json | ||
"package-specs": [{ | ||
"module": "es6", | ||
"suffix": ".mjs" | ||
},{ | ||
"module": "commonjs", | ||
"suffix": ".cjs" | ||
}], | ||
|
||
``` | ||
|
||
## More flexible filename support | ||
|
||
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.Android.res` so that it can just be picked up by those tools | ||
|
||
|
||
|
||
## Better type based inference for pattern `let {a,b,c} = value` | ||
|
||
Previously, for code like this: | ||
|
||
```ocaml | ||
module N = struct | ||
type t = { | ||
x : int | ||
} | ||
end | ||
|
||
let f (u : N.t) = | ||
let {x } = u in x + 1 (* type error *) | ||
``` | ||
|
||
You will get a type error | ||
|
||
``` | ||
Error: Unbound record field x | ||
``` | ||
|
||
However, since the compiler already knows the type of `u`, it is capable of looking up the label `x` properly. | ||
In this release, we make the original code style work out of the box without a work-around such as adding a module prefix | ||
like `let {N.x} = ..` | ||
|
||
## Build system enhancement | ||
|
||
A lot of work is put in improving the build system, we will expand on this topic in the next post! | ||
|
||
Happy Hacking! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
--- | ||
author: hongbo | ||
date: "2020-09-23" | ||
previewImg: | ||
category: compiler | ||
title: What's new in ReScript 8.3 (Part 1) | ||
description: | | ||
--- | ||
|
||
|
||
# What's new in ReScript 8.3 (Part 1) | ||
|
||
ReScript is a soundly typed language with an optimizing compiler focused on JS platform. | ||
It's focused on type safety, performance and JS interop. It used to be called BuckleScript. | ||
|
||
ReScript@8.3 is available, people can try it via | ||
|
||
``` | ||
npm i bs-platform@8.3.0 | ||
``` | ||
|
||
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. | ||
|
||
|
||
|
||
## Lightweight FFI attributes without `bs.` prefix | ||
|
||
In this release, we make the `bs.` prefix optional, this will make the FFI less verbose. | ||
|
||
For example, the old externals for `readFileAsUtf8Sync` used to be written like this | ||
|
||
|
||
<CodeTab labels={["ReScript", "Reason", "ML"]}> | ||
```res | ||
@bs.val @bs.module("fs") | ||
external readFileAsUtf8Sync: (string, @bs.as("utf8") _) => string = "readFileSync" | ||
``` | ||
```reason | ||
[@bs.val] [@bs.module "fs"] | ||
external readFileAsUtf8Sync: (string, [@bs.as "utf8"] _) => string = | ||
"readFileSync"; | ||
``` | ||
```ocaml | ||
external readFileAsUtf8Sync : string -> (_[@bs.as "utf8"]) -> string = "readFileSync" [@@bs.val] [@@bs.module "fs"] | ||
``` | ||
</CodeTab> | ||
|
||
It can now be simplified as | ||
<CodeTab labels={["ReScript", "Reason", "ML"]}> | ||
```res | ||
@val @module("fs") external readFileAsUtf8Sync: (string, @as("utf8") _) => string = "readFileSync" | ||
``` | ||
```reason | ||
[@val] [@module "fs"] | ||
external readFileAsUtf8Sync: (string, [@as "utf8"] _) => string = | ||
"readFileSync"; | ||
``` | ||
```ocaml | ||
external readFileAsUtf8Sync : string -> (_[@as "utf8"]) -> string = "readFileSync" | ||
[@@val] [@@module "fs"] | ||
``` | ||
</CodeTab> | ||
|
||
Note almost all previous attributes with `bs.xx` can be simplified as `xx` | ||
with the exception of the following two that don't have abbreviations: | ||
|
||
- `bs.send.pipe` : this attribute was deprecated in favor of `bs.send`; you can still use the existing one for backward compatibility. | ||
|
||
- `bs.splice` : this attribute was deprecated in favor of `bs.variadic`; you can still use the existing one for | ||
backward compatibility. | ||
|
||
|
||
## default import in Es6 support | ||
|
||
If you use es6 module output, the default bindings will be compiled properly now: | ||
|
||
<CodeTab labels={["ReScript", "Reason", "ML"]}> | ||
```res | ||
@module("hello") external input: string => string = "default" | ||
|
||
let a = input("hello") | ||
``` | ||
```reason | ||
[@module "hello"] external input: string => string = "default"; | ||
|
||
let a = input("hello"); | ||
``` | ||
```ocaml | ||
external input : string -> string = "default" [@@module "hello"] | ||
|
||
let a = input "hello" | ||
``` | ||
</CodeTab> | ||
|
||
Will now be compiled properly under es6 format as below: | ||
|
||
```js | ||
import Hello from "hello"; | ||
var a = Hello("hello"); | ||
``` | ||
|
||
|
||
## Customized js file extension support | ||
|
||
Now user can pick up their js file extension support per module format: | ||
|
||
```json | ||
"package-specs": [{ | ||
"module": "es6", | ||
"suffix": ".mjs" | ||
},{ | ||
"module": "commonjs", | ||
"suffix": ".cjs" | ||
}], | ||
|
||
``` | ||
|
||
## More flexible filename support | ||
|
||
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.Android.res` so that it can just be picked up by those tools | ||
|
||
|
||
|
||
## Better type based inference for pattern `let {a,b,c} = value` | ||
|
||
Previously, for code like this: | ||
|
||
<CodeTab labels={["ReScript", "Reason", "ML"]}> | ||
```res | ||
module N = { | ||
type t = {x: int} | ||
} | ||
|
||
let f = (u: N.t) => { | ||
let {x} = u | ||
x + 1 | ||
} /* type error */ | ||
``` | ||
```reason | ||
module N = { | ||
type t = {x: int}; | ||
}; | ||
|
||
let f = (u: N.t) => { | ||
let {x} = u; | ||
x + 1; | ||
}; /* type error */ | ||
``` | ||
```ocaml | ||
module N = struct | ||
type t = { | ||
x : int | ||
} | ||
end | ||
|
||
let f (u : N.t) = | ||
let {x } = u in x + 1 (* type error *) | ||
``` | ||
</CodeTab> | ||
|
||
You will get a type error | ||
|
||
``` | ||
Error: Unbound record field x | ||
``` | ||
|
||
However, since the compiler already knows the type of `u`, it is capable of looking up the label `x` properly. | ||
In this release, we make the original code style work out of the box without a work-around such as adding a module prefix | ||
like `let {N.x} = ..` | ||
|
||
## Build system enhancement | ||
|
||
A lot of work is put in improving the build system, we will expand on this topic in the next post! | ||
|
||
Happy Hacking! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.