Skip to content

Commit 80e47db

Browse files
committed
Merge in master
2 parents 72767c0 + 9d36563 commit 80e47db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+343
-234
lines changed

.credo.exs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,7 @@
5454
{Credo.Check.Consistency.SpaceAroundOperators},
5555
{Credo.Check.Consistency.SpaceInParentheses, false},
5656
{Credo.Check.Consistency.TabsOrSpaces},
57-
58-
# For some checks, like AliasUsage, you can only customize the priority
59-
# Priority values are: `low, normal, high, higher`
60-
{Credo.Check.Design.AliasUsage, priority: :low},
61-
62-
# For others you can set parameters
63-
64-
# If you don't want the `setup` and `test` macro calls in ExUnit tests
65-
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
66-
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
6757
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
68-
69-
# You can also customize the exit_status of each check.
70-
# If you don't want TODO comments to cause `mix credo` to fail, just
71-
# set this value to 0 (zero).
7258
{Credo.Check.Design.TagTODO, exit_status: 2},
7359
{Credo.Check.Design.TagFIXME},
7460

@@ -119,9 +105,6 @@
119105
{Credo.Check.Warning.UnusedRegexOperation},
120106
{Credo.Check.Warning.UnusedStringOperation},
121107
{Credo.Check.Warning.UnusedTupleOperation},
122-
123-
# Custom checks can be created using `mix credo.gen.check`.
124-
#
125108
]
126109
}
127110
]

.ebert.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
styleguide: elixirscript/elixirscript
2+
engines:
3+
credo:
4+
enabled: true
5+
fixme:
6+
enabled: true
7+
eslint:
8+
enabled: true
9+
remark-lint:
10+
enabled: true
11+
exclude_paths:
12+
- config
13+
- test

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [unreleased]
88
### Added
99
- Reimplement `String.split_at/2` to make sure Unicode library isn't compiled
10+
- Added `ElixirScript.JS.map_to_object/2` with options [keys: :string, symbols: false]
1011

1112
### Fixed
1213
- Make sure not to add underscores to erlang functions

lib/elixir_script/compiler.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule ElixirScript.Compiler do
2525
@spec compile(atom | [atom], []) :: nil
2626
def compile(entry_modules, opts \\ []) do
2727
opts = build_compiler_options(opts, entry_modules)
28-
{:ok, pid} = ElixirScript.State.start_link(opts)
28+
{:ok, pid} = ElixirScript.State.start_link()
2929

3030
entry_modules = List.wrap(entry_modules)
3131

@@ -37,7 +37,7 @@ defmodule ElixirScript.Compiler do
3737
ElixirScript.Translate.execute(modules, pid)
3838

3939
modules = ElixirScript.State.list_modules(pid)
40-
result = ElixirScript.Output.execute(modules, pid)
40+
result = ElixirScript.Output.execute(modules, pid, opts)
4141

4242
ElixirScript.State.stop(pid)
4343

