@@ -54,18 +54,18 @@ include alias moduleName =
5454
5555internalImports name =
5656 VarDeclStmt ()
57− [ varDecl "N" (obj "Elm.Native")
58− , include "_N" "N.Utils"
59− , include "_L" "N.List"
60− , include "_E" "N.Error"
61− , include "_J" "N.JavaScript"
57+ [ varDecl "_N" (obj "Elm.Native")
58+ , include "_U" "_N.Utils"
59+ , include "_L" "_N.List"
60+ , include "_E" "_N.Error"
61+ , include "_J" "_N.JavaScript"
6262 , varDecl "$moduleName" (string name)
6363 ]
6464
6565literal :: Literal -> Expression ()
6666literal lit =
6767 case lit of
68− Chr c -> obj "_N.chr" <| string [c]
68+ Chr c -> obj "_U.chr" <| string [c]
6969 Str s -> string s
7070 IntNum n -> IntLit () n
7171 FloatNum n -> NumLit () n
@@ -88,19 +88,19 @@ expression (L span expr) =
8888
8989 Remove e x ->
9090 do e' <- expression e
91− return $ obj "_N.remove" `call` [string x, e']
91+ return $ obj "_U.remove" `call` [string x, e']
9292
9393 Insert e x v ->
9494 do v' <- expression v
9595 e' <- expression e
96− return $ obj "_N.insert" `call` [string x, v', e']
96+ return $ obj "_U.insert" `call` [string x, v', e']
9797
9898 Modify e fs ->
9999 do e' <- expression e
100100 fs' <- forM fs $ \(f,v) -> do
101101 v' <- expression v
102102 return $ ArrayLit () [string f, v']
103− return $ obj "_N.replace" `call` [ArrayLit () fs', e']
103+ return $ obj "_U.replace" `call` [ArrayLit () fs', e']
104104
105105 Record fields ->
106106 do fields' <- forM fields $ \(f,e) -> do
@@ -198,11 +198,11 @@ expression (L span expr) =
198198
199199 PortIn name _ _ handler ->
200200 do handler' <- expression handler
201− return $ obj "_N.portIn" `call` [ string name, handler' ]
201+ return $ obj "Native.Ports.portIn" `call` [ string name, handler' ]
202202
203203 PortOut name _ signal ->
204204 do signal' <- expression signal
205− return $ obj "_N.portOut" `call` [ string name, signal' ]
205+ return $ obj "Native.Ports.portOut" `call` [ string name, signal' ]
206206
207207definition :: Def -> State Int [Statement ()]
208208definition (Definition pattern expr@(L span _) _) = do
@@ -309,8 +309,7 @@ generate unsafeModule =
309309 concat [ setup (Just "_elm") (names modul ++ ["values"])
310310 , [ IfSingleStmt () thisModule (ReturnStmt () (Just thisModule)) ]
311311 , [ internalImports (List.intercalate "." (names modul)) ]
312− , concatMap jsImport (imports modul)
313− , checkInPorts (recvPorts modul)
312+ , concatMap jsImport . Set.toList . Set.fromList . map fst $ imports modul
314313 , [ assign ["_op"] (ObjectLit () []) ]
315314 , concat $ evalState (mapM definition . fst . flattenLets [] $ program modul) 0
316315 , [ jsExports ]
@@ -328,7 +327,7 @@ generate unsafeModule =
328327 _ -> ExprStmt () $
329328 AssignExpr () OpAssign (LDot () (dotSep (init path)) (last path)) expr
330329
331− jsImport (modul,_) = setup Nothing path ++ [ include ]
330+ jsImport modul = setup Nothing path ++ [ include ]
332331 where
333332 path = split modul
334333 include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
@@ -340,11 +339,6 @@ generate unsafeModule =
340339 Nothing -> tail . init $ List.inits path
341340 Just nmspc -> drop 2 . init . List.inits $ nmspc : path
342341
343− checkInPorts ports =
344− [ ExprStmt () $ obj "_N.portCheck" `call` [ref "$moduleName", names] ]
345− where
346− names = ArrayLit () [ string name | (name, _, _) <- ports ]
347−
348342binop span op e1 e2 =
349343 case op of
350344 "Basics.." ->
@@ -394,8 +388,8 @@ binop span op e1 e2 =
394388 specialOps = concat
395389 [ specialOp "^" $ \a b -> obj "Math.pow" `call` [a,b]
396390 , specialOp "|>" $ flip (<|)
397− , specialOp "==" $ \a b -> obj "_N.eq" `call` [a,b]
398− , specialOp "/=" $ \a b -> PrefixExpr () PrefixLNot (obj "_N.eq" `call` [a,b])
391+ , specialOp "==" $ \a b -> obj "_U.eq" `call` [a,b]
392+ , specialOp "/=" $ \a b -> PrefixExpr () PrefixLNot (obj "_U.eq" `call` [a,b])
399393 , specialOp "<" $ cmp OpLT 0
400394 , specialOp ">" $ cmp OpGT 0
401395 , specialOp "<=" $ cmp OpLT 1
@@ -403,4 +397,4 @@ binop span op e1 e2 =
403397 , specialOp "div" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
404398 ]
405399
406− cmp op n a b = InfixExpr () op (obj "_N.cmp" `call` [a,b]) (IntLit () n)
400+ cmp op n a b = InfixExpr () op (obj "_U.cmp" `call` [a,b]) (IntLit () n)