@@ -64,17 +64,14 @@ moduleToJs opts (Module name decls exps) env =
6464--
6565declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
6666declToJs opts mp (ValueDeclaration ident _ _ val) e =
67− Just [ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
68− , setExportProperty ident (var ident) ]
67+ Just $ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
6968declToJs opts mp (BindingGroupDeclaration vals) e =
7069 Just $ concatMap (\(ident, val) ->
71− [ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
72− , setExportProperty ident (var ident) ]
70+ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
7371 ) vals
7472declToJs _ mp (DataDeclaration _ _ ctors) _ =
7573 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), tys) ->
76− [ JSVariableIntroduction ctor (Just (go pn 0 tys []))
77− , setExportProperty (Escaped ctor) (JSVar ctor) ]
74+ export (Escaped ctor) $ JSVariableIntroduction ctor (Just (go pn 0 tys []))
7875 where
7976 go pn _ [] values =
8077 JSObjectLiteral [ ("ctor", JSStringLiteral (show (Qualified (Just mp) pn))), ("values", JSArrayLiteral $ reverse values) ]
@@ -84,15 +81,15 @@ declToJs _ mp (DataDeclaration _ _ ctors) _ =
8481declToJs opts mp (DataBindingGroupDeclaration ds) e =
8582 Just $ concat $ mapMaybe (flip (declToJs opts mp) e) ds
8683declToJs _ _ (ExternDeclaration _ ident (Just js) _) _ =
87− Just [js, setExportProperty ident (var ident)]
84+ Just $ export ident js
8885declToJs _ _ _ _ = Nothing
8986
9087-- |
9188-- Generate code in the simplified Javascript intermediate representation for exporting a
9289-- declaration from a module.
9390--
94−setExportProperty :: Ident -> JS -> JS
95−setExportProperty ident = JSAssignment (accessor ident (JSVar "module"))
91+export :: Ident -> JS -> [JS]
92+export ident value = [ value, JSAssignment (accessor ident (JSVar "module")) (var ident) ]
9693
9794-- |
9895-- Generate code in the simplified Javascript intermediate representation for a variable based on a