@@ -26,8 +26,11 @@ import Data.Maybe (catMaybes)
26import Data.Function (on)
26import Data.Function (on)
27import Data.List (nub, (\\), delete, sortBy)
27import Data.List (nub, (\\), delete, sortBy)
29+import qualified Data.Map as M
29import Control.Monad (foldM, replicateM, forM)
31import Control.Monad (foldM, replicateM, forM)
30import Control.Applicative
32import Control.Applicative
33+import Control.Arrow (second)
32import Language.PureScript.Names
35import Language.PureScript.Names
33import Language.PureScript.Declarations
36import Language.PureScript.Declarations
@@ -51,7 +54,7 @@ moduleToJs opts (Module name decls (Just exps)) env = do
51 let optimized = concat $ map (map $ optimize opts) $ catMaybes jsDecls
54 let optimized = concat $ map (map $ optimize opts) $ catMaybes jsDecls
52 let isModuleEmpty = null exps
55 let isModuleEmpty = null exps
53 let moduleBody = JSStringLiteral "use strict" : jsImports ++ optimized
56 let moduleBody = JSStringLiteral "use strict" : jsImports ++ optimized
54− let moduleExports = JSObjectLiteral $ concatMap exportToJs exps
57+ let moduleExports = JSObjectLiteral . map (second var) . M.toList . M.unions $ map exportToJs exps
55 return $ case optionsAdditional opts of
58 return $ case optionsAdditional opts of
56 MakeOptions -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
59 MakeOptions -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
57 CompileOptions ns _ _ | not isModuleEmpty ->
60 CompileOptions ns _ _ | not isModuleEmpty ->
@@ -154,12 +157,12 @@ declToJs _ _ _ _ = return Nothing
155-- Generate key//value pairs for an object literal exporting values from a module.
158-- Generate key//value pairs for an object literal exporting values from a module.
157−exportToJs :: DeclarationRef -> [(String, JS)]
160+exportToJs :: DeclarationRef -> M.Map String Ident
158−exportToJs (TypeRef _ (Just dctors)) = map ((\n -> (n, var (Ident n))) . runProperName) dctors
161+exportToJs (TypeRef _ (Just dctors)) = M.fromList [ (n, Ident n) | (ProperName n) <- dctors ]
159−exportToJs (ValueRef name) = [(runIdent name, var name)]
162+exportToJs (ValueRef name) = M.singleton (runIdent name) name
160−exportToJs (TypeInstanceRef name) = [(runIdent name, var name)]
163+exportToJs (TypeInstanceRef name) = M.singleton (runIdent name) name
161−exportToJs (TypeClassRef name) = [(runProperName name, var $ Ident $ runProperName name)]
164+exportToJs (TypeClassRef name) = M.singleton (runProperName name) (Ident $ runProperName name)
162−exportToJs _ = []
165+exportToJs _ = M.empty
165-- Generate code in the simplified Javascript intermediate representation for a variable based on a
168-- Generate code in the simplified Javascript intermediate representation for a variable based on a