hjsmin 0.0.5 → 0.0.6
raw patch · 4 files changed
+32/−37 lines, 4 filesdep ~language-javascriptPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: language-javascript
API changes (from Hackage documentation)
Files
- TODO.txt +6/−0
- Text/Jasmine/Pretty.hs +14/−26
- hjsmin.cabal +2/−2
- runtests.hs +10/−9
TODO.txt view
@@ -80,6 +80,12 @@ 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
Text/Jasmine/Pretty.hs view
@@ -50,7 +50,7 @@ renderJS (JSExpression xs) = rJS xs renderJS (JSSourceElements xs) = rJS (map fixBlock $ fixSourceElements xs) renderJS (JSSourceElementsTop xs)= rJS (fixTop $ map fixBlock $ fixSourceElements xs)-renderJS (JSElement _s xs) = rJS $ fixLiterals xs+--renderJS (JSElement _s xs) = rJS $ fixLiterals xs renderJS (JSFunction s p xs) = (text "function") <+> (renderJS s) <> (text "(") <> (commaList p) <> (text ")") <> (renderJS xs) renderJS (JSFunctionBody xs) = (text "{") <> (rJS xs) <> (text "}") renderJS (JSFunctionExpression as s) = (text "function") <> (text "(") <> (commaList as) <> (text ")") <> (renderJS s)@@ -91,7 +91,7 @@ renderJS (JSContinue is) = (text "continue") <> (rJS is) -- <> (char ';') renderJS (JSDefault xs) = (text "default") <> (char ':') <> (renderJS xs) renderJS (JSDoWhile s e _ms) = (text "do") <> (renderJS s) <> (text "while") <> (char '(') <> (renderJS e) <> (char ')') -- <> (renderJS ms)-renderJS (JSElementList xs) = rJS xs+--renderJS (JSElementList xs) = rJS xs renderJS (JSElision xs) = (char ',') <> (rJS xs) renderJS (JSExpressionBinary o e1 e2) = (rJS e1) <> (text o) <> (rJS e2) --renderJS (JSExpressionBinary o e1 e2) = (text o) <> (rJS e1) <> (rJS e2)@@ -248,16 +248,14 @@ _case0 :: JSNode _case0 = JSSourceElements [- JSExpression [JSElement "assignmentExpression" [JSIdentifier "x",JSOperator "=",JSDecimal "1"]],+ JSExpression [JSIdentifier "x",JSOperator "=",JSDecimal "1"], JSEmpty (JSLiteral ";") ] -- doParse statementList "a=1;" _case1 :: [JSNode] _case1 = [JSExpression - [JSElement "assignmentExpression" - [JSIdentifier "a",JSOperator "=",JSDecimal "1"]- ]+ [JSIdentifier "a",JSOperator "=",JSDecimal "1"] ,JSEmpty (JSLiteral ";") ] @@ -266,8 +264,6 @@ _case4 :: JSNode _case4 = JSExpression [- JSElement "assignmentExpression" - [ JSIdentifier "opTypeNames", JSOperator "=", JSObjectLiteral @@ -275,7 +271,6 @@ JSPropertyNameandValue (JSStringLiteral '\'' ";") [JSStringLiteral '"' "SEMICOLON"], JSPropertyNameandValue (JSStringLiteral '\'' ",") [JSStringLiteral '"' "COMMA"] ]- ] ] @@ -293,7 +288,7 @@ JSExpressionBinary "!=" [JSStringLiteral '"' "string"] []]) (JSReturn [JSExpression [JSIdentifier "s"],JSLiteral ";"]) ,JSLiteral ";"- ,JSExpression [JSElement "assignmentExpression" [JSIdentifier "a",JSOperator "=",JSDecimal "1"]]+ ,JSExpression [JSIdentifier "a",JSOperator "=",JSDecimal "1"] ] ] )@@ -388,7 +383,7 @@ _case13 :: JSNode _case13 = JSSourceElements [- JSFor [JSExpression [JSElement "assignmentExpression" [JSIdentifier "i",JSOperator "=",JSDecimal "0"]]] + JSFor [JSExpression [JSIdentifier "i",JSOperator "=",JSDecimal "0"]] [] [] (JSBlock (@@ -400,7 +395,7 @@ [] [] (JSBlock (- JSStatementList [JSExpression [JSElement "assignmentExpression" [JSIdentifier "x",JSOperator "=",JSDecimal "1"]]]+ JSStatementList [JSExpression [JSIdentifier "x",JSOperator "=",JSDecimal "1"]] ) ) ] @@ -423,7 +418,7 @@ _case16 :: JSNode _case16 = JSSourceElementsTop [- JSFor [JSExpression [JSElement "assignmentExpression" [JSIdentifier "i",JSOperator "=",JSDecimal "0"]]] [] [] + JSFor [JSExpression [JSIdentifier "i",JSOperator "=",JSDecimal "0"]] [] [] (JSBlock (JSStatementList [@@ -433,7 +428,7 @@ ] ) ),- JSExpression [JSElement "assignmentExpression" [JSIdentifier "x",JSOperator "=",JSDecimal "1"]],+ JSExpression [JSIdentifier "x",JSOperator "=",JSDecimal "1"], JSLiteral ";" ] @@ -450,10 +445,7 @@ (JSReturn [JSLiteral ";"]), JSWhile (JSExpression [JSUnary "--",JSIdentifier "n",JSExpressionBinary ">=" [JSDecimal "0"] []]) (JSExpression - [- JSElement "assignmentExpression" - [JSIdentifier "s",JSOperator "+=",JSIdentifier "t"]- ]+ [JSIdentifier "s",JSOperator "+=",JSIdentifier "t"] ), JSLiteral ";" ] @@ -469,10 +461,8 @@ [ JSReturn [JSExpression [JSIdentifier "n"],JSLiteral ";"], JSExpression - [JSElement "assignmentExpression" - [+ [ JSIdentifier "x",JSOperator "=",JSDecimal "1"- ] ] ] ]@@ -484,7 +474,7 @@ _case20 = [ JSReturn [JSExpression [JSIdentifier "n"],JSLiteral ";"], JSExpression - [JSElement "assignmentExpression" [JSIdentifier "x",JSOperator "=",JSDecimal "1"]]+ [JSIdentifier "x",JSOperator "=",JSDecimal "1"] ] --doParse program "if(!u)continue;t=n"@@ -493,7 +483,7 @@ [ JSIf (JSExpression [JSUnary "!",JSIdentifier "u"]) (JSContinue [JSLiteral ";"]),- JSExpression [JSElement "assignmentExpression" [JSIdentifier "t",JSOperator "=",JSIdentifier "n"]]+ JSExpression [JSIdentifier "t",JSOperator "=",JSIdentifier "n"] ] --doParse program "if (!v.base){throw new ReferenceError(v.propertyName + \" is not defined\");};x=1"@@ -537,15 +527,13 @@ _case24 = JSSourceElementsTop [ JSExpression - [- JSElement "assignmentExpression" [JSIdentifier "x", JSOperator "=", JSStringLiteral '"' "hello ", JSExpressionBinary "+" [JSStringLiteral '"' "world"] [] ]- ],+ , JSLiteral ";" ]
hjsmin.cabal view
@@ -1,5 +1,5 @@ name: hjsmin-version: 0.0.5+version: 0.0.6 license: BSD3 license-file: LICENSE author: Alan Zimmerman <alan.zimm@gmail.com>@@ -30,7 +30,7 @@ , blaze-builder >= 0.2 && < 1 , text >= 0.8 && < 1 , containers >= 0.2 && < 0.5- , language-javascript >= 0.0 && < 0.5+ , language-javascript >= 0.1 && < 0.5 exposed-modules: Text.Jasmine other-modules: Text.Jasmine.Parse, Text.Jasmine.Pretty, Text.Jasmine.Token ghc-options: -Wall
runtests.hs view
@@ -122,7 +122,7 @@ srcHelloWorld2 = "function Hello(a) {b=1}" caseHelloWorld2 = - "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Hello\") [JSIdentifier \"a\"] (JSFunctionBody [JSSourceElements [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]]]])])"+ "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Hello\") [JSIdentifier \"a\"] (JSFunctionBody [JSSourceElements [JSExpression [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]]])])" @=? (show $ parseProgram srcHelloWorld2) caseMinHelloWorld2 = -- "function Hello(a){b=1}" @=? (minify (U.fromString srcHelloWorld2))@@ -130,18 +130,18 @@ srcSimpleAssignment = "a=1;" caseSimpleAssignment = - "Right (JSSourceElementsTop [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"a\",JSOperator \"=\",JSDecimal \"1\"]],JSLiteral \";\"])"+ "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"a\",JSOperator \"=\",JSDecimal \"1\"],JSLiteral \";\"])" @=? (show $ parseProgram srcSimpleAssignment) caseMinSimpleAssignment = testMinify "a=1" srcSimpleAssignment srcEmptyFor = "for (i = 0;;){}" caseEmptyFor =- "Right (JSSourceElementsTop [JSFor [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]]] [] [] (JSLiteral \";\")])"+ "Right (JSSourceElementsTop [JSFor [JSExpression [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]] [] [] (JSLiteral \";\")])" @=? (show $ parseProgram srcEmptyFor) srcFullFor = "for (i = 0;i<10;i++){}" caseFullFor =- "Right (JSSourceElementsTop [JSFor [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]]] [JSExpression [JSExpressionBinary \"<\" [JSIdentifier \"i\"] [JSDecimal \"10\"]]] [JSExpression [JSExpressionPostfix \"++\" [JSIdentifier \"i\"]]] (JSLiteral \";\")])"+ "Right (JSSourceElementsTop [JSFor [JSExpression [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]] [JSExpression [JSExpressionBinary \"<\" [JSIdentifier \"i\"] [JSDecimal \"10\"]]] [JSExpression [JSExpressionPostfix \"++\" [JSIdentifier \"i\"]]] (JSLiteral \";\")])" @=? (show $ parseProgram srcFullFor) srcForVarFull = "for(var i=0,j=tokens.length;i<j;i++){}"@@ -151,7 +151,7 @@ srcIfElse1 = "if(a){b=1}else c=2"; caseIfElse1 =- "Right (JSSourceElementsTop [JSIfElse (JSExpression [JSIdentifier \"a\"]) (JSBlock (JSStatementList [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]]])) (JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"c\",JSOperator \"=\",JSDecimal \"2\"]])])"+ "Right (JSSourceElementsTop [JSIfElse (JSExpression [JSIdentifier \"a\"]) (JSBlock (JSStatementList [JSExpression [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]])) (JSExpression [JSIdentifier \"c\",JSOperator \"=\",JSDecimal \"2\"])])" -- @=? (show $ parseString program srcIfElse1) @=? (show $ parseProgram srcIfElse1) caseMinIfElse1 =@@ -159,7 +159,7 @@ srcIfElse2 = "if(a){b=1}else {c=2;d=4}"; caseIfElse2 =- "Right (JSSourceElementsTop [JSIfElse (JSExpression [JSIdentifier \"a\"]) (JSBlock (JSStatementList [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]]])) (JSBlock (JSStatementList [JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"c\",JSOperator \"=\",JSDecimal \"2\"]],JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"d\",JSOperator \"=\",JSDecimal \"4\"]]]))])"+ "Right (JSSourceElementsTop [JSIfElse (JSExpression [JSIdentifier \"a\"]) (JSBlock (JSStatementList [JSExpression [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]])) (JSBlock (JSStatementList [JSExpression [JSIdentifier \"c\",JSOperator \"=\",JSDecimal \"2\"],JSLiteral \";\",JSExpression [JSIdentifier \"d\",JSOperator \"=\",JSDecimal \"4\"]]))])" -- @=? (show $ parseString program srcIfElse2) @=? (show $ parseProgram srcIfElse2) caseMinIfElse2 =@@ -189,7 +189,7 @@ src_min_100_animals = "function Animal(name){if(!name)throw new Error('Must specify an animal name');this.name=name};Animal.prototype.toString=function(){return this.name};o=new Animal(\"bob\");o.toString()==\"bob\"" case_min_100_animals =- "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Animal\") [JSIdentifier \"name\"] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSUnary \"!\",JSIdentifier \"name\"]) (JSBlock (JSStatementList [JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"Error\",JSArguments [[JSStringLiteral '\\'' \"Must specify an animal name\"]]])])),JSExpression [JSElement \"assignmentExpression\" [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\"),JSOperator \"=\",JSIdentifier \"name\"]]]]),JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSMemberDot [JSMemberDot [JSIdentifier \"Animal\"] (JSIdentifier \"prototype\")] (JSIdentifier \"toString\"),JSOperator \"=\",JSFunctionExpression [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\")],JSLiteral \"\"]]])]],JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"o\",JSOperator \"=\",JSLiteral \"new \",JSIdentifier \"Animal\",JSArguments [[JSStringLiteral '\"' \"bob\"]]]],JSLiteral \";\",JSExpression [JSExpressionBinary \"==\" [JSMemberDot [JSIdentifier \"o\"] (JSIdentifier \"toString\"),JSArguments []] [JSStringLiteral '\"' \"bob\"]]])"+ "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Animal\") [JSIdentifier \"name\"] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSUnary \"!\",JSIdentifier \"name\"]) (JSBlock (JSStatementList [JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"Error\",JSArguments [[JSStringLiteral '\\'' \"Must specify an animal name\"]]])])),JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\"),JSOperator \"=\",JSIdentifier \"name\"]]]),JSLiteral \";\",JSExpression [JSMemberDot [JSMemberDot [JSIdentifier \"Animal\"] (JSIdentifier \"prototype\")] (JSIdentifier \"toString\"),JSOperator \"=\",JSFunctionExpression [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\")],JSLiteral \"\"]]])],JSLiteral \";\",JSExpression [JSIdentifier \"o\",JSOperator \"=\",JSLiteral \"new \",JSIdentifier \"Animal\",JSArguments [[JSStringLiteral '\"' \"bob\"]]],JSLiteral \";\",JSExpression [JSExpressionBinary \"==\" [JSMemberDot [JSIdentifier \"o\"] (JSIdentifier \"toString\"),JSArguments []] [JSStringLiteral '\"' \"bob\"]]])" -- "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Animal\") [JSIdentifier \"name\"] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSUnary \"!\",JSIdentifier \"name\"]) (JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"Error\",JSArguments [[JSStringLiteral '\\'' \"Must specify an animal name\"]]])),JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\"),JSOperator \"=\",JSIdentifier \"name\"]]]]),JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSMemberDot [JSMemberDot [JSIdentifier \"Animal\"] (JSIdentifier \"prototype\")] (JSIdentifier \"toString\"),JSOperator \"=\",JSFunctionExpression [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\")],JSLiteral \"\"]]])]],JSLiteral \";\",JSExpression [JSElement \"assignmentExpression\" [JSIdentifier \"o\",JSOperator \"=\",JSLiteral \"new \",JSIdentifier \"Animal\",JSArguments [[JSStringLiteral '\"' \"bob\"]]]],JSLiteral \";\",JSExpression [JSExpressionBinary \"==\" [JSMemberDot [JSIdentifier \"o\"] (JSIdentifier \"toString\"),JSArguments []] [JSStringLiteral '\"' \"bob\"]]])" @=? (show $ parseProgram src_min_100_animals) caseMin_min_100_animals =@@ -204,13 +204,14 @@ srcNestedSquare = "this.cursor+=match[0].length;" caseNestedSquare =- "Right (JSSourceElementsTop [JSExpression [JSElement \"assignmentExpression\" [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"cursor\"),JSOperator \"+=\",JSMemberDot [JSMemberSquare [JSIdentifier \"match\"] (JSExpression [JSDecimal \"0\"])] (JSIdentifier \"length\")]],JSLiteral \";\"])"+ "Right (JSSourceElementsTop [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"cursor\"),JSOperator \"+=\",JSMemberDot [JSMemberSquare [JSIdentifier \"match\"] (JSExpression [JSDecimal \"0\"])] (JSIdentifier \"length\")],JSLiteral \";\"])" @=? (show $ parseProgram srcNestedSquare) caseMinNestedSquare = testMinify "this.cursor+=match[0].length" srcNestedSquare caseEitherLeft = - Left "UnexpectedToken (MulToken {token_span = SpanPoint {span_filename = \"src\", span_row = 1, span_column = 3}})"+ Left "UnexpectedToken (MulToken {token_span = (AlexPn 2 1 3,'=',\"*SYNTAX*ERROR*\")})"+ -- Left "UnexpectedToken (MulToken {token_span = SpanPoint {span_filename = \"src\", span_row = 1, span_column = 3}})" @=? minifym (LB.fromChunks [(E.encodeUtf8 $ T.pack "a=*SYNTAX*ERROR*")]) caseEitherRight =