Skip to content

BuckleScript JS bundle API rehaul 2020 #4450

Closed
@ryyppy

Description

@ryyppy

This is a tracking issue for needed changes to build a good rescript-lang.org playground experience.
Since there have been substantial changes previously on the compiler infrastructure, this issue also replaces #3857.

Single window namespace

Right now, the bundle exposes two window objects: window.ocaml and window.reason, each of them implementing the same set of functions.

Our plan is to unify it to one single namespace instead, e.g. window.bs_platform (actual name needs to be discussed).

Reformatting Functionality

The BuckleScript bundle currently ships with Refmt_api which is capable of parsing / printing Reason code. We need access to these apis:

  • bs_platform.reason.parse(string): ast
  • bs_platform.reason.print(ast): string

Version Strings

  • bs_platform.reason.version: string (returns version from Refmt_Api)
  • bs_platform.ocaml.version: string (returns the OCaml version bs_platform is built on, e.g. 4.06.1)
  • bs_platform.version: string (returns the bucklescript version, such as v8.0.0)

Configuration

Right now there is no way to set any globally set configuration values within the JS BuckleScript compiler. Ideally we'd provide a function like bs_platform.setConfig(configObj) to set the configuration, optionally a function for setting separate values as well.

  • bs_platform.setConfig(ConfigObj)

whereas ConfigObj could look like:

type ConfigObj = {
  "module": "es6" | "commonjs" | "...",
  "bsc-flags": Array<string>,
  "use-super-errors": boolean
};

There's probably more, but for now having a way to configure the module output format would be a great boon for configuring different playground output formats.

With use-super-errors, we would be able to control the output format of the error messages as well.

Compilation

Right now, we offer different compilation functions with different sets of parameters, such as reason.compile(...) and reason.compile_super_errors(...).

With the new configuration functionality in place, we could configure the compiler depending on the user's preference (e.g if super-errors should be used) and expose a single reason.compile(codeStr) instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions