Skip to content

Commit

Permalink
Merge pull request #393 from purescript/noemptymodules
Browse files Browse the repository at this point in the history
Do not generate module wrapper when module has no declarations
  • Loading branch information
paf31 committed Apr 27, 2014
2 parents 6cda05d + 79de82b commit 511ba81
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Language/PureScript/CodeGen/JS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ data ModuleType = CommonJS | Globals
moduleToJs :: ModuleType -> Options -> Module -> Environment -> [JS]
moduleToJs mt opts (Module name decls (Just exps)) env = case mt of
CommonJS -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
Globals ->
Globals | not isModuleEmpty ->
[ JSVariableIntroduction (fromJust (optionsBrowserNamespace opts))
(Just (JSBinary Or (JSVar (fromJust (optionsBrowserNamespace opts))) (JSObjectLiteral [])) )
, JSAssignment (JSAccessor (moduleNameToJs name) (JSVar (fromJust (optionsBrowserNamespace opts))))
(JSApp (JSFunction Nothing [] (JSBlock (moduleBody ++ [JSReturn moduleExports]))) [])
]
_ -> []
where
isModuleEmpty = null jsDecls
moduleBody = JSStringLiteral "use strict" : jsImports ++ jsDecls
moduleExports = JSObjectLiteral $ concatMap exportToJs exps
jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)
Expand Down

0 comments on commit 511ba81

Please sign in to comment.