Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Language Manual
Overview
  • Introduction
  • Installation
  • Editor Plugins
  • Migrate to ReScript Syntax
    • Upgrade Your Codebase
    • Difference With Old Reason
  • Try
Language Features
  • Overview
  • Let Binding
  • Type
  • Primitive Types
  • Tuple
  • Record
  • Object
  • Variant
  • Null, Undefined and Option
  • Array & List
  • Function
  • If-Else & Loops
  • Pipe
  • Pattern Matching / Destructuring
  • Mutation
  • JSX
  • Exception
  • Lazy Values
  • Promise
  • Module
  • Import & Export
  • Reserved Keyword
JavaScript Interop
  • Embed Raw JavaScript
  • Shared Data Types
  • External (Bind to Any JS Library)
  • Bind to JS Object
  • Bind to JS Function
  • Import from / Export to JS
  • Bind to Global JS Values
  • JSON
  • Use Illegal Identifier Names
  • Generate Converters & Helpers
  • Browser Support & Polyfills
  • Interop Cheatsheet
Build System
  • Build System Overview
  • Build System Configuration
  • Interop with JS Build Systems
  • Build Performance
Guides
  • Converting from JS
  • Libraries
Extra
  • Newcomer Examples
  • Project Structure
  • FAQ
Docs / Language Manual / Migrate to ReScript Syntax
Edit

You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest manual page here.

(These docs are equivalent to the old BuckleScript docs before the ReScript rebrand)

Migrate to New Syntax

Starting from v8.2.0, BuckleScript and the JS part of Reason are now fused into the new ReScript. We've also introduced a new syntax similar to the old Reason syntax, but tremendously improved.

The old ML and Reason syntax are still supported (see our support commitment here). The gist is: this is mostly just a rebranding and shouldn't affect your existing code much.

Upgrade Your Codebase

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:

  • Upgrade your project to bs-platform 8.2.0 or later.

  • node_modules/.bin/bsc -format MyFile.re > MyFile.res

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

Enjoy the improved experience!

Difference With Old Reason

  • Complete removal of semicolon (you can still write them).

  • No need for parentheses around if, switch and try.

  • Type arguments: from option(int) to option<int>.

  • Old interpolated string: from {j|hello ${name}|j} to j`hello ${name}`. Now with proper unicode support!

  • New interpolated string: `hello world`. Also supports multiline and unicode. "hello world" string is now singleline.

  • Polymorphic variants: from `red to #red.

  • Arrays: from [|1,2,3|] to [1,2,3]. In JS, arrays are the right default.

  • 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.

  • Exception: from try (compute()) { | Not_found => Js.log("oops")} to try compute() catch { | Not_found => Js.log("oops")}.

  • First class module: from (module S: Student) to module(S: Student).

  • No custom infix operator for now (including mod).

  • Object access: from settings##visible #= true to settings["visible"] = true. Rejoice!

  • Object: from Js.t({"age": int}) to just {"age": int}. The Js.t part is now implicit.

  • Attribute: from [@bs.deriving accessors] to @bs.deriving(accessors). From [%re bla] to %re(bla).

  • Removed dereference syntax result^. Just use result.contents.

  • fun pattern matching syntax removed.

  • 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>).

  • Use any words, including reserved keywords, as your identifier name: let \"try" = true.

Editor PluginsTry

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on