2module Generate.JavaScript.Variable where
4import qualified AST.Helpers as Help
5import qualified AST.Variable as Var
6import qualified Data.Set as Set
7import qualified Generate.JavaScript.Helpers as JS
8import qualified Language.ECMAScript3.Syntax as JS
10swap :: Char -> Char -> Char -> Char
11swap from to c = if c == from then to else c
13canonical :: Var.Canonical -> JS.Expression ()
14canonical (Var.Canonical home name) =
15 case Help.isOp name of
16 True -> JS.BracketRef () (JS.obj (home' ++ ["_op"])) (JS.string name)
17 False -> JS.obj (home' ++ [ varName name ])
23 Var.Module path -> [ moduleName path ]
25moduleName :: String -> String
26moduleName x = '$' : map (swap '.' '$') x
28varName :: String -> String
29varName x = map (swap '\'' '$') x'
31 x' = if Set.member x jsReserveds then '$' : x else x
33value :: String -> String -> JS.Expression ()
35 canonical (Var.Canonical (Var.Module home) name)
37jsReserveds :: Set.Set String
38jsReserveds = Set.fromList
39 [ "null", "undefined", "Nan", "Infinity", "true", "false", "eval"
40 , "arguments", "int", "byte", "char", "goto", "long", "final", "float"
41 , "short", "double", "native", "throws", "boolean", "abstract", "volatile"
42 , "transient", "synchronized", "function", "break", "case", "catch"
43 , "continue", "debugger", "default", "delete", "do", "else", "finally"
44 , "for", "function", "if", "in", "instanceof", "new", "return", "switch"
45 , "this", "throw", "try", "typeof", "var", "void", "while", "with", "class"
46 , "const", "enum", "export", "extends", "import", "super", "implements"
47 , "interface", "let", "package", "private", "protected", "public"
49 -- reserved by the Elm runtime system
51 , "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9"
52 , "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