ElixirScript DocumentationBuild

The goal is to convert a subset (or full set) of Elixir code to JavaScript, providing the ability to write JavaScript in Elixir. This is done by taking the Elixir AST and converting it into JavaScript AST and then to JavaScript code. This is done using the Elixir-ESTree library.

Requirements

Usage

ElixirScript can be used in the following ways:

Development

Clone the repo

git clone git@github.com:bryanjos/elixirscript.git

Get dependencies

mix deps.get
npm install

Compile

mix compile

Test

mix test

Usage

usage: ex2js <input> [options]
<input> path to elixir files or
the elixir code string if the -ex flag is used
options:
-o --output [path] places output at the given path
-ex --elixir read input as elixir code string
-r --root [path] root path for standard libs
-h --help this message

A note on -r. The standard lib modules are included in the output inside the __libs folder. They are by default included by importing them like so

import Kernel from '__lib/kernel'

Depending on your setup that may not work. With -r you can specify the root path that will be prepended to the default path.

Ex.

mix ex2js "my/elixir/dir/**/*.ex" -r "js" -o my/js/dir

Will make the standard lib imports look like so

import Kernel from 'js/__lib/kernel'

Examples

Limitations

Not all of the Kernel.SpecialForms module is defined

The following aren't defined (yet):

The following are defined but incomplete:

Most of the Standard Library isn't defined yet

A lot of functions in the Kernel module are implemented. The Enum, Atom, List, Tuple, Logger, and Range modules are either fully defined are not complete. The rest still need to be implemented. Some modules like System or File may not be useful or function in the browser and may end up being only useful when using ElixirScript outside of the browser.

No Macros

Not sure how this would be implemented right now, but looking for ideas.

Example projects

Using with Brunch

There is a plugin for using ElixirScript in your Brunch project here