Skip to content

Commit d87bf07

Browse files
committed
Merge pull request purescript#1358 from purescript/1246
Fix purescript#1246
2 parents 396aa3b + f144aab commit d87bf07

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

psc/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$>
8484
parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
8585
=> [(Either P.RebuildPolicy FilePath, String)]
8686
-> [(FilePath, P.ForeignJS)]
87-
-> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName (FilePath, P.ForeignJS))
87+
-> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
8888
parseInputs modules foreigns =
8989
(,) <$> P.parseModulesFromFiles (either (const "") id) modules
9090
<*> P.parseForeignModulesFromFiles foreigns

psci/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data PSCiState = PSCiState
3535
{ psciImportedFilenames :: [FilePath]
3636
, psciImportedModules :: [ImportedModule]
3737
, psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
38-
, psciForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS)
38+
, psciForeignFiles :: M.Map P.ModuleName FilePath
3939
, psciLetBindings :: [P.Declaration]
4040
, psciNodeFlags :: [String]
4141
}
@@ -91,7 +91,7 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
9191
-- |
9292
-- Updates the state to have more let bindings.
9393
--
94-
updateForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> PSCiState -> PSCiState
94+
updateForeignFiles :: M.Map P.ModuleName FilePath -> PSCiState -> PSCiState
9595
updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `M.union` fs }
9696

9797
-- |

src/Language/PureScript/Make.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import System.Directory
5959
import System.FilePath ((</>), takeDirectory)
6060
import System.IO.Error (tryIOError)
6161

62-
6362
import Language.PureScript.AST
6463
import Language.PureScript.CodeGen.Externs (moduleToPs)
6564
import Language.PureScript.Environment
@@ -245,8 +244,8 @@ traverseEither f (Right y) = Right <$> f y
245244
-- A set of make actions that read and write modules from the given directory.
246245
--
247246
buildMakeActions :: FilePath -- ^ the output directory
248-
-> M.Map ModuleName (Either RebuildPolicy String) -- ^ a map between module names and paths to the file containing the PureScript module
249-
-> M.Map ModuleName (FilePath, ForeignJS) -- ^ a map between module name and the file containing the foreign javascript for the module
247+
-> M.Map ModuleName (Either RebuildPolicy FilePath) -- ^ a map between module names and paths to the file containing the PureScript module
248+
-> M.Map ModuleName FilePath -- ^ a map between module name and the file containing the foreign javascript for the module
250249
-> Bool -- ^ Generate a prefix comment?
251250
-> MakeActions Make
252251
buildMakeActions outputDir filePathMap foreigns usePrefix =
@@ -257,7 +256,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
257256
getInputTimestamp mn = do
258257
let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
259258
e1 <- traverseEither getTimestamp path
260-
fPath <- maybe (return Nothing) (getTimestamp . fst) $ M.lookup mn foreigns
259+
fPath <- maybe (return Nothing) getTimestamp $ M.lookup mn foreigns
261260
return $ fmap (max fPath) e1
262261

263262
getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
@@ -276,7 +275,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
276275
codegen m _ exts = do
277276
let mn = CF.moduleName m
278277
foreignInclude <- case mn `M.lookup` foreigns of
279-
Just (path, _)
278+
Just path
280279
| not $ requiresForeign m -> do
281280
tell $ errorMessage $ UnnecessaryFFIModule mn path
282281
return Nothing
@@ -292,7 +291,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
292291
js = unlines $ map ("// " ++) prefix ++ [pjs]
293292
lift $ do
294293
writeTextFile jsFile js
295-
maybe (return ()) (writeTextFile foreignFile . snd) $ mn `M.lookup` foreigns
294+
for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
296295
writeTextFile externsFile exts
297296

298297
requiresForeign :: CF.Module a -> Bool

src/Language/PureScript/Parser/JS.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ type ForeignJS = String
3737

3838
parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
3939
=> [(FilePath, ForeignJS)]
40-
-> m (M.Map ModuleName (FilePath, ForeignJS))
40+
-> m (M.Map ModuleName FilePath)
4141
parseForeignModulesFromFiles files = do
4242
foreigns <- parU files $ \(path, file) ->
4343
case findModuleName (lines file) of
44-
Just name -> return (name, (path, file))
44+
Just name -> return (name, path)
4545
Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
4646
let grouped = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) foreigns
4747
forM_ grouped $ \grp ->
4848
when (length grp > 1) $ do
4949
let mn = fst (head grp)
50-
paths = map (fst . snd) grp
50+
paths = map snd grp
5151
tell $ errorMessage $ MultipleFFIModules mn paths
5252
return $ M.fromList foreigns
5353

tests/Main.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import Text.Parsec (ParseError)
6969
modulesDir :: FilePath
7070
modulesDir = ".test_modules" </> "node_modules"
7171

72-
makeActions :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> P.MakeActions P.Make
72+
makeActions :: M.Map P.ModuleName FilePath -> P.MakeActions P.Make
7373
makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input file map was read.") foreigns False)
7474
{ P.getInputTimestamp = getInputTimestamp
7575
, P.getOutputTimestamp = getOutputTimestamp
@@ -98,14 +98,14 @@ type TestM = WriterT [(FilePath, String)] IO
9898
runTest :: P.Make a -> IO (Either P.MultipleErrors a)
9999
runTest = fmap (fmap fst) . P.runMake P.defaultOptions
100100

101-
compile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> IO (Either P.MultipleErrors P.Environment)
101+
compile :: [FilePath] -> M.Map P.ModuleName FilePath -> IO (Either P.MultipleErrors P.Environment)
102102
compile inputFiles foreigns = runTest $ do
103103
fs <- liftIO $ readInput inputFiles
104104
ms <- P.parseModulesFromFiles id fs
105105
P.make (makeActions foreigns) (map snd ms)
106106

107107
assert :: [FilePath] ->
108-
M.Map P.ModuleName (FilePath, P.ForeignJS) ->
108+
M.Map P.ModuleName FilePath ->
109109
(Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
110110
TestM ()
111111
assert inputFiles foreigns f = do
@@ -115,7 +115,7 @@ assert inputFiles foreigns f = do
115115
Just err -> tell [(last inputFiles, err)]
116116
Nothing -> return ()
117117

118-
assertCompiles :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
118+
assertCompiles :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
119119
assertCompiles inputFiles foreigns = do
120120
liftIO . putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
121121
assert inputFiles foreigns $ \e ->
@@ -131,7 +131,7 @@ assertCompiles inputFiles foreigns = do
131131
Just (ExitFailure _, _, err) -> return $ Just err
132132
Nothing -> return $ Just "Couldn't find node.js executable"
133133

134-
assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
134+
assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
135135
assertDoesNotCompile inputFiles foreigns = do
136136
let testFile = last inputFiles
137137
liftIO . putStrLn $ "Assert " ++ testFile ++ " does not compile"

0 commit comments

Comments
 (0)