Guard against issue #387

This commit is contained in:
Evan Czaplicki 2013-12-15 19:14:00 -08:00
parent fe7e3195fa
commit 61ff49067f

View file

@ -50,7 +50,7 @@ varDecl x expr =
VarDecl () (var x) (Just expr) VarDecl () (var x) (Just expr)
include alias moduleName = include alias moduleName =
varDecl alias (obj (moduleName ++ ".make") <| ref "elm") varDecl alias (obj (moduleName ++ ".make") <| ref "_elm")
internalImports name = internalImports name =
VarDeclStmt () VarDeclStmt ()
@ -293,11 +293,11 @@ clause span variable (Case.Clause value vars mtch) =
generate :: MetadataModule () () -> String generate :: MetadataModule () () -> String
generate modul = generate modul =
show . prettyPrint $ setup (Just "Elm") (names modul ++ ["make"]) ++ show . prettyPrint $ setup (Just "Elm") (names modul ++ ["make"]) ++
[ assign ("Elm" : names modul ++ ["make"]) (function ["elm"] programStmts) ] [ assign ("Elm" : names modul ++ ["make"]) (function ["_elm"] programStmts) ]
where where
thisModule = dotSep ("elm" : names modul ++ ["values"]) thisModule = dotSep ("_elm" : names modul ++ ["values"])
programStmts = programStmts =
concat [ setup (Just "elm") (names modul ++ ["values"]) concat [ setup (Just "_elm") (names modul ++ ["values"])
, [ IfSingleStmt () thisModule (ReturnStmt () (Just thisModule)) ] , [ IfSingleStmt () thisModule (ReturnStmt () (Just thisModule)) ]
, [ internalImports (List.intercalate "." (names modul)) ] , [ internalImports (List.intercalate "." (names modul)) ]
, concatMap jsImport (imports modul) , concatMap jsImport (imports modul)
@ -309,7 +309,7 @@ generate modul =
, [ ReturnStmt () (Just thisModule) ] , [ ReturnStmt () (Just thisModule) ]
] ]
jsExports = assign ("elm" : names modul ++ ["values"]) (ObjectLit () exs) jsExports = assign ("_elm" : names modul ++ ["values"]) (ObjectLit () exs)
where where
exs = map entry . filter (not . isOp) $ "_op" : exports modul exs = map entry . filter (not . isOp) $ "_op" : exports modul
entry x = (PropId () (var x), ref x) entry x = (PropId () (var x), ref x)
@ -323,7 +323,7 @@ generate modul =
jsImport (modul,_) = setup Nothing path ++ [ include ] jsImport (modul,_) = setup Nothing path ++ [ include ]
where where
path = split modul path = split modul
include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "elm" include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
setup namespace path = map create paths setup namespace path = map create paths
where where
@ -332,15 +332,15 @@ generate modul =
Nothing -> tail . init $ List.inits path Nothing -> tail . init $ List.inits path
Just nmspc -> drop 2 . init . List.inits $ nmspc : path Just nmspc -> drop 2 . init . List.inits $ nmspc : path
addId js = InfixExpr () OpAdd (string (js++"_")) (obj "elm.id") addId js = InfixExpr () OpAdd (string (js++"_")) (obj "_elm.id")
importEvent (js,base,elm,_) = importEvent (js,base,elm,_) =
[ VarDeclStmt () [ varDecl elm $ obj "Signal.constant" <| evalState (expression base) 0 ] [ VarDeclStmt () [ varDecl elm $ obj "Signal.constant" <| evalState (expression base) 0 ]
, ExprStmt () $ , ExprStmt () $
obj "document.addEventListener" `call` obj "document.addEventListener" `call`
[ addId js [ addId js
, function ["e"] , function ["_e"]
[ ExprStmt () $ obj "elm.notify" `call` [dotSep [elm,"id"], obj "e.value"] ] [ ExprStmt () $ obj "_elm.notify" `call` [dotSep [elm,"id"], obj "_e.value"] ]
] ]
] ]
@ -348,13 +348,13 @@ generate modul =
ExprStmt () $ ExprStmt () $
ref "A2" `call` ref "A2" `call`
[ obj "Signal.lift" [ obj "Signal.lift"
, function ["v"] , function ["_v"]
[ VarDeclStmt () [varDecl "e" $ obj "document.createEvent" <| string "Event"] [ VarDeclStmt () [varDecl "_e" $ obj "document.createEvent" <| string "Event"]
, ExprStmt () $ , ExprStmt () $
obj "e.initEvent" `call` [ addId js, BoolLit () True, BoolLit () True ] obj "_e.initEvent" `call` [ addId js, BoolLit () True, BoolLit () True ]
, ExprStmt () $ AssignExpr () OpAssign (LDot () (ref "e") "value") (ref "v") , ExprStmt () $ AssignExpr () OpAssign (LDot () (ref "_e") "value") (ref "_v")
, ExprStmt () $ obj "document.dispatchEvent" <| ref "e" , ExprStmt () $ obj "document.dispatchEvent" <| ref "_e"
, ReturnStmt () (Just $ ref "v") , ReturnStmt () (Just $ ref "_v")
] ]
, ref elm ] , ref elm ]