git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1611 from phadej/refactors

Apply few automatic refactorings

commit7ce4667fc24ce5c72336bd497b4a79b406a81064 authorPhil Freeman <paf31@cantab.net> dateSat 7 Nov 2015, 07:14 (11 years ago) parent648591fb70991f
7 files changed+22−31
psc-bundle/Main.hs+13−14 psc-docs/Ctags.hs+1−1 psc-docs/Etags.hs+1−3 psc-publish/tests/Test.hs+2−2 psci/Completion.hs+2−6 psci/PSCi.hs+3−4 tests/Main.hs−1
psc-bundle/Main.hs+13−14
@@ -12,7 +12,6 @@
1212--
1313-----------------------------------------------------------------------------
1414
15−{-# LANGUAGE PatternGuards #-}
1615{-# LANGUAGE FlexibleContexts #-}
1716{-# LANGUAGE ScopedTypeVariables #-}
1817{-# LANGUAGE TupleSections #-}
@@ -53,16 +52,16 @@ data Options = Options
5352
5453-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
5554guessModuleIdentifier :: (Applicative m, MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
56−guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> (guessModuleType (takeFileName filename))
55+guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> guessModuleType (takeFileName filename)
5756 where
5857 guessModuleType "index.js" = pure Regular
59− guessModuleType "foreign.js" = pure Foreign
58+ guessModuleType "foreign.js" = pure Foreign
6059 guessModuleType name = throwError $ UnsupportedModulePath name
6160
6261-- | The main application function.
6362-- This function parses the input files, performs dead code elimination, filters empty modules
6463-- and generates and prints the final Javascript bundle.
65−app :: forall m. (Applicative m, MonadError ErrorMessage m, MonadIO m) => Options -> m String
64+app :: (Applicative m, MonadError ErrorMessage m, MonadIO m) => Options -> m String
6665app Options{..} = do
6766 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
6867 when (null inputFiles) . liftIO $ do
@@ -72,11 +71,11 @@ app Options{..} = do
7271 js <- liftIO (readFile filename)
7372 mid <- guessModuleIdentifier filename
7473 return (mid, js)
75−
76− let entryIds = (map (`ModuleIdentifier` Regular) optionsEntryPoints)
74+
75+ let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
7776
7877 bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
79−
78+
8079-- | Command line options parser.
8180options :: Parser Options
8281options = Options <$> some inputFile
@@ -85,29 +84,29 @@ options = Options <$> some inputFile
8584 <*> optional mainModule
8685 <*> namespace
8786 <*> optional requirePath
88− where
87+ where
8988 inputFile :: Parser FilePath
9089 inputFile = strArgument $
9190 metavar "FILE"
9291 <> help "The input .js file(s)"
93−
92+
9493 outputFile :: Parser FilePath
9594 outputFile = strOption $
9695 short 'o'
9796 <> long "output"
9897 <> help "The output .js file"
99−
98+
10099 entryPoint :: Parser String
101100 entryPoint = strOption $
102101 short 'm'
103102 <> long "module"
104103 <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
105−
104+
106105 mainModule :: Parser String
107106 mainModule = strOption $
108107 long "main"
109108 <> help "Generate code to run the main method in the specified module."
110−
109+
111110 namespace :: Parser String
112111 namespace = strOption $
113112 short 'n'
@@ -122,8 +121,8 @@ options = Options <$> some inputFile
122121 <> long "require-path"
123122 <> Opts.value ""
124123 <> help "The path prefix used in require() calls in the generated JavaScript"
125−
126−-- | Make it go.
124+
125+-- | Make it go.
127126main :: IO ()
128127main = do
129128 opts <- execParser (info (version <*> helper <*> options) infoModList)
psc-docs/Ctags.hs+1−1
@@ -5,7 +5,7 @@ import Tags
55import Data.List (sort)
66
77dumpCtags :: [(String, P.Module)] -> [String]
8−dumpCtags = sort . concat . (map renderModCtags)
8+dumpCtags = sort . concatMap renderModCtags
99
1010renderModCtags :: (String, P.Module) -> [String]
1111renderModCtags (path, mdl) = sort tagLines
psc-docs/Etags.hs+1−3
@@ -4,12 +4,10 @@ import qualified Language.PureScript as P
44import Tags
55
66dumpEtags :: [(String, P.Module)] -> [String]
7−dumpEtags = concat . (map renderModEtags)
7+dumpEtags = concatMap renderModEtags
88
99renderModEtags :: (String, P.Module) -> [String]
1010renderModEtags (path, mdl) = ["\x0c", path ++ "," ++ show tagsLen] ++ tagLines
1111 where tagsLen = sum $ map length tagLines
1212 tagLines = map tagLine $ tags mdl
1313 tagLine (name, line) = "\x7f" ++ name ++ "\x01" ++ show line ++ ","
14−
15−
psc-publish/tests/Test.hs+2−2
@@ -46,8 +46,8 @@ clonePackage = do
4646 readProcess "git" ["tag", "v999.0.0"] "" >>= putStr
4747
4848bowerInstall :: IO ()
49−bowerInstall = do
50− pushd packageDir $ do
49+bowerInstall =
50+ pushd packageDir $
5151 readProcess "bower" ["install"] "" >>= putStr
5252
5353getPackage :: IO UploadedPackage
psci/Completion.hs+2−6
@@ -172,12 +172,8 @@ getAllQualifications sho m (declName, decl) = do
172172 let q = qualifyWith asQ'
173173 in case importType of
174174 P.Implicit -> [q]
175− P.Explicit refs -> if referencedBy refs
176− then [q]
177− else []
178− P.Hiding refs -> if referencedBy refs
179− then []
180− else [q]
175+ P.Explicit refs -> [q | referencedBy refs]
176+ P.Hiding refs -> [q | not $ referencedBy refs]
181177
182178
183179-- | Returns all the ImportedModule values referring to imports of a particular
psci/PSCi.hs+3−4
@@ -29,7 +29,6 @@ import Data.Tuple (swap)
2929import Data.Version (showVersion)
3030import qualified Data.Map as M
3131
32−import Control.Applicative
3332import Control.Arrow (first)
3433import Control.Monad
3534import Control.Monad.Error.Class (MonadError(..))
@@ -253,7 +252,7 @@ modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
253252-- | This is different than the runMake in 'Language.PureScript.Make' in that it specifies the
254253-- options and ignores the warning messages.
255254runMake :: P.Make a -> IO (Either P.MultipleErrors a)
256−runMake mk = fmap fst $ P.runMake P.defaultOptions mk
255+runMake mk = fst <$> P.runMake P.defaultOptions mk
257256
258257makeIO :: (IOError -> P.ErrorMessage) -> IO a -> P.Make a
259258makeIO f io = do
@@ -441,8 +440,8 @@ getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
441440 case firstLine of
442441 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
443442 Just "" -> return (Right Nothing)
444− Just s | singleLineMode || head s == ':' -> return . either Left (Right . Just) $ parseCommand s
445− Just s -> either Left (Right . Just) . parseCommand <$> go [s]
443+ Just s | singleLineMode || head s == ':' -> return .fmap Just $ parseCommand s
444+ Just s -> fmap Just . parseCommand <$> go [s]
446445 where
447446 go :: [String] -> InputT (StateT PSCiState IO) String
448447 go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
tests/Main.hs−1
@@ -14,7 +14,6 @@
1414{-# LANGUAGE DataKinds #-}
1515{-# LANGUAGE DoAndIfThenElse #-}
1616{-# LANGUAGE TupleSections #-}
17−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1817{-# LANGUAGE FlexibleInstances #-}
1918
2019-- Failing tests can specify the kind of error that should be thrown with a