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