on master help sign in
Add `open` keyword to import everything. Default is now to just import the module, not to open it into local scope.
commit1f1187cc74fa2fe85d7189ec9300ba83df37b3ad authorevancz <info@elm-lang.org> dateTue 21 May 2013, 10:02 (13 years ago) parent7f31484
3 files changed+9−4
compiler/Gen/CompileToJS.hs+2−1 compiler/Parse/Library.hs+1−1 compiler/Parse/Modules.hs+6−2
compiler/Gen/CompileToJS.hs+2−1
@@ -99,10 +99,11 @@ jsImport (modul, how) =
9999 Hiding vs -> include ++ " var hiding=" ++ (jsObj $ map (++":1") vs) ++
100100 "; for(var k in _){if(k in hiding)continue;" ++
101101 "eval('var '+k+'=_[\"'+k+'\"]')}"
102− Importing vs -> include ++ "\nvar " ++ intercalate ", " (map def vs) ++ ";"
102+ Importing vs -> include ++ named
103103 where
104104 imprt v = assign' v ("_." ++ v)
105105 def (o:p) = imprt (if isOp o then "$op['" ++ o:p ++ "']" else deprime (o:p))
106+ named = if null vs then "" else "\nvar " ++ intercalate ", " (map def vs) ++ ";"
106107 where
107108 include = "\nvar _ = Elm." ++ modul ++ parens "elm" ++ ";" ++ setup modul
108109 setup moduleName = " var " ++ concatMap (++";") (defs ++ [assign' moduleName "_"])
compiler/Parse/Library.hs+1−1
@@ -16,7 +16,7 @@ reserveds = [ "if", "then", "else"
1616 , "let", "in"
1717 , "data", "type"
1818 , "module", "where"
19− , "import", "as", "hiding"
19+ , "import", "as", "hiding", "open"
2020 , "export", "foreign" ]
2121
2222expecting = flip (<?>)
compiler/Parse/Modules.hs+6−2
@@ -30,9 +30,13 @@ import' :: IParser (String, ImportMethod)
3030import' = do
3131 reserved "import"
3232 whitespace
33+ open <- optionMaybe (reserved "open")
34+ whitespace
3335 name <- intercalate "." <$> dotSep1 capVar
34− method <- option (Hiding []) $ try (whitespace >> (as' <|> importing'))
35− return (name, method)
36+ case open of
37+ Just _ -> return (name, Hiding [])
38+ Nothing -> let how = try (whitespace >> (as' <|> importing'))
39+ in (,) name <$> option (Importing []) how
3640
3741
3842as' :: IParser ImportMethod