git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Simplify JS exporting of declarations
39a3a3dGary Burgess
src/Language/PureScript/CodeGen/JS.hs+6−9
@@ -64,17 +64,14 @@ moduleToJs opts (Module name decls exps) env =
64--
64--
65declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
65declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
66declToJs opts mp (ValueDeclaration ident _ _ val) e =
66declToJs opts mp (ValueDeclaration ident _ _ val) e =
67− Just [ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
67+ Just $ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
68− , setExportProperty ident (var ident) ]
69declToJs opts mp (BindingGroupDeclaration vals) e =
68declToJs opts mp (BindingGroupDeclaration vals) e =
70 Just $ concatMap (\(ident, val) ->
69 Just $ concatMap (\(ident, val) ->
71− [ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
70+ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
72− , setExportProperty ident (var ident) ]
73 ) vals
71 ) vals
74declToJs _ mp (DataDeclaration _ _ ctors) _ =
72declToJs _ mp (DataDeclaration _ _ ctors) _ =
75 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), tys) ->
73 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), tys) ->
76− [ JSVariableIntroduction ctor (Just (go pn 0 tys []))
74+ export (Escaped ctor) $ JSVariableIntroduction ctor (Just (go pn 0 tys []))
77− , setExportProperty (Escaped ctor) (JSVar ctor) ]
78 where
75 where
79 go pn _ [] values =
76 go pn _ [] values =
80 JSObjectLiteral [ ("ctor", JSStringLiteral (show (Qualified (Just mp) pn))), ("values", JSArrayLiteral $ reverse values) ]
77 JSObjectLiteral [ ("ctor", JSStringLiteral (show (Qualified (Just mp) pn))), ("values", JSArrayLiteral $ reverse values) ]
@@ -84,15 +81,15 @@ declToJs _ mp (DataDeclaration _ _ ctors) _ =
84declToJs opts mp (DataBindingGroupDeclaration ds) e =
81declToJs opts mp (DataBindingGroupDeclaration ds) e =
85 Just $ concat $ mapMaybe (flip (declToJs opts mp) e) ds
82 Just $ concat $ mapMaybe (flip (declToJs opts mp) e) ds
86declToJs _ _ (ExternDeclaration _ ident (Just js) _) _ =
83declToJs _ _ (ExternDeclaration _ ident (Just js) _) _ =
87− Just [js, setExportProperty ident (var ident)]
84+ Just $ export ident js
88declToJs _ _ _ _ = Nothing
85declToJs _ _ _ _ = Nothing
89
86
90-- |
87-- |
91-- Generate code in the simplified Javascript intermediate representation for exporting a
88-- Generate code in the simplified Javascript intermediate representation for exporting a
92-- declaration from a module.
89-- declaration from a module.
93--
90--
94−setExportProperty :: Ident -> JS -> JS
91+export :: Ident -> JS -> [JS]
95−setExportProperty ident = JSAssignment (accessor ident (JSVar "module"))
92+export ident value = [ value, JSAssignment (accessor ident (JSVar "module")) (var ident) ]
96
93
97-- |
94-- |
98-- Generate code in the simplified Javascript intermediate representation for a variable based on a
95-- Generate code in the simplified Javascript intermediate representation for a variable based on a