Skip to content

Commit 9a1533f

Browse files
committed
Add old vs new syntax differences
1 parent 6e8fb81 commit 9a1533f

File tree

3 files changed

+45
-264
lines changed

3 files changed

+45
-264
lines changed

pages/docs/manual/latest/migrate-from-bucklescript-reason.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ canonical: "/docs/manual/latest/migrate-to-new-syntax"
66

77
# Migrate from BuckleScript/Reason
88

9-
ReScript is a rebranding and cleanup of BuckleScript & Reason that enables us to ship a tighter compile-to-JS stack with more coherent documentation & tools. If you're an existing user of BuckleScript & Reason, here's the gist:
9+
ReScript is a rebranding and cleanup of BuckleScript (since `v8.2.0`) & Reason (`v3.6`) that enables us to ship a tighter compile-to-JS stack with more coherent documentation & tools. If you're an existing user of BuckleScript & Reason, here's the gist:
1010

1111
- ReScript is mostly just BuckleScript rebranded, with a new syntax that's like the Reason syntax, but catered more toward the JavaScript crowd.
1212
- All your existing code will keep working even if you don't upgrade.
@@ -15,9 +15,30 @@ ReScript is a rebranding and cleanup of BuckleScript & Reason that enables us to
1515

1616
There are lots of exciting improvements in the new syntax (features, speed, error messages, etc.). The upgrade is trivial, backward-compatible and can be done on a per-file basis:
1717

18-
- Upgrade your project to `bs-platform 8.2.0`.
18+
- Upgrade your project to `bs-platform 8.2.0` or later.
1919
- `node_modules/.bin/bsc -format MyFile.re > MyFile.res`
2020

2121
**That's it**! `MyFile.re` could be any `.re`, `.rei`, `.ml` and `.mli` file.
2222

2323
Enjoy the improved experience!
24+
25+
## Difference With Old Reason
26+
27+
- Complete removal of semicolon (you can still write them).
28+
- No need for parentheses around `if`, `switch` and `try`.
29+
- Type arguments: from `option(int)` to `option<int>`.
30+
- Old interpolated string: from `{j|hello ${name}|j}` to `` j`hello ${name}` ``. Now with proper unicode support!
31+
- New interpolated string: `` `hello world` ``. Also supports multiline and unicode. `"hello world"` string is now singleline.
32+
- Polymorphic variants: from `` `red`` to `#red`.
33+
- Arrays: from `[|1,2,3|]` to `[1,2,3]`. In JS, arrays are the right default.
34+
- Lists: from `[1,2,3]` to `list[1,2,3]` (_8.1.1 update_: now it is `list{1, 2, 3}`). This ties with upcoming plans to access containers in a uniform way: `set[...]` and `map[...]`. Maybe temporary.
35+
- Exception: from `try (compute()) { | Not_found => Js.log("oops")}` to `try compute() catch { | Not_found => Js.log("oops")}`.
36+
- First class module: from `(module S: Student)` to `module(S: Student)`.
37+
- No custom infix operator for now (including `mod`).
38+
- Object access: from `settings##visible #= true` to `settings["visible"] = true`. Rejoice!
39+
- Object: from `Js.t({"age": int})` to just `{"age": int}`. The `Js.t` part is now implicit.
40+
- Attribute: from `[@bs.deriving accessors]` to `@bs.deriving(accessors)`. From `[%re bla]` to `%re(bla)`.
41+
- Removed dereference syntax `result^`. Just use `result.contents`.
42+
- `fun` pattern matching syntax removed.
43+
- Type declaration is non-recursive by default, consistent with let bindings. To have recursive types, use `type rec myList<'a> = Nil | Cons('a, myList<'a>)`.
44+
- Use any words, including reserved keywords, as your identifier name: `let \"try" = true`.

pages/docs/manual/v8.0.0/migrate-from-bucklescript-reason.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,30 @@ The old ML and Reason syntax are still supported (see our support commitment [he
1414

1515
There are lots of exciting improvements in the new syntax (features, speed, error messages, etc.). The upgrade is trivial, backward-compatible and can be done on a per-file basis:
1616

17-
- Upgrade your project to `bs-platform 8.2.0`.
17+
- Upgrade your project to `bs-platform 8.2.0` or later.
1818
- `node_modules/.bin/bsc -format MyFile.re > MyFile.res`
1919

2020
**That's it**! `MyFile.re` could be any `.re`, `.rei`, `.ml` and `.mli` file.
2121

2222
Enjoy the improved experience!
23+
24+
## Difference With Old Reason
25+
26+
- Complete removal of semicolon (you can still write them).
27+
- No need for parentheses around `if`, `switch` and `try`.
28+
- Type arguments: from `option(int)` to `option<int>`.
29+
- Old interpolated string: from `{j|hello ${name}|j}` to `` j`hello ${name}` ``. Now with proper unicode support!
30+
- New interpolated string: `` `hello world` ``. Also supports multiline and unicode. `"hello world"` string is now singleline.
31+
- Polymorphic variants: from `` `red`` to `#red`.
32+
- Arrays: from `[|1,2,3|]` to `[1,2,3]`. In JS, arrays are the right default.
33+
- Lists: from `[1,2,3]` to `list[1,2,3]` (_8.1.1 update_: now it is `list{1, 2, 3}`). This ties with upcoming plans to access containers in a uniform way: `set[...]` and `map[...]`. Maybe temporary.
34+
- Exception: from `try (compute()) { | Not_found => Js.log("oops")}` to `try compute() catch { | Not_found => Js.log("oops")}`.
35+
- First class module: from `(module S: Student)` to `module(S: Student)`.
36+
- No custom infix operator for now (including `mod`).
37+
- Object access: from `settings##visible #= true` to `settings["visible"] = true`. Rejoice!
38+
- Object: from `Js.t({"age": int})` to just `{"age": int}`. The `Js.t` part is now implicit.
39+
- Attribute: from `[@bs.deriving accessors]` to `@bs.deriving(accessors)`. From `[%re bla]` to `%re(bla)`.
40+
- Removed dereference syntax `result^`. Just use `result.contents`.
41+
- `fun` pattern matching syntax removed.
42+
- Type declaration is non-recursive by default, consistent with let bindings. To have recursive types, use `type rec myList<'a> = Nil | Cons('a, myList<'a>)`.
43+
- Use any words, including reserved keywords, as your identifier name: `let \"try" = true`.

pages/docs/reason-compiler/latest/new-bucklescript-syntax.mdx

Lines changed: 0 additions & 261 deletions
This file was deleted.

0 commit comments

Comments
 (0)