File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
lib/elixir_script/passes/translate Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
10
10
11
11
### Fixed
12
12
- Make sure not to add underscores to erlang functions
13
+ - Make sure any variable names that are javascript keywords are handled properly
13
14
14
15
## [ 0.30.0] - 2017-08-15
15
16
Original file line number Diff line number Diff line change @@ -9,6 +9,39 @@ defmodule ElixirScript.Translate.Form do
9
9
alias ElixirScript.Translate.Clause
10
10
require Logger
11
11
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
+
12
45
def compile! ( ast , state ) do
13
46
{ js_ast , _ } = compile ( ast , state )
14
47
@@ -369,10 +402,10 @@ defmodule ElixirScript.Translate.Form do
369
402
end
370
403
end
371
404
372
- def compile ( { :default , meta , _ } , state ) do
405
+ def compile ( { var , meta , _ } , state ) when var in @ js_reserved_words do
373
406
counter = Pattern . get_counter ( meta )
374
407
375
- var = :__default__
408
+ var = String . to_atom ( "__ #{ var } __" )
376
409
var = Pattern . get_variable_name ( to_string ( var ) <> counter , state )
377
410
{ ElixirScript.Translate.Identifier . make_identifier ( var ) , state }
378
411
end
You can’t perform that action at this time.
0 commit comments