@@ -67,11 +67,11 @@ import System.FilePath (pathSeparator)
6767--
6868-- * Pretty-print the generated Javascript
6969--
70−compile :: Options -> [Module] -> Either String (String, String, Environment)
70+compile :: Options -> [Module] -> [String] -> Either String (String, String, Environment)
7171compile = compile' initEnvironment
7272
73−compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
74−compile' env opts ms = do
73+compile' :: Environment -> Options -> [Module] -> [String] -> Either String (String, String, Environment)
74+compile' env opts ms prefix = do
7575 (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
7676 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
7777 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
@@ -84,7 +84,8 @@ compile' env opts ms = do
8484 let js = evalSupply nextVar $ concat <$> mapM (\m -> moduleToJs Globals opts m env') modulesToCodeGen
8585 let exts = intercalate "\n" . map (`moduleToPs` env') $ modulesToCodeGen
8686 js' <- generateMain env' opts js
87− return (prettyPrintJS js', exts, env')
87+ let pjs = unlines $ map ("// " ++) prefix ++ [prettyPrintJS js']
88+ return (pjs, exts, env')
8889 where
8990 mainModuleIdent = moduleNameFromString <$> optionsMain opts
9091
@@ -169,8 +170,8 @@ class MonadMake m where
169170-- If timestamps have not changed, the externs file can be used to provide the module's types without
170171-- having to typecheck the module again.
171172--
172−make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> m Environment
173−make outputDir opts ms = do
173+make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options -> [(FilePath, Module)] -> [String] -> m Environment
174+make outputDir opts ms prefix = do
174175 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
175176
176177 (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
217218 let mod' = Module moduleName' regrouped exps
218219 let [renamed] = renameInModules [mod']
219220
220− js <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
221− let exts = moduleToPs renamed env'
221+ pjs <- prettyPrintJS <$> moduleToJs CommonJS opts renamed env'
222+ let js = unlines $ map ("// " ++) prefix ++ [pjs]
223+ let exts = unlines $ map ("-- " ++ ) prefix ++ [moduleToPs renamed env']
222224
223225 lift $ writeTextFile jsFile js
224226 lift $ writeTextFile externsFile exts