aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Loader.purs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Loader.purs')
-rw-r--r--src/Loader.purs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/Loader.purs b/src/Loader.purs
index 523aa7a..aae51c0 100644
--- a/src/Loader.purs
+++ b/src/Loader.purs
@@ -9,9 +9,11 @@ import Control.Monad.Eff (Eff())
9import Control.Monad.Eff.Class (liftEff) 9import Control.Monad.Eff.Class (liftEff)
10import Control.Monad.Eff.Exception (error) 10import Control.Monad.Eff.Exception (error)
11 11
12import Data.Array ((!!), catMaybes, concat, nub, null) 12import Data.Array ((!!), catMaybes, concat, filter, null)
13import Data.Foldable (foldl)
13import Data.Function (Fn2(), mkFn2) 14import Data.Function (Fn2(), mkFn2)
14import Data.Maybe (Maybe(..), fromMaybe, maybe) 15import Data.Maybe (Maybe(..), fromMaybe, maybe)
16import Data.Set (Set(), empty, insert, member, toList, unions)
15import Data.String (joinWith, split) 17import Data.String (joinWith, split)
16import Data.String.Regex (Regex(), match, noFlags, regex) 18import Data.String.Regex (Regex(), match, noFlags, regex)
17import Data.StrMap (StrMap(), fromList, lookup) 19import Data.StrMap (StrMap(), fromList, lookup)
@@ -60,11 +62,16 @@ mkGraph files = (fromList <<< catMaybes) <$> sequence (parse <$> files)
60 return $ (\a -> tuple2 a { file: file, imports: imports }) <$> key 62 return $ (\a -> tuple2 a { file: file, imports: imports }) <$> key
61 63
62mkDeps :: forall eff. String -> Graph -> [String] 64mkDeps :: forall eff. String -> Graph -> [String]
63mkDeps key graph = nub $ go [] key 65mkDeps key graph = toList $ go empty key
64 where go acc key = 66 where
65 maybe acc (\a -> if null a.imports 67 go :: Set String -> String -> Set String
66 then acc 68 go acc key =
67 else concat $ go (acc <> a.imports) <$> a.imports) (lookup key graph) 69 let node = fromMaybe {file: "", imports: []} (lookup key graph)
70 uniq = filter (not <<< flip member acc) node.imports
71 acc' = foldl (flip insert) acc node.imports
72 in if null uniq
73 then acc'
74 else unions $ go acc' <$> uniq
68 75
69addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit 76addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit
70addDeps ref graph deps = const unit <$> (sequence $ add <$> deps) 77addDeps ref graph deps = const unit <$> (sequence $ add <$> deps)