Skip to content

Commit bbdd260

Browse files
committed
Renamed transpile functions to compile
1 parent 71d4cf2 commit bbdd260

5 files changed

Lines changed: 29 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* import - `only` option is the only one allowed
1616
* aliases are now longer automatically turned into ES6 import statements. You must alias all modules used within a module
1717
* `Mutable.update` has been replaced by `JS.mutate`
18+
* `transpile`, `transpile_quoted`, and `transpile_path` are now `compile`, `compile_quoted`, and `compile_path`
1819

1920
# v0.10.0
2021
* Enhancements

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Usage
6464
-h --help this message
6565
```
6666

67-
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
67+
A note on `-r`. The standard lib modules are included in the output as `elixir.js`. They are by default included by importing them like so
6868

6969
```javascript
70-
import Kernel from '__lib/kernel'
70+
import {...} from 'elixir'
7171
```
7272

7373
Depending on your setup that may not work. With `-r` you can specify the root path that will be prepended to the default path.
@@ -79,7 +79,7 @@ mix ex2js "my/elixir/dir/**/*.ex" -r "js" -o my/js/dir
7979

8080
Will make the standard lib imports look like so
8181
```javascript
82-
import Kernel from 'js/__lib/kernel'
82+
import {...} from 'js/elixir'
8383
```
8484

8585

@@ -97,7 +97,7 @@ import Kernel from 'js/__lib/kernel'
9797

9898
* Using the included the ElixirScript module to turn Elixir code into JavaScript
9999
```elixir
100-
iex(1)> ElixirScript.transpile("[1, 2, 3, 4]")
100+
iex(1)> ElixirScript.compile("[1, 2, 3, 4]")
101101
["Erlang.list(1,2,3,4)"]
102102
```
103103

@@ -124,7 +124,7 @@ end
124124
125125
126126
#Now pass it to `ElixirScript.tranpile`
127-
ElixirScript.transpile("""
127+
ElixirScript.compile("""
128128
Math.squared(1)
129129
""", env: make_custom_env)
130130

lib/elixir_script.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ defmodule ElixirScript do
66
require Logger
77

88
@moduledoc """
9-
Transpiles Elixir into JavaScript.
9+
Translates Elixir into JavaScript.
1010
11-
All transpile functions return a list of
11+
All compile functions return a list of
1212
transpiled javascript code or a tuple consisting of
1313
the file name for the code and the transpiled javascript code.
1414
15-
All transpile functions also take an optional opts parameter
15+
All compile functions also take an optional opts parameter
1616
that controls transpiler output.
1717
1818
Available options are:
@@ -25,20 +25,20 @@ defmodule ElixirScript do
2525
"""
2626

2727
@doc """
28-
Transpiles the given Elixir code string
28+
Compiles the given Elixir code string
2929
"""
30-
@spec transpile(binary, Dict.t) :: [binary | { binary, binary }]
31-
def transpile(elixir_code, opts \\ []) do
30+
@spec compile(binary, Dict.t) :: [binary | { binary, binary }]
31+
def compile(elixir_code, opts \\ []) do
3232
elixir_code
3333
|> Code.string_to_quoted!
34-
|> transpile_quoted(opts)
34+
|> compile_quoted(opts)
3535
end
3636

3737
@doc """
38-
Transpiles the given Elixir code in quoted form
38+
Compiles the given Elixir code in quoted form
3939
"""
40-
@spec transpile_quoted(Macro.t, Dict.t) :: [binary | { binary, binary }]
41-
def transpile_quoted(quoted, opts \\ []) do
40+
@spec compile_quoted(Macro.t, Dict.t) :: [binary | { binary, binary }]
41+
def compile_quoted(quoted, opts \\ []) do
4242
include_path = Dict.get(opts, :include_path, false)
4343
root = Dict.get(opts, :root)
4444
env = Dict.get(opts, :env, custom_env)
@@ -57,10 +57,10 @@ defmodule ElixirScript do
5757
end
5858

5959
@doc """
60-
Transpiles the elixir files found at the given path
60+
Compiles the elixir files found at the given path
6161
"""
62-
@spec transpile_path(binary, Dict.t) :: [binary | { binary, binary }]
63-
def transpile_path(path, opts \\ []) do
62+
@spec compile_path(binary, Dict.t) :: [binary | { binary, binary }]
63+
def compile_path(path, opts \\ []) do
6464
include_path = Dict.get(opts, :include_path, false)
6565
root = Dict.get(opts, :root)
6666
env = Dict.get(opts, :env, custom_env)

lib/elixir_script/cli.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ defmodule ElixirScript.CLI do
4949
end
5050

5151
def do_process(input, options) do
52-
transpile_opts = [
52+
compile_opts = [
5353
root: options[:root],
5454
include_path: options[:output] != nil
5555
]
5656

57-
transpile_output = case options[:elixir] do
57+
compile_output = case options[:elixir] do
5858
true ->
59-
ElixirScript.transpile(input, transpile_opts)
59+
ElixirScript.compile(input, compile_opts)
6060
_ ->
61-
ElixirScript.transpile_path(input, transpile_opts)
61+
ElixirScript.compile_path(input, compile_opts)
6262
end
6363

6464
case options[:output] do
6565
nil ->
66-
Enum.each(transpile_output,
66+
Enum.each(compile_output,
6767
fn
6868
({_path, code})-> IO.write(code)
6969
(code)-> IO.write(code)
7070
end)
7171
output_path ->
72-
Enum.each(transpile_output, fn(x) ->
72+
Enum.each(compile_output, fn(x) ->
7373
write_to_file(x, output_path)
7474
end)
7575

test/elixir_script_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ defmodule ElixirScript.Test do
33
import ElixirScript.TestHelper
44

55
should "chain methods" do
6-
js_code = ElixirScript.transpile("""
6+
js_code = ElixirScript.compile("""
77
JQuery.("<div/>").text(html)
88
""")
99

1010
assert hd(js_code) == "JQuery('<div/>').text(html)"
1111
end
1212

1313
should "turn javascript ast into javascript code strings" do
14-
js_code = ElixirScript.transpile(":atom")
14+
js_code = ElixirScript.compile(":atom")
1515
assert hd(js_code) == "Erlang.atom('atom')"
1616
end
1717

1818
should "parse one module correctly" do
19-
js_code = ElixirScript.transpile("""
19+
js_code = ElixirScript.compile("""
2020
2121
defmodule Elephant do
2222
@ul JQuery.("#todo-list")
@@ -53,7 +53,7 @@ defmodule ElixirScript.Test do
5353

5454
should "parse multiple modules correctly" do
5555

56-
js_code = ElixirScript.transpile("""
56+
js_code = ElixirScript.compile("""
5757
defmodule Animals do
5858
use ElixirScript.Using, async: true
5959

0 commit comments

Comments
 (0)