git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Check for missing or unnecessary foreign modules
680aff5Gary Burgess
psc/Main.hs+11−6
@@ -115,13 +115,18 @@ compileJS ms foreigns prefix = do
115
115
116 where
116 where
117
117
118− --codegenModule :: CF.Module CF.Ann -> m [J.JS]
119 codegenModule m =
118 codegenModule m =
119+ let requiresForeign = not $ null (CF.moduleForeign m)
120+ in case CF.moduleName m `M.lookup` foreigns of
121+ Just js | not requiresForeign -> error "Found unnecessary foreign module"
122+ | otherwise -> J.moduleToJs m $ Just $
120− J.moduleToJs m $ (\js -> J.JSApp (J.JSFunction Nothing [] (J.JSBlock
123+ J.JSApp (J.JSFunction Nothing [] $
121− [ J.JSVariableIntroduction "exports" (Just $ J.JSObjectLiteral [])
124+ J.JSBlock [ J.JSVariableIntroduction "exports" (Just $ J.JSObjectLiteral [])
122− , J.JSRaw js
125+ , J.JSRaw js
123− , J.JSReturn (J.JSVar "exports")
126+ , J.JSReturn (J.JSVar "exports")
124− ])) []) <$> CF.moduleName m `M.lookup` foreigns
127+ ]) []
128+ Nothing | requiresForeign -> error "Foreign module missing"
129+ | otherwise -> J.moduleToJs m Nothing
125
130
126 generateMain :: P.Environment -> [J.JS] -> m [J.JS]
131 generateMain :: P.Environment -> [J.JS] -> m [J.JS]
127 generateMain env js = do
132 generateMain env js = do