diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Loader.purs | 19 |
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()) | |||
9 | import Control.Monad.Eff.Class (liftEff) | 9 | import Control.Monad.Eff.Class (liftEff) |
10 | import Control.Monad.Eff.Exception (error) | 10 | import Control.Monad.Eff.Exception (error) |
11 | 11 | ||
12 | import Data.Array ((!!), catMaybes, concat, nub, null) | 12 | import Data.Array ((!!), catMaybes, concat, filter, null) |
13 | import Data.Foldable (foldl) | ||
13 | import Data.Function (Fn2(), mkFn2) | 14 | import Data.Function (Fn2(), mkFn2) |
14 | import Data.Maybe (Maybe(..), fromMaybe, maybe) | 15 | import Data.Maybe (Maybe(..), fromMaybe, maybe) |
16 | import Data.Set (Set(), empty, insert, member, toList, unions) | ||
15 | import Data.String (joinWith, split) | 17 | import Data.String (joinWith, split) |
16 | import Data.String.Regex (Regex(), match, noFlags, regex) | 18 | import Data.String.Regex (Regex(), match, noFlags, regex) |
17 | import Data.StrMap (StrMap(), fromList, lookup) | 19 | import 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 | ||
62 | mkDeps :: forall eff. String -> Graph -> [String] | 64 | mkDeps :: forall eff. String -> Graph -> [String] |
63 | mkDeps key graph = nub $ go [] key | 65 | mkDeps 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 | ||
69 | addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit | 76 | addDeps :: forall eff. LoaderRef -> Graph -> [String] -> Eff (loader :: Loader | eff) Unit |
70 | addDeps ref graph deps = const unit <$> (sequence $ add <$> deps) | 77 | addDeps ref graph deps = const unit <$> (sequence $ add <$> deps) |