Skip to content

Commit aa8a269

Browse files
committed
Disable prelude auto-import with --no-prelude
1 parent 4f76abf commit aa8a269

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

psc-make/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ browserNamespace = value $ opt "PS" $ (optInfo [ "browser-namespace" ])
116116
{ optDoc = "Specify the namespace that PureScript modules will be exported to when running in the browser." }
117117

118118
options :: Term P.Options
119-
options = P.Options <$> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> browserNamespace <*> pure [] <*> pure []
119+
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> browserNamespace <*> pure [] <*> pure []
120120

121121
inputFilesAndPrelude :: FilePath -> Term [FilePath]
122122
inputFilesAndPrelude prelude = combine <$> (not <$> noPrelude) <*> inputFiles

psc/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ codeGenModules = value $ optAll [] $ (optInfo [ "codegen" ])
123123
{ optDoc = "A list of modules for which Javascript and externs should be generated. This argument can be used multiple times." }
124124

125125
options :: Term P.Options
126-
options = P.Options <$> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules <*> codeGenModules
126+
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules <*> codeGenModules
127127

128128
stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
129129
stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles

psci/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ completion = completeWord Nothing " \t\n\r" findCompletions
194194
-- | Compilation options.
195195
--
196196
options :: P.Options
197-
options = P.Options True False True (Just "Main") True "PS" [] []
197+
options = P.Options False True False True (Just "Main") True "PS" [] []
198198

199199
-- |
200200
-- Makes a volatile module to execute the current expression.

src/Language/PureScript.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ compile = compile' initEnvironment
6969

7070
compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
7171
compile' env opts ms = do
72-
(sorted, _) <- sortModules (map importPrelude ms)
72+
(sorted, _) <- sortModules $ if optionsNoPrelude opts then ms else (map importPrelude ms)
7373
desugared <- desugar sorted
7474
(elaborated, env') <- runCheck' env $ forM desugared $ typeCheckModule mainModuleIdent
7575
regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
@@ -164,7 +164,7 @@ make :: (Functor m, Monad m, MonadMake m) => Options -> [(FilePath, Module)] ->
164164
make opts ms = do
165165
let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
166166

167-
(sorted, graph) <- liftError $ sortModules (map (importPrelude . snd) ms)
167+
(sorted, graph) <- liftError $ sortModules $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
168168

169169
toRebuild <- foldM (\s (Module moduleName' _ _) -> do
170170
let filePath = toFileName moduleName'

src/Language/PureScript/Options.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ module Language.PureScript.Options where
1919
-- The data type of compiler options
2020
--
2121
data Options = Options {
22+
-- |
23+
-- Disable inclusion of the built in Prelude
24+
--
25+
optionsNoPrelude :: Bool
2226
-- |
2327
-- Disable tail-call elimination
2428
--
25-
optionsNoTco :: Bool
29+
, optionsNoTco :: Bool
2630
-- |
2731
-- Perform type checks at runtime
2832
--
@@ -59,4 +63,4 @@ data Options = Options {
5963
-- Default compiler options
6064
--
6165
defaultOptions :: Options
62-
defaultOptions = Options False False False Nothing False "PS" [] []
66+
defaultOptions = Options False False False False Nothing False "PS" [] []

0 commit comments

Comments
 (0)