@@ -7,6 +7,7 @@ defmodule ElixirScript.Translator.Module do
77 alias ElixirScript.Preprocess.Aliases
88 alias ElixirScript.Preprocess.Using
99 alias ElixirScript.Translator.Function
10+ alias ElixirScript.Translator.Primitive
1011
1112 def make_module ( module_name_list , nil , env ) do
1213 [ % JSModule { name: module_name_list , body: List . wrap ( create__module__ ( module_name_list , env ) ) } ]
@@ -82,7 +83,7 @@ defmodule ElixirScript.Translator.Module do
8283 result
8384 end
8485
85- defp extract_functions_from_module ( { :__block__ , meta , body_list } ) do
86+ def extract_functions_from_module ( { :__block__ , meta , body_list } ) do
8687 { body_list , functions } = Enum . map_reduce ( body_list ,
8788 % { exported: HashDict . new ( ) , private: HashDict . new ( ) } , fn
8889 ( { :def , _ , [ { :when , _ , [ { name , _ , _ } | _guards ] } , _ ] } = function , state ) ->
@@ -104,7 +105,7 @@ defmodule ElixirScript.Translator.Module do
104105 {
105106 nil ,
106107 % { state | private: HashDict . put ( state . private , name , HashDict . get ( state . private , name , [ ] ) ++ [ function ] ) }
107- }
108+ }
108109 ( x , state ) ->
109110 { x , state }
110111 end )
@@ -115,11 +116,11 @@ defmodule ElixirScript.Translator.Module do
115116 { body , functions }
116117 end
117118
118- defp extract_functions_from_module ( body ) do
119+ def extract_functions_from_module ( body ) do
119120 extract_functions_from_module ( { :__block__ , [ ] , List . wrap ( body ) } )
120121 end
121122
122- defp extract_imports_from_body ( body ) do
123+ def extract_imports_from_body ( body ) do
123124 Enum . partition ( body , fn ( x ) ->
124125 case x do
125126 % ESTree.ImportDeclaration { } ->
@@ -130,7 +131,7 @@ defmodule ElixirScript.Translator.Module do
130131 end )
131132 end
132133
133- defp extract_structs_from_body ( body ) do
134+ def extract_structs_from_body ( body ) do
134135 Enum . partition ( body , fn ( x ) ->
135136 case x do
136137 % ESTree.FunctionDeclaration { } ->
@@ -154,7 +155,7 @@ defmodule ElixirScript.Translator.Module do
154155 end
155156 end
156157
157- defp process_imports ( imports , aliases ) do
158+ def process_imports ( imports , aliases ) do
158159 imports ++ make_imports ( aliases )
159160 |> Enum . reduce ( HashSet . new , fn ( x , acc ) ->
160161 HashSet . put ( acc , x )
@@ -180,7 +181,7 @@ defmodule ElixirScript.Translator.Module do
180181 end )
181182 end
182183
183- defp process_functions ( % { exported: exported , private: private } , env ) do
184+ def process_functions ( % { exported: exported , private: private } , env ) do
184185 exported_functions = Enum . map ( Dict . keys ( exported ) , fn ( key ) ->
185186 functions = Dict . get ( exported , key )
186187 { key , Function . process_function ( key , functions , env ) }
@@ -203,10 +204,14 @@ defmodule ElixirScript.Translator.Module do
203204 JS . variable_declaration ( [ declarator ] , :const )
204205 end
205206
206- defp create__module__ ( module_name_list , env ) do
207+ def create__module__ ( module_name_list , env ) do
208+ module_name = Enum . map ( module_name_list , & Atom . to_string ( & 1 ) )
209+ |> Enum . join ( "." )
210+ |> String . to_atom
211+
207212 declarator = JS . variable_declarator (
208213 JS . identifier ( :__MODULE__ ) ,
209- ElixirScript.Translator . translate ( List . last ( module_name_list ) , env )
214+ Primitive . make_atom ( module_name )
210215 )
211216
212217 JS . variable_declaration ( [ declarator ] , :const )
0 commit comments