@@ -7,6 +7,32 @@ defmodule ElixirScript.Translator.Function do
77 alias ElixirScript.Preprocess.Variables
88 alias ElixirScript.Translator.Map
99
10+ @ standard_libs [
11+ :Patterns , :Kernel , :Atom , :Enum , :Integer , :JS ,
12+ :List , :Range , :Tuple , :Agent , :Keyword , :BitString ,
13+ :Base , :String , :Bitwise
14+ ]
15+
16+ def update_alias ( { :__aliases__ , context , [ name | rest ] } ) when name in @ standard_libs do
17+ { :__aliases__ , context , [ :Elixir , name ] ++ rest }
18+ end
19+
20+ def update_alias ( { :__aliases__ , context , [ name ] } ) when name in @ standard_libs do
21+ { :__aliases__ , context , [ :Elixir , name ] }
22+ end
23+
24+ def update_alias ( { { :. , context , [ module_name , function_name ] } , context2 , params } ) do
25+ { { :. , context , [ update_alias ( module_name ) , function_name ] } , context2 , params }
26+ end
27+
28+ def update_alias ( ast ) do
29+ ast
30+ end
31+
32+ def module_in_standard_libs? ( name ) do
33+ name in @ standard_libs
34+ end
35+
1036
1137 def process_function ( name , functions , env ) do
1238 result = make_anonymous_function ( functions , env )
@@ -16,7 +42,7 @@ defmodule ElixirScript.Translator.Function do
1642 result
1743 )
1844
19- JS . variable_declaration ( [ declarator ] , :let )
45+ JS . variable_declaration ( [ declarator ] , :const )
2046 end
2147
2248 def make_anonymous_function ( functions , env ) do
@@ -58,8 +84,11 @@ defmodule ElixirScript.Translator.Function do
5884 def make_defmatch ( clauses ) do
5985 JS . call_expression (
6086 JS . member_expression (
61- JS . identifier ( "Patterns" ) ,
62- JS . identifier ( "defmatch" )
87+ JS . identifier ( "Elixir" ) ,
88+ JS . member_expression (
89+ JS . identifier ( "Patterns" ) ,
90+ JS . identifier ( "defmatch" )
91+ )
6392 ) ,
6493 clauses
6594 )
@@ -87,8 +116,11 @@ defmodule ElixirScript.Translator.Function do
87116 def do_make_function_clause ( patterns , params , body , guard_body ) do
88117 JS . call_expression (
89118 JS . member_expression (
90- JS . identifier ( "Patterns" ) ,
91- JS . identifier ( "make_case" )
119+ JS . identifier ( "Elixir" ) ,
120+ JS . member_expression (
121+ JS . identifier ( "Patterns" ) ,
122+ JS . identifier ( "make_case" )
123+ )
92124 ) ,
93125 [
94126 JS . array_expression ( patterns ) ,
@@ -101,8 +133,11 @@ defmodule ElixirScript.Translator.Function do
101133 def do_make_function_clause ( patterns , params , body ) do
102134 JS . call_expression (
103135 JS . member_expression (
104- JS . identifier ( "Patterns" ) ,
105- JS . identifier ( "make_case" )
136+ JS . identifier ( "Elixir" ) ,
137+ JS . member_expression (
138+ JS . identifier ( "Patterns" ) ,
139+ JS . identifier ( "make_case" )
140+ )
106141 ) ,
107142 [
108143 JS . array_expression ( patterns ) ,
@@ -112,7 +147,7 @@ defmodule ElixirScript.Translator.Function do
112147 end
113148
114149 def make_function_or_property_call ( module_name , function_name , env ) do
115- the_name = case module_name do
150+ the_name = case update_alias ( module_name ) do
116151 { :__aliases__ , _ , name } ->
117152 name
118153 { name , _ , _ } when is_atom ( name ) ->
@@ -130,8 +165,11 @@ defmodule ElixirScript.Translator.Function do
130165
131166 JS . call_expression (
132167 JS . member_expression (
133- JS . identifier ( "JS" ) ,
134- JS . identifier ( "get_property_or_call_function" )
168+ JS . identifier ( "Elixir" ) ,
169+ JS . member_expression (
170+ JS . identifier ( "JS" ) ,
171+ JS . identifier ( "call_property" )
172+ )
135173 ) ,
136174 [
137175 Utils . make_module_expression_tree ( the_name , false , env ) ,
@@ -149,7 +187,7 @@ defmodule ElixirScript.Translator.Function do
149187 end
150188
151189 def make_function_call ( module_name , function_name , params , env ) do
152- the_name = case module_name do
190+ the_name = case update_alias ( module_name ) do
153191 { :__aliases__ , _ , name } ->
154192 name
155193 { name , _ , _ } when is_atom ( name ) ->
0 commit comments