Skip to content

Commit 680aff5

Browse files
committed
Check for missing or unnecessary foreign modules
1 parent f56ed2b commit 680aff5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

psc/Main.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,18 @@ compileJS ms foreigns prefix = do
115115

116116
where
117117

118-
--codegenModule :: CF.Module CF.Ann -> m [J.JS]
119118
codegenModule m =
120-
J.moduleToJs m $ (\js -> J.JSApp (J.JSFunction Nothing [] (J.JSBlock
121-
[ J.JSVariableIntroduction "exports" (Just $ J.JSObjectLiteral [])
122-
, J.JSRaw js
123-
, J.JSReturn (J.JSVar "exports")
124-
])) []) <$> CF.moduleName m `M.lookup` foreigns
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 $
123+
J.JSApp (J.JSFunction Nothing [] $
124+
J.JSBlock [ J.JSVariableIntroduction "exports" (Just $ J.JSObjectLiteral [])
125+
, J.JSRaw js
126+
, J.JSReturn (J.JSVar "exports")
127+
]) []
128+
Nothing | requiresForeign -> error "Foreign module missing"
129+
| otherwise -> J.moduleToJs m Nothing
125130

126131
generateMain :: P.Environment -> [J.JS] -> m [J.JS]
127132
generateMain env js = do

0 commit comments

Comments
 (0)