@@ -23,6 +23,7 @@ defmodule ElixirScript.Translator do
2323 alias ElixirScript.Translator.Utils
2424 alias ElixirScript.Lib.Logger
2525 alias ElixirScript.Lib.Kernel , as: KernelLib
26+ alias ElixirScript.Lib.JS , as: JSLib
2627 alias ESTree.Tools.Builder , as: JS
2728
2829 @ doc """
@@ -149,15 +150,18 @@ defmodule ElixirScript.Translator do
149150 end
150151
151152 defp do_translate ( { { :. , _ , [ module_name , function_name ] } , _ , params } = ast , env ) do
152- if module_name == Kernel do
153- KernelLib . translate_kernel_function ( function_name , params , env )
154- else
155- expanded_ast = Macro . expand ( ast , env )
156- if expanded_ast == ast do
157- Function . make_function_call ( module_name , function_name , params , env )
158- else
159- translate ( expanded_ast , env )
160- end
153+ case module_name do
154+ Kernel ->
155+ KernelLib . translate_kernel_function ( function_name , params , env )
156+ { :__aliases__ , [ alias: false ] , [ :JS ] } ->
157+ JSLib . translate_js_function ( function_name , params , env )
158+ _ ->
159+ expanded_ast = Macro . expand ( ast , env )
160+ if expanded_ast == ast do
161+ Function . make_function_call ( module_name , function_name , params , env )
162+ else
163+ translate ( expanded_ast , env )
164+ end
161165 end
162166 end
163167
@@ -195,15 +199,15 @@ defmodule ElixirScript.Translator do
195199 end
196200
197201 defp do_translate ( { :super , _ , _expressions } , _ ) do
198- raise ElixirScript.UnsupportedError , : super
202+ raise ElixirScript.UnsupportedError , " super"
199203 end
200204
201205 defp do_translate ( { :__CALLER__ , _ , _expressions } , _ ) do
202- raise ElixirScript.UnsupportedError , : __CALLER__
206+ raise ElixirScript.UnsupportedError , " __CALLER__"
203207 end
204208
205209 defp do_translate ( { :__ENV__ , _ , _expressions } , _ ) do
206- raise ElixirScript.UnsupportedError , : __ENV__
210+ raise ElixirScript.UnsupportedError , " __ENV__"
207211 end
208212
209213 defp do_translate ( { :quote , _ , [ [ do: expr ] ] } , _ ) do
@@ -214,12 +218,12 @@ defmodule ElixirScript.Translator do
214218 Quote . make_quote ( opts , expr )
215219 end
216220
217- defp do_translate ( { :import , _ , [ { :__aliases__ , _ , module_name_list } ] } , _ ) do
218- Import . make_import ( module_name_list , [ ] )
221+ defp do_translate ( { :import , _ , [ { :__aliases__ , _ , module_name_list } , [ only: functions ] ] } , _ ) do
222+ Import . make_import ( module_name_list , [ only: functions ] )
219223 end
220224
221- defp do_translate ( { :import , _ , [ { :__aliases__ , _ , module_name_list } , options ] } , _ ) do
222- Import . make_import ( module_name_list , options )
225+ defp do_translate ( { :import , _ , _ } , _ ) do
226+ raise ElixirScript.UnsupportedError , "import without `:only` option"
223227 end
224228
225229 defp do_translate ( { :alias , _ , [ alias_info , options ] } , _ ) when is_tuple ( alias_info ) do
0 commit comments