@@ -3,13 +3,26 @@ defmodule ElixirScript.Translate.Forms.JS do
33 alias ESTree.Tools.Builder , as: J
44 alias ElixirScript.Translate.Form
55
6+ def call_property ( ) do
7+ J . member_expression (
8+ J . member_expression (
9+ J . identifier ( "Bootstrap" ) ,
10+ J . member_expression (
11+ J . identifier ( "Core" ) ,
12+ J . identifier ( "Functions" )
13+ )
14+ ) ,
15+ J . identifier ( "call_property" )
16+ )
17+ end
18+
619 def global ( ) do
7- Builder . member_expression (
8- Builder . member_expression (
9- Builder . identifier ( "Bootstrap" ) ,
10- Builder . identifier ( "Core" )
20+ J . member_expression (
21+ J . member_expression (
22+ J . identifier ( "Bootstrap" ) ,
23+ J . identifier ( "Core" )
1124 ) ,
12- Builder . identifier ( "global" )
25+ J . identifier ( "global" )
1326 )
1427 end
1528
@@ -41,15 +54,15 @@ defmodule ElixirScript.Translate.Forms.JS do
4154 { ast , state }
4255 end
4356
44- defp do_translate ( { { :. , _ , [ JS , :throw ] } , _ , [ term ] } , state ) do
57+ def compile ( { { :. , _ , [ JS , :throw ] } , _ , [ term ] } , state ) do
4558 ast = J . throw_statement (
4659 Form . compile! ( term , state )
4760 )
4861
4962 { ast , state }
5063 end
5164
52- defp do_translate ( { { :. , _ , [ JS , :import ] } , _ , [ term ] } , state ) do
65+ def compile ( { { :. , _ , [ JS , :import ] } , _ , [ term ] } , state ) do
5366 ast = J . call_expression (
5467 J . identifier ( "import" ) ,
5568 [ Form . compile! ( term , state ) ]
@@ -58,7 +71,19 @@ defmodule ElixirScript.Translate.Forms.JS do
5871 { ast , state }
5972 end
6073
61- defp do_translate ( { { :. , _ , [ JS , function ] } , _ , params } , state ) do
74+ def compile ( { { :. , _ , [ JS , function ] } , _ , [ ] } , state ) do
75+ ast = J . call_expression (
76+ call_property ( ) ,
77+ [
78+ global ( ) ,
79+ Form . compile! ( to_string ( function ) , state )
80+ ]
81+ )
82+
83+ { ast , state }
84+ end
85+
86+ def compile ( { { :. , _ , [ JS , function ] } , _ , params } , state ) do
6287 ast = J . call_expression (
6388 J . identifier ( function ) ,
6489 Enum . map ( params , & Form . compile! ( & 1 , state ) )
0 commit comments