1module Generate.JavaScript.Helpers where
3import AST.Annotation (Region)
4import qualified AST.PrettyPrint as PP
5import Language.ECMAScript3.Syntax
12ref :: String -> Expression ()
13ref name = VarRef () (var name)
15prop :: String -> Prop ()
16prop name = PropId () (var name)
20obj :: [String] -> Expression ()
23 x:xs -> foldl (DotRef ()) (ref x) (map var xs)
24 [] -> error "dotSep must be called on a non-empty list of variables"
28localModuleName :: String
29localModuleName = "$moduleName"
31throw :: String -> Region -> Expression ()
33 obj ["_E",kind] `call` [ ref localModuleName, string (PP.renderPretty region) ]
37(<|) :: Expression () -> Expression () -> Expression ()
38(<|) f x = CallExpr () f [x]
40ret :: Expression () -> Statement ()
41ret e = ReturnStmt () (Just e)
43(==>) :: [String] -> Expression () -> Expression ()
44(==>) args e = FuncExpr () Nothing (map var args) [ ret e ]
46function :: [String] -> [Statement ()] -> Expression ()
47function args stmts = FuncExpr () Nothing (map var args) stmts
49call :: Expression () -> [Expression ()] -> Expression ()
54equal :: Expression () -> Expression () -> Expression ()
55equal a b = InfixExpr () OpStrictEq a b
57instanceof :: String -> Expression () -> Expression ()
59 InfixExpr () OpLAnd (typeof "object" x) (InfixExpr () OpInstanceof x (ref tipe))
61typeof :: String -> Expression () -> Expression ()
62typeof tipe x = equal (PrefixExpr () PrefixTypeof x) (string tipe)
64member :: String -> Expression () -> Expression ()
65member 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