1module Generate.JavaScript.Variable 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
14swap :: Char -> Char -> Char -> Char
16 if c == from then to else c
19canonical :: Var.Canonical -> JS.Expression ()
20canonical (Var.Canonical home name) =
21 if Help.isOp name then
22 JS.BracketRef () (JS.ref (addRoot home "_op")) (JS.string name)
25 JS.ref (addRoot home (varName name))
28addRoot :: Var.Home -> String -> String
34 Var.TopLevel moduleName ->
35 canonicalName moduleName name
40 Var.Module moduleName ->
41 canonicalName moduleName name
44canonicalName :: ModuleName.Canonical -> String -> String
45canonicalName (ModuleName.Canonical (Pkg.Name user project) moduleName) name =
46 map (swap '-' '_') user
47 ++ '$' : map (swap '-' '_') project
48 ++ '$' : List.intercalate "$" moduleName
53varName :: String -> String
56 if Set.member name jsReserveds then '$' : name else name
58 map (swap '\'' '$') saferName
61--value :: Module.Name -> String -> JS.Expression ()
63-- canonical (Var.Canonical (Var.Module home) name)
66jsReserveds :: Set.Set String
67jsReserveds = Set.fromList
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
80 , "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9"
81 , "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