git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
validate imports correctly
206bb51Bogdan Popa
psci/Main.hs+13−9
@@ -233,14 +233,6 @@ instance P.MonadMake Make where
233mkdirp :: FilePath -> IO ()
233mkdirp :: FilePath -> IO ()
234mkdirp = createDirectoryIfMissing True . takeDirectory
234mkdirp = createDirectoryIfMissing True . takeDirectory
235
235
236−-- |
237−-- Just an empty module.
238−--
239−emptyModule :: P.Module
240−emptyModule =
241− let moduleName = P.ModuleName [P.ProperName "$PSCI"]
242− in P.Module moduleName [] Nothing
243−
244-- |
236-- |
245-- Makes a volatile module to execute the current expression.
237-- Makes a volatile module to execute the current expression.
246--
238--
@@ -271,6 +263,17 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
271 in
263 in
272 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
264 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
273
265
266+-- |
267+-- Makes a volatile module to execute the current imports.
268+--
269+createTemporaryModuleForImports :: PSCiState -> P.Module
270+createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
271+ let
272+ moduleName = P.ModuleName [P.ProperName "$PSCI"]
273+ importDecl m = P.ImportDeclaration m P.Unqualified Nothing
274+ in
275+ P.Module moduleName (importDecl `map` imports) Nothing
276+
274modulesDir :: FilePath
277modulesDir :: FilePath
275modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
278modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
276
279
@@ -302,7 +305,8 @@ handleDeclaration value = do
302handleImport :: P.ModuleName -> PSCI ()
305handleImport :: P.ModuleName -> PSCI ()
303handleImport moduleName = do
306handleImport moduleName = do
304 s <- liftM (updateImports moduleName) $ PSCI $ lift get
307 s <- liftM (updateImports moduleName) $ PSCI $ lift get
308+ let m = createTemporaryModuleForImports s
305− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", emptyModule)]) []
309+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", m)]) []
306 case e of
310 case e of
307 Left err -> PSCI $ outputStrLn err
311 Left err -> PSCI $ outputStrLn err
308 Right _ -> do
312 Right _ -> do