@@ -3,51 +3,39 @@ defmodule ElixirScript.ModuleSystems.Common do
33 alias ElixirScript.Translator
44 alias ElixirScript.Translator.Utils
55
6- def import_module ( module_name , from , env ) do
7- ref_declarator = JS . variable_declarator (
8- Translator . translate! ( module_name , env ) ,
9- JS . call_expression (
10- JS . identifier ( "require" ) ,
11- [ JS . literal ( from ) ]
12- )
13- )
6+ def import_module ( module_names , from , env ) when is_list ( module_names ) do
7+ assignment_properties = Enum . map ( module_names , fn ( x ) ->
8+ JS . assignment_property ( Translator . translate! ( x , env ) )
9+ end )
1410
15- JS . variable_declaration ( [ ref_declarator ] , :const )
11+ do_import_module ( JS . object_pattern ( assignment_properties ) , from )
12+ end
13+
14+ def import_module ( module_name , from , env ) do
15+ do_import_module ( Translator . translate! ( module_name , env ) , from )
1616 end
1717
1818 def import_module ( module_name , % ElixirScript.Macro.Env { } = env ) do
1919 { from , _ } = Code . eval_quoted ( module_name )
20-
21- ref_declarator = JS . variable_declarator (
22- Translator . translate! ( module_name , env ) ,
23- JS . call_expression (
24- JS . identifier ( "require" ) ,
25- [ JS . literal ( Macro . underscore ( from ) ) ]
26- )
27- )
28-
29- JS . variable_declaration ( [ ref_declarator ] , :const )
30-
20+ do_import_module ( Translator . translate! ( module_name , env ) , Macro . underscore ( from ) )
3121 end
3222
3323 def import_module ( import_name , from ) do
24+ do_import_module ( JS . identifier ( import_name ) , from )
25+ end
26+
27+ defp do_import_module ( ref , file_path ) do
3428
3529 ref_declarator = JS . variable_declarator (
36- JS . identifier ( import_name ) ,
30+ ref ,
3731 JS . call_expression (
3832 JS . identifier ( "require" ) ,
39- [ JS . literal ( from ) ]
33+ [ JS . literal ( file_path ) ]
4034 )
4135 )
4236
4337 JS . variable_declaration ( [ ref_declarator ] , :const )
44- end
4538
46- defp do_import_module ( import_specifiers , file_path ) do
47- JS . import_declaration (
48- import_specifiers ,
49- JS . literal ( file_path )
50- )
5139 end
5240
5341 def export_module ( exported_object ) do
0 commit comments