1module Generate.JavaScript.Variable (canonical, safe) where
3import qualified Data.List as List
4import qualified Data.Set as Set
5import qualified Language.ECMAScript3.Syntax as JS
7import qualified AST.Helpers as Help
8import qualified AST.Module.Name as ModuleName
9import qualified AST.Variable as Var
10import qualified Elm.Package as Pkg
11import qualified Generate.JavaScript.Helpers as JS
14-- INSTANTIATE VARIABLES
16canonical :: Var.Canonical -> JS.Expression ()
17canonical (Var.Canonical home name) =
18 if Help.isOp name then
19 JS.BracketRef () (JS.ref (addRoot home "_op")) (JS.string name)
22 JS.ref (addRoot home (safe name))
25addRoot :: Var.Home -> String -> String
31 Var.TopLevel moduleName ->
32 canonicalName moduleName name
37 Var.Module moduleName ->
38 canonicalName moduleName name
41canonicalName :: ModuleName.Canonical -> String -> String
42canonicalName (ModuleName.Canonical (Pkg.Name user project) moduleName) name =
43 map (swap '-' '_') user
44 ++ '$' : map (swap '-' '_') project
45 ++ '$' : List.intercalate "$" moduleName
49swap :: Char -> Char -> Char -> Char
51 if c == from then to else c
56safe :: String -> String
59 if Set.member name jsReserveds then '$' : name else name
61 map (swap '\'' '$') saferName
64jsReserveds :: Set.Set String
68 [ "null", "undefined", "Nan", "Infinity", "true", "false", "eval"
69 , "arguments", "int", "byte", "char", "goto", "long", "final", "float"
70 , "short", "double", "native", "throws", "boolean", "abstract", "volatile"
71 , "transient", "synchronized", "function", "break", "case", "catch"
72 , "continue", "debugger", "default", "delete", "do", "else", "finally"
73 , "for", "function", "if", "in", "instanceof", "new", "return", "switch"
74 , "this", "throw", "try", "typeof", "var", "void", "while", "with", "class"
75 , "const", "enum", "export", "extends", "import", "super", "implements"
76 , "interface", "let", "package", "private", "protected", "public"
78 -- reserved by the Elm runtime system
79 , "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9"
80 , "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9"
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