Skip to content

Commit c94e4c4

Browse files
committed
Make sure any variable names that are javascript keywords are handled properly
1 parent 3037e43 commit c94e4c4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Fixed
1212
- Make sure not to add underscores to erlang functions
13+
- Make sure any variable names that are javascript keywords are handled properly
1314

1415
## [0.30.0] - 2017-08-15
1516

lib/elixir_script/passes/translate/form.ex

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ defmodule ElixirScript.Translate.Form do
99
alias ElixirScript.Translate.Clause
1010
require Logger
1111

12+
@js_reserved_words [
13+
:break,
14+
:case,
15+
:class,
16+
:const,
17+
:continue,
18+
:debugger,
19+
:default,
20+
:delete,
21+
:do,
22+
:else,
23+
:export,
24+
:extends,
25+
:finally,
26+
:function,
27+
:if,
28+
:import,
29+
:in,
30+
:instanceof,
31+
:new,
32+
:return,
33+
:super,
34+
:switch,
35+
:throw,
36+
:try,
37+
:typeof,
38+
:var,
39+
:void,
40+
:while,
41+
:with,
42+
:yield
43+
]
44+
1245
def compile!(ast, state) do
1346
{js_ast, _} = compile(ast, state)
1447

@@ -369,10 +402,10 @@ defmodule ElixirScript.Translate.Form do
369402
end
370403
end
371404

372-
def compile({:default, meta, _}, state) do
405+
def compile({var, meta, _}, state) when var in @js_reserved_words do
373406
counter = Pattern.get_counter(meta)
374407

375-
var = :__default__
408+
var = String.to_atom("__#{var}__")
376409
var = Pattern.get_variable_name(to_string(var) <> counter, state)
377410
{ ElixirScript.Translate.Identifier.make_identifier(var), state }
378411
end

0 commit comments

Comments
 (0)