git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Apply few automatic refactorings
b70991fOleg Grenrus
psc-bundle/Main.hs+13−14
@@ -12,7 +12,6 @@
12--
12--
13-----------------------------------------------------------------------------
13-----------------------------------------------------------------------------
14
14
15−{-# LANGUAGE PatternGuards #-}
16{-# LANGUAGE FlexibleContexts #-}
15{-# LANGUAGE FlexibleContexts #-}
17{-# LANGUAGE ScopedTypeVariables #-}
16{-# LANGUAGE ScopedTypeVariables #-}
18{-# LANGUAGE TupleSections #-}
17{-# LANGUAGE TupleSections #-}
@@ -53,16 +52,16 @@ data Options = Options
53
52
54-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
53-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
55guessModuleIdentifier :: (Applicative m, MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
54guessModuleIdentifier :: (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)
57 where
56 where
58 guessModuleType "index.js" = pure Regular
57 guessModuleType "index.js" = pure Regular
59− guessModuleType "foreign.js" = pure Foreign
58+ guessModuleType "foreign.js" = pure Foreign
60 guessModuleType name = throwError $ UnsupportedModulePath name
59 guessModuleType name = throwError $ UnsupportedModulePath name
61
60
62-- | The main application function.
61-- | The main application function.
63-- This function parses the input files, performs dead code elimination, filters empty modules
62-- This function parses the input files, performs dead code elimination, filters empty modules
64-- and generates and prints the final Javascript bundle.
63-- 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
66app Options{..} = do
65app Options{..} = do
67 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
66 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
68 when (null inputFiles) . liftIO $ do
67 when (null inputFiles) . liftIO $ do
@@ -72,11 +71,11 @@ app Options{..} = do
72 js <- liftIO (readFile filename)
71 js <- liftIO (readFile filename)
73 mid <- guessModuleIdentifier filename
72 mid <- guessModuleIdentifier filename
74 return (mid, js)
73 return (mid, js)
75−
74+
76− let entryIds = (map (`ModuleIdentifier` Regular) optionsEntryPoints)
75+ let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
77
76
78 bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
77 bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
79−
78+
80-- | Command line options parser.
79-- | Command line options parser.
81options :: Parser Options
80options :: Parser Options
82options = Options <$> some inputFile
81options = Options <$> some inputFile
@@ -85,29 +84,29 @@ options = Options <$> some inputFile
85 <*> optional mainModule
84 <*> optional mainModule
86 <*> namespace
85 <*> namespace
87 <*> optional requirePath
86 <*> optional requirePath
88− where
87+ where
89 inputFile :: Parser FilePath
88 inputFile :: Parser FilePath
90 inputFile = strArgument $
89 inputFile = strArgument $
91 metavar "FILE"
90 metavar "FILE"
92 <> help "The input .js file(s)"
91 <> help "The input .js file(s)"
93−
92+
94 outputFile :: Parser FilePath
93 outputFile :: Parser FilePath
95 outputFile = strOption $
94 outputFile = strOption $
96 short 'o'
95 short 'o'
97 <> long "output"
96 <> long "output"
98 <> help "The output .js file"
97 <> help "The output .js file"
99−
98+
100 entryPoint :: Parser String
99 entryPoint :: Parser String
101 entryPoint = strOption $
100 entryPoint = strOption $
102 short 'm'
101 short 'm'
103 <> long "module"
102 <> long "module"
104 <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
103 <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
105−
104+
106 mainModule :: Parser String
105 mainModule :: Parser String
107 mainModule = strOption $
106 mainModule = strOption $
108 long "main"
107 long "main"
109 <> help "Generate code to run the main method in the specified module."
108 <> help "Generate code to run the main method in the specified module."
110−
109+
111 namespace :: Parser String
110 namespace :: Parser String
112 namespace = strOption $
111 namespace = strOption $
113 short 'n'
112 short 'n'
@@ -122,8 +121,8 @@ options = Options <$> some inputFile
122 <> long "require-path"
121 <> long "require-path"
123 <> Opts.value ""
122 <> Opts.value ""
124 <> help "The path prefix used in require() calls in the generated JavaScript"
123 <> help "The path prefix used in require() calls in the generated JavaScript"
125−
124+
126−-- | Make it go.
125+-- | Make it go.
127main :: IO ()
126main :: IO ()
128main = do
127main = do
129 opts <- execParser (info (version <*> helper <*> options) infoModList)
128 opts <- execParser (info (version <*> helper <*> options) infoModList)
psc-docs/Ctags.hs+1−1
@@ -5,7 +5,7 @@ import Tags
5import Data.List (sort)
5import Data.List (sort)
6
6
7dumpCtags :: [(String, P.Module)] -> [String]
7dumpCtags :: [(String, P.Module)] -> [String]
8−dumpCtags = sort . concat . (map renderModCtags)
8+dumpCtags = sort . concatMap renderModCtags
9
9
10renderModCtags :: (String, P.Module) -> [String]
10renderModCtags :: (String, P.Module) -> [String]
11renderModCtags (path, mdl) = sort tagLines
11renderModCtags (path, mdl) = sort tagLines
psc-docs/Etags.hs+1−3
@@ -4,12 +4,10 @@ import qualified Language.PureScript as P
4import Tags
4import Tags
5
5
6dumpEtags :: [(String, P.Module)] -> [String]
6dumpEtags :: [(String, P.Module)] -> [String]
7−dumpEtags = concat . (map renderModEtags)
7+dumpEtags = concatMap renderModEtags
8
8
9renderModEtags :: (String, P.Module) -> [String]
9renderModEtags :: (String, P.Module) -> [String]
10renderModEtags (path, mdl) = ["\x0c", path ++ "," ++ show tagsLen] ++ tagLines
10renderModEtags (path, mdl) = ["\x0c", path ++ "," ++ show tagsLen] ++ tagLines
11 where tagsLen = sum $ map length tagLines
11 where tagsLen = sum $ map length tagLines
12 tagLines = map tagLine $ tags mdl
12 tagLines = map tagLine $ tags mdl
13 tagLine (name, line) = "\x7f" ++ name ++ "\x01" ++ show line ++ ","
13 tagLine (name, line) = "\x7f" ++ name ++ "\x01" ++ show line ++ ","
14−
15−
psc-publish/tests/Test.hs+2−2
@@ -46,8 +46,8 @@ clonePackage = do
46 readProcess "git" ["tag", "v999.0.0"] "" >>= putStr
46 readProcess "git" ["tag", "v999.0.0"] "" >>= putStr
47
47
48bowerInstall :: IO ()
48bowerInstall :: IO ()
49−bowerInstall = do
49+bowerInstall =
50− pushd packageDir $ do
50+ pushd packageDir $
51 readProcess "bower" ["install"] "" >>= putStr
51 readProcess "bower" ["install"] "" >>= putStr
52
52
53getPackage :: IO UploadedPackage
53getPackage :: IO UploadedPackage
psci/Completion.hs+2−6
@@ -172,12 +172,8 @@ getAllQualifications sho m (declName, decl) = do
172 let q = qualifyWith asQ'
172 let q = qualifyWith asQ'
173 in case importType of
173 in case importType of
174 P.Implicit -> [q]
174 P.Implicit -> [q]
175− P.Explicit refs -> if referencedBy refs
175+ P.Explicit refs -> [q | referencedBy refs]
176− then [q]
176+ P.Hiding refs -> [q | not $ referencedBy refs]
177− else []
178− P.Hiding refs -> if referencedBy refs
179− then []
180− else [q]
181
177
182
178
183-- | Returns all the ImportedModule values referring to imports of a particular
179-- | Returns all the ImportedModule values referring to imports of a particular
psci/PSCi.hs+3−4
@@ -29,7 +29,6 @@ import Data.Tuple (swap)
29import Data.Version (showVersion)
29import Data.Version (showVersion)
30import qualified Data.Map as M
30import qualified Data.Map as M
31
31
32−import Control.Applicative
33import Control.Arrow (first)
32import Control.Arrow (first)
34import Control.Monad
33import Control.Monad
35import Control.Monad.Error.Class (MonadError(..))
34import Control.Monad.Error.Class (MonadError(..))
@@ -253,7 +252,7 @@ modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
253-- | This is different than the runMake in 'Language.PureScript.Make' in that it specifies the
252-- | This is different than the runMake in 'Language.PureScript.Make' in that it specifies the
254-- options and ignores the warning messages.
253-- options and ignores the warning messages.
255runMake :: P.Make a -> IO (Either P.MultipleErrors a)
254runMake :: 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
257
256
258makeIO :: (IOError -> P.ErrorMessage) -> IO a -> P.Make a
257makeIO :: (IOError -> P.ErrorMessage) -> IO a -> P.Make a
259makeIO f io = do
258makeIO f io = do
@@ -441,8 +440,8 @@ getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
441 case firstLine of
440 case firstLine of
442 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
441 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
443 Just "" -> return (Right Nothing)
442 Just "" -> return (Right Nothing)
444− Just s | singleLineMode || head s == ':' -> return . either Left (Right . Just) $ parseCommand s
443+ Just s | singleLineMode || head s == ':' -> return .fmap Just $ parseCommand s
445− Just s -> either Left (Right . Just) . parseCommand <$> go [s]
444+ Just s -> fmap Just . parseCommand <$> go [s]
446 where
445 where
447 go :: [String] -> InputT (StateT PSCiState IO) String
446 go :: [String] -> InputT (StateT PSCiState IO) String
448 go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
447 go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
tests/Main.hs−1
@@ -14,7 +14,6 @@
14{-# LANGUAGE DataKinds #-}
14{-# LANGUAGE DataKinds #-}
15{-# LANGUAGE DoAndIfThenElse #-}
15{-# LANGUAGE DoAndIfThenElse #-}
16{-# LANGUAGE TupleSections #-}
16{-# LANGUAGE TupleSections #-}
17−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
18{-# LANGUAGE FlexibleInstances #-}
17{-# LANGUAGE FlexibleInstances #-}
19
18
20-- Failing tests can specify the kind of error that should be thrown with a
19-- Failing tests can specify the kind of error that should be thrown with a