@@ -26,8 +26,11 @@ import Data.Maybe (catMaybes)
2626import Data.Function (on)
2727import Data.List (nub, (\\), delete, sortBy)
2828
29+import qualified Data.Map as M
30+
2931import Control.Monad (foldM, replicateM, forM)
3032import Control.Applicative
33+import Control.Arrow (second)
3134
3235import Language.PureScript.Names
3336import Language.PureScript.Declarations
@@ -51,7 +54,7 @@ moduleToJs opts (Module name decls (Just exps)) env = do
5154 let optimized = concat $ map (map $ optimize opts) $ catMaybes jsDecls
5255 let isModuleEmpty = null exps
5356 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
5558 return $ case optionsAdditional opts of
5659 MakeOptions -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
5760 CompileOptions ns _ _ | not isModuleEmpty ->
@@ -154,12 +157,12 @@ declToJs _ _ _ _ = return Nothing
154157-- |
155158-- Generate key//value pairs for an object literal exporting values from a module.
156159--
157−exportToJs :: DeclarationRef -> [(String, JS)]
158−exportToJs (TypeRef _ (Just dctors)) = map ((\n -> (n, var (Ident n))) . runProperName) dctors
159−exportToJs (ValueRef name) = [(runIdent name, var name)]
160−exportToJs (TypeInstanceRef name) = [(runIdent name, var name)]
161−exportToJs (TypeClassRef name) = [(runProperName name, var $ Ident $ runProperName name)]
162−exportToJs _ = []
160+exportToJs :: DeclarationRef -> M.Map String Ident
161+exportToJs (TypeRef _ (Just dctors)) = M.fromList [ (n, Ident n) | (ProperName n) <- dctors ]
162+exportToJs (ValueRef name) = M.singleton (runIdent name) name
163+exportToJs (TypeInstanceRef name) = M.singleton (runIdent name) name
164+exportToJs (TypeClassRef name) = M.singleton (runProperName name) (Ident $ runProperName name)
165+exportToJs _ = M.empty
163166
164167-- |
165168-- Generate code in the simplified Javascript intermediate representation for a variable based on a