@@ -7,59 +7,91 @@ import Language.ECMAScript3.Syntax
77-- Creating Variables
88
99var :: String -> Id ()
10−var name = Id () name
10+var name =
11+ Id () name
12+
1113
1214ref :: String -> Expression ()
13−ref name = VarRef () (var name)
15+ref name =
16+ VarRef () (var name)
17+
1418
1519prop :: String -> Prop ()
16−prop name = PropId () (var name)
20+prop name =
21+ PropId () (var name)
22+
1723
1824string = StringLit ()
1925
26+
2027obj :: [String] -> Expression ()
2128obj vars =
2229 case vars of
2330 x:xs -> foldl (DotRef ()) (ref x) (map var xs)
2431 [] -> error "dotSep must be called on a non-empty list of variables"
2532
33+
2634-- Specific Utilities
2735
2836localModuleName :: String
29−localModuleName = "$moduleName"
37+localModuleName =
38+ "$moduleName"
39+
3040
3141throw :: String -> Region -> Expression ()
3242throw kind region =
33− obj ["_U",kind] `call` [ ref localModuleName, string (PP.renderPretty region) ]
43+ let args =
44+ [ ref localModuleName
45+ , string (PP.renderPretty region)
46+ ]
47+ in
48+ obj ["_U",kind] `call` args
49+
3450
3551-- Function Calls
3652
3753(<|) :: Expression () -> Expression () -> Expression ()
38−(<|) f x = CallExpr () f [x]
54+(<|) f x =
55+ CallExpr () f [x]
56+
3957
4058ret :: Expression () -> Statement ()
41−ret e = ReturnStmt () (Just e)
59+ret e =
60+ ReturnStmt () (Just e)
61+
4262
4363(==>) :: [String] -> Expression () -> Expression ()
44−(==>) args e = FuncExpr () Nothing (map var args) [ ret e ]
64+(==>) args e =
65+ FuncExpr () Nothing (map var args) [ ret e ]
66+
4567
4668function :: [String] -> [Statement ()] -> Expression ()
47−function args stmts = FuncExpr () Nothing (map var args) stmts
69+function args stmts =
70+ FuncExpr () Nothing (map var args) stmts
71+
4872
4973call :: Expression () -> [Expression ()] -> Expression ()
50−call = CallExpr ()
74+call =
75+ CallExpr ()
76+
5177
5278-- Checks
5379
5480equal :: Expression () -> Expression () -> Expression ()
55−equal a b = InfixExpr () OpStrictEq a b
81+equal a b =
82+ InfixExpr () OpStrictEq a b
83+
5684
5785instanceof :: String -> Expression () -> Expression ()
5886instanceof tipe x =
5987 InfixExpr () OpLAnd (typeof "object" x) (InfixExpr () OpInstanceof x (ref tipe))
6088
89+
6190typeof :: String -> Expression () -> Expression ()
62−typeof tipe x = equal (PrefixExpr () PrefixTypeof x) (string tipe)
91+typeof tipe x =
92+ equal (PrefixExpr () PrefixTypeof x) (string tipe)
93+
6394
6495member :: String -> Expression () -> Expression ()
65−member field x = InfixExpr () OpIn (string field) x
96+member field x =
97+ InfixExpr () OpIn (string field) x