zephyr 0.2.0 → 0.2.1
raw patch · 5 files changed
+40/−3 lines, 5 files
Files
- README.md +6/−0
- app/Command/DCE.hs +21/−1
- app/Command/DCEOptions.hs +1/−0
- test/Main.hs +11/−1
- zephyr.cabal +1/−1
README.md view
@@ -17,6 +17,12 @@ webpack ``` +or you can bundle with `pulp`:++```+pulp browserify --skip-compile -o dce-output -t app.js+```+ You can also specify modules as entry points, which is the same as specifying all exported identifiers.
app/Command/DCE.hs view
@@ -113,6 +113,14 @@ <> " The default target is 'js', but if this option is used only the targets specified will be used." ) +dceNoEvalOpt :: Opts.Parser Bool+dceNoEvalOpt = Opts.flag True False $+ Opts.short 'e'+ <> Opts.long "no-eval"+ <> Opts.showDefault+ <> Opts.internal+ <> Opts.help "do not evaluate"+ targets :: M.Map String P.CodegenTarget targets = M.fromList [ ("js", P.JS)@@ -164,6 +172,7 @@ <*> pureScriptOptions <*> (not <$> noPrefix) <*> jsonErrors+ <*> dceNoEvalOpt readInput :: [FilePath] -> IO [Either (FilePath, JSONPath, String) (Version, CoreFn.Module CoreFn.Ann)] readInput inputFiles = forM inputFiles (\f -> addPath f . decodeCoreFn <$> BSL.readFile f)@@ -289,7 +298,9 @@ -- run `dceEval` and `dce` on the `CoreFn` (mods, warns) <- mapExceptT (fmap $ first CompilationError) $ runWriterT- $ dceEval (snd `map` rights inpts) >>= return . flip dce entryPoints+ $ if dceNoEval+ then return $ dce (snd `map` rights inpts) entryPoints+ else dceEval (snd `map` rights inpts) >>= return . flip dce entryPoints relPath <- liftIO getCurrentDirectory liftIO $ traverse_ (hPutStrLn stderr . uncurry (displayDCEWarning relPath)) (zip (zip [1..] (repeat (length warns))) warns) let filePathMap = M.fromList $ map (\m -> (CoreFn.moduleName m, Right $ CoreFn.modulePath m)) mods@@ -299,6 +310,15 @@ liftIO $ P.runMake dcePureScriptOptions $ runSupplyT 0 $ traverse (\m -> P.codegen makeActions m P.initEnvironment mempty) mods++ -- copy externs files+ -- we do not have access to data to regenerate extern files (they relay on+ -- more information than is present in `CoreFn.Module`).+ _ <- for mods $ \m -> lift $ do+ let mn = P.runModuleName $ CoreFn.moduleName m+ exts <- BSL.readFile (dceInputDir </> T.unpack mn </> "externs.json")+ BSL.writeFile (dceOutputDir </> T.unpack mn </> "externs.json") exts+ when dceForeign $ forM_ mods $ \(CoreFn.Module{moduleName,moduleForeign}) -> liftIO $ case moduleName `M.lookup` foreigns of
app/Command/DCEOptions.hs view
@@ -14,4 +14,5 @@ , dcePureScriptOptions :: P.Options , dceUsePrefix :: Bool , dceJsonErrors :: Bool+ , dceNoEval :: Bool }
test/Main.hs view
@@ -16,6 +16,7 @@ import Data.Maybe (fromJust, fromMaybe, isJust, maybe) import Data.Text (Text) import qualified Data.Text as T+import Data.Semigroup ((<>)) import System.Directory ( createDirectoryIfMissing , doesDirectoryExist@@ -148,6 +149,15 @@ , LibTest ["Eval.evalUnderObjectLiteral"] Nothing "require('./dce-output/Eval').evalUnderObjectLiteral;" True , LibTest ["Eval.evalVars"] Nothing "require('./dce-output/Eval').evalVars;" True , LibTest ["Eval"] Nothing "require('./dce-output/Eval').evalVars;" True+ , LibTest ["Eval.recordUpdate"] Nothing+ ( " var eval = require('./dce-output/Eval');\n"+ <> " var foo = eval.recordUpdate({foo: '', bar: 0})(eval.Foo.create('foo')).foo;\n"+ <> " if (foo != 'foo') {\n"+ <> " console.error(foo)\n"+ <> " throw('Error: ' + foo)\n"+ <> " }\n"+ )+ True ] data KarmaTest = KarmaTest@@ -411,6 +421,6 @@ TestDCECoreFn.main TestDCEEval.main - hspec $ changeDir "test/tests" libSpec+ hspec $ changeDir "test/lib-tests" libSpec -- hspec $ changeDir ".temp" coreLibSpec -- hspec karmaSpec
zephyr.cabal view
@@ -1,5 +1,5 @@ name: zephyr-version: 0.2.0+version: 0.2.1 synopsis: Zephyr tree shaking for PureScript Language description: