rescript-lang / rescript-lang/rescript-lang.org

Cheat sheet for annotations

Open
#572 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
MDX
Stars
1.9k
Forks
260
Avg merge
3d 9h
Merged PRs (30d)
17

Description

Present a compact cheat sheet for decorators relevant for code generation. Here's a list of all decorators. Irrelevant ones to be removed:

  • @@deprecated
  • @@warning
  • @as only used for runtime representation, except for default arguments @as("someString") _
  • @bs.send.pipe
  • @dead
  • @deprecated
  • @deriving About runtime representation
  • @doesNotRaise
  • @genType
  • @get
  • @get_index
  • @ignore
  • @inline
  • @int not relevant: about runtime representation
  • @live
  • @meth About runtime representation
  • @module
  • @new
  • @obj
  • @raises
  • @react.component
  • @return This mixes runtime representation and externals: a post-processing for results
  • @scope
  • @send
  • @set
  • @set_index
  • @string not relevant: about runtime representation
  • @this Requires annotations on both external and uses
  • @unboxed About runtime representation
  • @uncurry This guarantees that the curried function is treated as if it were uncurried
  • @unwrap Unwraps one level of unary polymorphci variants (e.g. [#Int(int) | #Str(string)]). Should probably be a language-level feature either<(int, string)>.
  • @val
  • [?] @variadic Should this be a language-level feature?

A few examples covered:

// @val
// external setTimeout: (unit => unit, int) => timeoutID = "setTimeout"
external setTimeout: (unit => unit, int) => timeoutID = "setTimeout($1, $2)"

// @get external getName: window => string = "name"
external getName: window => string = "$1.name"

// @set external setName: (window, string) => unit = "name"
external setName: (window, string) => unit = "$1.name = $2"

// @get_index external get: (t, string) => int = ""
external get: (t, string) => int = "$1[$2]"

// @set_index external set: (t, string, int) => unit = ""
external set: (t, string, int) => unit = "$1[$2] = $3"

// @module("path")
// external dirname: string => string = "dirname"
external dirname: string => string = "import(path).dirname($1)"

// @new external create: unit => t = "Date"
external create: unit => t = "new Date()"

// @send external getElementById: (document, string) => Dom.element = "getElementById"
external getElementById: (document, string) => Dom.element = "$1.getElementById($2)"

// @module("library-x")
// @val external doStuff: (@as(json`{format:"utf8", includeStuff: false}`) _, string) => string = "doStuff"
external doStuff: string => string = "import(library-x).doStuff({format: 'utf8', includeStuff: false}, $1)"

// @val external doSomething: (@ignore 'a, 'a) => unit = "doSomething"
external doSomething: ('a, 'a) => unit = "doSomething($2)"

// @obj
// external action: (~name: string, unit) => _ = ""
external action: (~name: string, unit) => _ = "{name:$1}"

// @scope("Math") @val
// external floor: float => int = "floor"
external floor: float => int = "Math.floor($1)"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the decorator list and ReScript external examples in this issue, then locate the existing annotations documentation in the site. Create a compact cheat sheet covering the relevant code-generation decorators and clearly separating or removing the irrelevant ones; done means the listed examples and remaining annotations are represented accurately.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.