1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript.BuiltIn
20import Data.Text (Text)
22import qualified AST.Module.Name as ModuleName
23import qualified AST.Variable as Var
24import qualified Generate.JavaScript.Builder as JS
25import Generate.JavaScript.Helpers ((<|), (==>))
26import qualified Generate.JavaScript.Variable as Var
27import Generate.JavaScript.Variable (Generator)
28import qualified Reporting.Region as R
35char :: Text -> Generator JS.Expr
37 utils "chr" [ JS.String c ]
40utils :: Text -> [JS.Expr] -> Generator JS.Expr
42 do func <- core "Elm.Kernel.Utils" name
43 return $ JS.Call func args
46core :: ModuleName.Raw -> Text -> Generator JS.Expr
48 Var.global (Var.Global (ModuleName.inCore home) name)
55list :: [JS.Expr] -> Generator JS.Expr
57 do fromArray <- core "Elm.Kernel.List" "fromArray"
58 return $ fromArray <| JS.Array elements
61cons :: JS.Expr -> JS.Expr -> Generator JS.Expr
63 do func <- core "Elm.Kernel.List" "Cons"
64 return $ JS.Call func [first, rest]
71recordUpdate :: JS.Expr -> [(Text, JS.Expr)] -> Generator JS.Expr
72recordUpdate record fields =
75 , JS.Object (map (uncurry (==>)) fields)
83eq :: JS.Expr -> JS.Expr -> Generator JS.Expr
85 utils "eq" [ left, right ]
88cmp :: JS.Expr -> JS.Expr -> Generator JS.Expr
90 utils "cmp" [ left, right ]
97effectManagers :: Generator JS.Expr
99 core "Elm.Kernel.Platform" "effectManagers"
102effect :: ModuleName.Canonical -> Generator JS.Expr
104 do leaf <- core "Elm.Kernel.Platform" "leaf"
105 return $ leaf <| JS.String (ModuleName.canonicalToText effectName)
108outgoingPort :: Text -> JS.Expr -> Generator JS.Expr
109outgoingPort name converter =
110 do outPort <- core "Elm.Kernel.Platform" "outgoingPort"
111 return $ JS.Call outPort [ JS.String name, converter ]
114incomingPort :: Text -> JS.Expr -> Generator JS.Expr
115incomingPort name converter =
116 do inPort <- core "Elm.Kernel.Platform" "incomingPort"
117 return $ JS.Call inPort [ JS.String name, converter ]
124staticProgram :: Generator JS.Expr
126 Var.global (Var.Global (ModuleName.inBrowser "Browser") "staticPage")
133crash :: ModuleName.Canonical -> R.Region -> Maybe (JS.Expr) -> Generator JS.Expr
134crash home region maybeCaseCrashValue =
137 JS.String (ModuleName.canonicalToText home)
139 case maybeCaseCrashValue of
141 utils "crash" [ homeString, regionToJs region ]
144 utils "crashCase" [ homeString, regionToJs region, crashValue ]
147regionToJs :: R.Region -> JS.Expr
148regionToJs (R.Region start end) =
150 [ "start" ==> positionToJs start
151 , "end" ==> positionToJs end
155positionToJs :: R.Position -> JS.Expr
156positionToJs (R.Position line column) =
158 [ "line" ==> JS.Int line
159 , "column" ==> JS.Int column
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