@@ -56,13 +56,15 @@ data ModuleType = CommonJS | Globals
56moduleToJs :: ModuleType -> Options -> Module -> Environment -> [JS]
56moduleToJs :: ModuleType -> Options -> Module -> Environment -> [JS]
57moduleToJs mt opts (Module name decls (Just exps)) env = case mt of
57moduleToJs mt opts (Module name decls (Just exps)) env = case mt of
58 CommonJS -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
58 CommonJS -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) moduleExports]
59− Globals ->
59+ Globals | not isModuleEmpty ->
60 [ JSVariableIntroduction (fromJust (optionsBrowserNamespace opts))
60 [ JSVariableIntroduction (fromJust (optionsBrowserNamespace opts))
61 (Just (JSBinary Or (JSVar (fromJust (optionsBrowserNamespace opts))) (JSObjectLiteral [])) )
61 (Just (JSBinary Or (JSVar (fromJust (optionsBrowserNamespace opts))) (JSObjectLiteral [])) )
62 , JSAssignment (JSAccessor (moduleNameToJs name) (JSVar (fromJust (optionsBrowserNamespace opts))))
62 , JSAssignment (JSAccessor (moduleNameToJs name) (JSVar (fromJust (optionsBrowserNamespace opts))))
63 (JSApp (JSFunction Nothing [] (JSBlock (moduleBody ++ [JSReturn moduleExports]))) [])
63 (JSApp (JSFunction Nothing [] (JSBlock (moduleBody ++ [JSReturn moduleExports]))) [])
67+ isModuleEmpty = null jsDecls
66 moduleBody = JSStringLiteral "use strict" : jsImports ++ jsDecls
68 moduleBody = JSStringLiteral "use strict" : jsImports ++ jsDecls
67 moduleExports = JSObjectLiteral $ concatMap exportToJs exps
69 moduleExports = JSObjectLiteral $ concatMap exportToJs exps
68 jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)
70 jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)