git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #393 from purescript/noemptymodules

Do not generate module wrapper when module has no declarations

commit511ba81e4443159cd5de4f1ccc3f8ad1e16a8007 authorPhil Freeman <paf31@cantab.net> dateSun 27 Apr 2014, 11:28 (13 years ago) parent6cda05d79de82b
1 file changed+3−1
src/Language/PureScript/CodeGen/JS.hs+3−1
src/Language/PureScript/CodeGen/JS.hs+3−1
@@ -56,13 +56,15 @@ data ModuleType = CommonJS | Globals
5656moduleToJs :: ModuleType -> Options -> Module -> Environment -> [JS]
5757moduleToJs mt opts (Module name decls (Just exps)) env = case mt of
5858 CommonJS -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
59− Globals ->
59+ Globals | not isModuleEmpty ->
6060 [ JSVariableIntroduction (fromJust (optionsBrowserNamespace opts))
6161 (Just (JSBinary Or (JSVar (fromJust (optionsBrowserNamespace opts))) (JSObjectLiteral [])) )
6262 , JSAssignment (JSAccessor (moduleNameToJs name) (JSVar (fromJust (optionsBrowserNamespace opts))))
6363 (JSApp (JSFunction Nothing [] (JSBlock (moduleBody ++ [JSReturn moduleExports]))) [])
6464 ]
65+ _ -> []
6566 where
67+ isModuleEmpty = null jsDecls
6668 moduleBody = JSStringLiteral "use strict" : jsImports ++ jsDecls
6769 moduleExports = JSObjectLiteral $ concatMap exportToJs exps
6870 jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)