2module Generate.JavaScript.Helpers where
4import AST.Annotation (Region)
5import qualified AST.PrettyPrint as PP
6import Language.ECMAScript3.Syntax
13ref :: String -> Expression ()
14ref name = VarRef () (var name)
16prop :: String -> Prop ()
17prop name = PropId () (var name)
21obj :: [String] -> Expression ()
24 x:xs -> foldl (DotRef ()) (ref x) (map var xs)
25 [] -> error "dotSep must be called on a non-empty list of variables"
29localModuleName :: String
30localModuleName = "$moduleName"
32throw :: String -> Region -> Expression ()
34 obj ["_E",kind] `call` [ ref localModuleName, string (PP.renderPretty region) ]
38(<|) :: Expression () -> Expression () -> Expression ()
39(<|) f x = CallExpr () f [x]
41ret :: Expression () -> Statement ()
42ret e = ReturnStmt () (Just e)
44(==>) :: [String] -> Expression () -> Expression ()
45(==>) args e = FuncExpr () Nothing (map var args) [ ret e ]
47function :: [String] -> [Statement ()] -> Expression ()
48function args stmts = FuncExpr () Nothing (map var args) stmts
50call :: Expression () -> [Expression ()] -> Expression ()
55equal :: Expression () -> Expression () -> Expression ()
56equal a b = InfixExpr () OpStrictEq a b
58instanceof :: String -> Expression () -> Expression ()
60 InfixExpr () OpLAnd (typeof "object" x) (InfixExpr () OpInstanceof x (ref tipe))
62typeof :: String -> Expression () -> Expression ()
63typeof tipe x = equal (PrefixExpr () PrefixTypeof x) (string tipe)
65member :: String -> Expression () -> Expression ()
66member field x = InfixExpr () OpIn (string field) x
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list