@@ -67,11 +67,11 @@ import System.FilePath (pathSeparator)
68-- * Pretty-print the generated Javascript
68-- * Pretty-print the generated Javascript
70−compile :: Options -> [Module] -> Either String (String, String, Environment)
70+compile :: Options -> [Module] -> [String] -> Either String (String, String, Environment)
71compile = compile' initEnvironment
71compile = compile' initEnvironment
73−compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
73+compile' :: Environment -> Options -> [Module] -> [String] -> Either String (String, String, Environment)
74−compile' env opts ms = do
74+compile' env opts ms prefix = do
75 (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
75 (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
76 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
76 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
77 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
77 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
@@ -84,7 +84,8 @@ compile' env opts ms = do
84 let js = evalSupply nextVar $ concat <$> mapM (\m -> moduleToJs Globals opts m env') modulesToCodeGen
84 let js = evalSupply nextVar $ concat <$> mapM (\m -> moduleToJs Globals opts m env') modulesToCodeGen
85 let exts = intercalate "\n" . map (`moduleToPs` env') $ modulesToCodeGen
85 let exts = intercalate "\n" . map (`moduleToPs` env') $ modulesToCodeGen
86 js' <- generateMain env' opts js
86 js' <- generateMain env' opts js
87− return (prettyPrintJS js', exts, env')
87+ let pjs = unlines $ map ("// " ++) prefix ++ [prettyPrintJS js']
88+ return (pjs, exts, env')
89 mainModuleIdent = moduleNameFromString <$> optionsMain opts
90 mainModuleIdent = moduleNameFromString <$> optionsMain opts
@@ -169,8 +170,8 @@ class MonadMake m where
169-- If timestamps have not changed, the externs file can be used to provide the module's types without
170-- If timestamps have not changed, the externs file can be used to provide the module's types without
170-- having to typecheck the module again.
171-- having to typecheck the module again.
172−make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> m Environment
173+make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> [String] -> m Environment
173−make outputDir opts ms = do
174+make outputDir opts ms prefix = do
174 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
175 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
176 (sorted, graph) <- liftError $ sortModules $ map importPrim $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
177 (sorted, graph) <- liftError $ sortModules $ map importPrim $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
@@ -217,8 +218,9 @@ make outputDir opts ms = do
217 let mod' = Module moduleName' regrouped exps
218 let mod' = Module moduleName' regrouped exps
218 let [renamed] = renameInModules [mod']
219 let [renamed] = renameInModules [mod']
220− js <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
221+ pjs <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
222+ let js = unlines $ map ("// " ++) prefix ++ [pjs]
221− let exts = moduleToPs renamed env'
223+ let exts = unlines $ map ("-- " ++ ) prefix ++ [moduleToPs renamed env']
223 lift $ writeTextFile jsFile js
225 lift $ writeTextFile jsFile js
224 lift $ writeTextFile externsFile exts
226 lift $ writeTextFile externsFile exts