hjsmin-0.2.0.2/0000755000000000000000000000000012755711632011340 5ustar0000000000000000hjsmin-0.2.0.2/Setup.hs0000644000000000000000000000005612755711632012775 0ustar0000000000000000import Distribution.Simple main = defaultMain hjsmin-0.2.0.2/hjsmin.hs0000644000000000000000000000257512755711632013175 0ustar0000000000000000{-# LANGUAGE CPP #-} module Main where #include "cabal_macros.h" import Data.Monoid ((<>)) import Options.Applicative import Text.Jasmine import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy.Char8 as C8 data Options = Options { inputFile :: String , outputFile :: Maybe String } main :: IO () main = execParser opts >>= minify' where opts = info (helper <*> options) ( fullDesc <> progDesc ( "Minify JavaScript files (using language-javascript version " ++ languageJavascriptVersion ++ ")." ) <> header "hjsmin - a simple command-line interface to the 'hjsmin' library" ) options :: Parser Options options = Options <$> argument str (metavar "INPUT_FILE" <> help "The unminified, original JavaScript file") <*> optional ( strOption (long "output-file" <> short 'o' <> metavar "OUTPUT_FILE" <> help "The minified output file. Default: stdout") ) minify' :: Options -> IO () minify' o = do minified <- minifyFile (inputFile o) case outputFile o of Nothing -> C8.putStrLn minified Just f -> B.writeFile f minified languageJavascriptVersion :: String languageJavascriptVersion = VERSION_language_javascript hjsmin-0.2.0.2/hjsmin.cabal0000644000000000000000000000310212755711632013610 0ustar0000000000000000name: hjsmin version: 0.2.0.2 license: BSD3 license-file: LICENSE author: Alan Zimmerman maintainer: Erik de Castro Lopo synopsis: Haskell implementation of a javascript minifier description: Reduces size of javascript files by stripping out extraneous whitespace and other syntactic elements, without changing the semantics. category: Web stability: unstable cabal-version: >= 1.9.2 build-type: Simple homepage: http://github.com/erikd/hjsmin bug-reports: http://github.com/erikd/hjsmin/issues Extra-source-files: TODO.txt , Readme.md library build-depends: base >= 4.5 , bytestring >= 0.9 , blaze-builder >= 0.2 , text >= 0.8 , containers >= 0.2 , language-javascript >= 0.6 && < 0.7 exposed-modules: Text.Jasmine other-modules: Text.Jasmine.Pretty ghc-options: -Wall executable hjsmin main-is: hjsmin.hs ghc-options: -Wall -threaded build-depends: base >= 4 && < 5 , bytestring >= 0.9 , blaze-builder >= 0.2 , text >= 0.8 , containers >= 0.2 , language-javascript >= 0.6 , optparse-applicative >= 0.7 source-repository head type: git location: https://github.com/erikd/hjsmin.git hjsmin-0.2.0.2/TODO.txt0000644000000000000000000000425112755711632012650 0ustar0000000000000000Testing: The following Lint has a strict parser http://www.javascriptlint.com/online_lint.php This one does not http://www.jslint.com/ --- Language reference https://developer.mozilla.org/en/JavaScript/Reference http://msdn.microsoft.com/en-us/library/ttyab5c8.aspx --- Look at http://dean.edwards.name/download/#packer http://code.google.com/p/minify/ Examples of parsers JSon parser in Parsec http://snippets.dzone.com/posts/show/3660 GOLD Parser, using the Javascript.grm from http://www.devincook.com/GOLDParser/grammars/index.htm http://oss.org.cn/ossdocs/web/js/js20/formal/parser-grammar.html ------------------------- - Generate output using standard pretty print library, so it can be used with various backends - Sort out semicolon insertion, as per http://oss.org.cn/ossdocs/web/js/js20/rationale/syntax.html Also: http://inimino.org/~inimino/blog/javascript_semicolons Grammatical Semicolon Insertion Semicolons before a closing } and the end of the program are optional in both JavaScript 1.5 and 2.0. In addition, the JavaScript 2.0 parser allows semicolons to be omitted before the else of an if-else statement and before the while of a do-while statement. Line-Break Semicolon Insertion If the first through the nth tokens of a JavaScript program form are grammatically valid but the first through the n+1st tokens are not and there is a line break between the nth tokens and the n+1st tokens, then the parser tries to parse the program again after inserting a VirtualSemicolon token between the nth and the n+1st tokens. - remove un-needed semicolons in pretty printer - put in tests for all cases of elementList -- Look at "in" keyword, as used : if (x in list) {} ------------ Integrating language-haskell. ----------------------------- Baseline before starting, on my laptop (intel Core2 Duo SU7300) $ time ./dist/build/runtests/runtests real 0m1.625s user 0m1.616s sys 0m0.016s Baseline 2010-12-20, after getting all tests to pass at last real 0m0.209s user 0m0.196s sys 0m0.004s After working in unicode, in language-javascript-0.0.3 [2010-12-28] real 0m0.236s user 0m0.224s sys 0m0.012s EOF hjsmin-0.2.0.2/LICENSE0000644000000000000000000000276512755711632012357 0ustar0000000000000000Copyright (c)2010, Alan Zimmerman All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Alan Zimmerman nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. hjsmin-0.2.0.2/Readme.md0000644000000000000000000000171512755711632013063 0ustar0000000000000000hjsmin ====== [![Build Status](https://secure.travis-ci.org/erikd/hjsmin.png?branch=master)](http://travis-ci.org/erikd/hjsmin) Haskell implementation of a command line javascript minifier. The executable generated from this package simply does command line parsing before handing the off the minification process to the [language-javascript] package which also does the rendering. How to build ------------ cabal clean && cabal configure && cabal build Tests ----- There are currently no tests, because all the heavy lifting is done by [language-javascript]. Reporting Bugs -------------- Bugs like failing to parse certain chunks of Javascript or errors in the minification process should be reported on the [language-javascript] issue tracker. Bugs about failure to handle command line paramters should be reported on the [hjsmin] issue tracker. [hjsmin]: https://github.com/erikd/hjsmin [language-javascript]: https://github.com/erikd/language-javascript hjsmin-0.2.0.2/Text/0000755000000000000000000000000012755711632012264 5ustar0000000000000000hjsmin-0.2.0.2/Text/Jasmine.hs0000644000000000000000000000244012755711632014206 0ustar0000000000000000module Text.Jasmine ( minify , minifym , minifyBb , minifyFile ) where import Control.Applicative ((<$>)) import Data.Text.Lazy (unpack) import Data.Text.Lazy.Encoding (decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import Language.JavaScript.Parser (readJs, parse, JSAST) import Language.JavaScript.Pretty.Printer import Language.JavaScript.Process.Minify import qualified Blaze.ByteString.Builder as BB import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Char8 as S8 minifym :: LB.ByteString -> Either String LB.ByteString minifym s = case myParse s of Left msg -> Left (show msg) Right p -> Right $ BB.toLazyByteString $ renderJS $ minifyJS p minifyBb :: LB.ByteString -> Either String BB.Builder minifyBb s = case myParse s of Left msg -> Left (show msg) Right p -> Right (renderJS $ minifyJS p) minify :: LB.ByteString -> LB.ByteString minify s = BB.toLazyByteString . renderJS . minifyJS . readJs $ lbToStr s minifyFile :: FilePath -> IO LB.ByteString minifyFile filename = minify <$> LB.readFile filename myParse :: S8.ByteString -> Either String JSAST myParse input = parse (lbToStr input) "src" lbToStr :: S8.ByteString -> String lbToStr = unpack . decodeUtf8With lenientDecode hjsmin-0.2.0.2/Text/Jasmine/0000755000000000000000000000000012755711632013652 5ustar0000000000000000hjsmin-0.2.0.2/Text/Jasmine/Pretty.hs0000644000000000000000000000015412755711632015475 0ustar0000000000000000module Text.Jasmine.Pretty ( renderJS ) where import Language.JavaScript.Pretty.Printer (renderJS)