lib/elixir_script/lib/js.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ defmodule ElixirScript.JS do
5050
"""
5151
defexternal mutate(object, key, value)
5252

53-
5453
@doc """
5554
Takes the given map and returns an object
5655
Throws an error if any key is not a
@@ -62,4 +61,15 @@ defmodule ElixirScript.JS do
6261
```
6362
"""
6463
defexternal map_to_object(object)
64+
65+
@doc """
66+
Takes the given map and returns an object
67+
Throws an error if any key is not a
68+
number, binary, or atom
69+
70+
```elixir
71+
ElixirScript.JS.map_to_object(%{my: "map"}, keys: :string)
72+
```
73+
"""
74+
defexternal map_to_object(object, options)
6575
end

lib/elixir_script/passes/output.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ defmodule ElixirScript.Output do
88
@doc """
99
Takes outputs the JavaScript code in the specified output
1010
"""
11-
@spec execute([atom], pid) :: nil
12-
def execute(modules, pid) do
11+
@spec execute([atom], pid, map) :: nil
12+
def execute(modules, pid, opts) do
1313
modules = modules
1414
|> Enum.filter(fn {_, info} -> Map.has_key?(info, :js_ast) end)
1515
|> Enum.map(fn {_module, info} ->
1616
info.js_ast
1717
end
1818
)
1919

20-
opts = ModuleState.get_compiler_opts(pid)
21-
2220
js_modules = ModuleState.js_modules(pid)
2321
|> Enum.filter(fn
2422
{_module, _name, nil} -> false

lib/elixir_script/passes/translate/forms/bitstring.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ defmodule ElixirScript.Translate.Forms.Bitstring do
2222
do_compile_element({:binary, Form.compile!(element, state)})
2323
end
2424

25-
def compile_element({:<<>>, _, elements}, state) do
26-
{ast, _} = compile(elements, state)
25+
def compile_element({:<<>>, _, _} = ast, state) do
26+
{ast, _} = compile(ast, state)
2727
ast
2828
end
2929

lib/elixir_script/passes/translate/forms/js.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,19 @@ defmodule ElixirScript.Translate.Forms.JS do
104104

105105
{ast, state}
106106
end
107+
108+
def compile({{:., _, [ElixirScript.JS, :map_to_object]}, _, [object, options]}, state) do
109+
ast = Helpers.call(
110+
J.member_expression(
111+
Helpers.functions(),
112+
J.identifier("map_to_object")
113+
),
114+
[
115+
Form.compile!(object, state),
116+
Form.compile!(options, state)
117+
]
118+
)
119+
120+
{ast, state}
121+
end
107122
end

lib/elixir_script/state.ex

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ defmodule ElixirScript.State do
33

44
# Holds the state for the ElixirScript compiler
55

6-
def start_link(compiler_opts) do
6+
def start_link() do
77
Agent.start_link(fn ->
88
%{
9-
compiler_opts: compiler_opts,
109
modules: Keyword.new,
11-
refs: [],
1210
js_modules: []
1311
}
1412
end)
@@ -18,12 +16,6 @@ defmodule ElixirScript.State do
1816
Agent.stop(pid)
1917
end
2018

21-
def get_compiler_opts(pid) do
22-
Agent.get(pid, fn(state) ->
23-
state.compiler_opts
24-
end)
25-
end
26-
2719
def get_module(pid, module) do
2820
Agent.get(pid, fn(state) ->
2921
Keyword.get(state.modules, module)
@@ -90,16 +82,6 @@ defmodule ElixirScript.State do
9082
end)
9183
end
9284

93-
def list_foreign_modules(pid) do
94-
Agent.get(pid, fn(state) ->
95-
state.modules
96-
|> Enum.filter(fn
97-
(%{attributes: [__foreign_info__: _]}) -> true
98-
(_) -> false
99-
end)
100-
end)
101-
end
102-
10385
def list_modules(pid) do
10486
Agent.get(pid, fn(state) ->
10587
state.modules

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [], [], "hexpm"},
22
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [], [], "hexpm"},
3-
"credo": {:hex, :credo, "0.8.6", "335f723772d35da499b5ebfdaf6b426bfb73590b6fcbc8908d476b75f8cbca3f", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
3+
"credo": {:hex, :credo, "0.8.6", "335f723772d35da499b5ebfdaf6b426bfb73590b6fcbc8908d476b75f8cbca3f", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
44
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [], [], "hexpm"},
55
"estree": {:hex, :estree, "2.6.1", "0a17cc0e9e35315dc4fcd79d30a746b1f3e9ed654be6084ce882ab491165ae22", [], [], "hexpm"},
66
"ex_doc": {:hex, :ex_doc, "0.16.2", "3b3e210ebcd85a7c76b4e73f85c5640c011d2a0b2f06dcdf5acdb2ae904e5084", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},

0 commit comments

Comments
 (0)