hjsmin 0.0.15 → 0.0.16
raw patch · 4 files changed
+166/−145 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.markdown +3/−1
- Text/Jasmine/Pretty.hs +39/−39
- hjsmin.cabal +3/−3
- runtests.hs +121/−102
README.markdown view
@@ -28,7 +28,9 @@ Changes ------- -0.0.15 - Fix GHC 7.4.1 compile compatibility. Patch accepted from github.com/luite+0.0.16 - Fix bug for issue 7, blowing up when calculating if space needed after return++0.0.15 - Fix ambiguous symbols with GHC 7.4.1, from @luite 0.0.14 - Allow unicode characters in comments
Text/Jasmine/Pretty.hs view
@@ -1,5 +1,5 @@ module Text.Jasmine.Pretty- ( + ( renderJS ) where @@ -66,15 +66,15 @@ rn (JSBlock x) = (text "{") <> (renderJS x) <> (text "}") -rn (JSIf c (NS (JSLiteral ";") _))= (text "if") <> (text "(") <> (renderJS c) <> (text ")") +rn (JSIf c (NS (JSLiteral ";") _))= (text "if") <> (text "(") <> (renderJS c) <> (text ")") rn (JSIf c t) = (text "if") <> (text "(") <> (renderJS c) <> (text ")") <> (renderJS $ fixBlock t) -rn (JSIfElse c t (NS (JSLiteral ";") _)) = (text "if") <> (text "(") <> (renderJS c) <> (text ")") <> (renderJS t) - <> (text "else") -rn (JSIfElse c t e) = (text "if") <> (text "(") <> (renderJS c) <> (text ")") <> (renderJS t) +rn (JSIfElse c t (NS (JSLiteral ";") _)) = (text "if") <> (text "(") <> (renderJS c) <> (text ")") <> (renderJS t)+ <> (text "else")+rn (JSIfElse c t e) = (text "if") <> (text "(") <> (renderJS c) <> (text ")") <> (renderJS t) <> (text "else") <> (spaceOrBlock $ fixBlock e) rn (JSMemberDot xs y) = (rJS xs) <> (text ".") <> (renderJS y)-rn (JSMemberSquare xs x) = (rJS xs) <> (text "[") <> (renderJS x) <> (text "]") +rn (JSMemberSquare xs x) = (rJS xs) <> (text "[") <> (renderJS x) <> (text "]") rn (JSLiteral l) = (text l) rn (JSStringLiteral s l) = empty <> (char s) <> (text l) <> (char s) rn (JSUnary l ) = text l@@ -88,13 +88,13 @@ rn (JSCallExpression t xs) = (char $ head t) <> (rJS xs) <> (if ((length t) > 1) then (char $ last t) else empty) -- No space between 'case' and string literal. TODO: what about expression in parentheses?---rn (JSCase (JSExpression [JSStringLiteral sepa s]) xs) = (text "case") <> (renderJS (JSStringLiteral sepa s)) -rn (JSCase (NS (JSExpression [(NS (JSStringLiteral sepa s) s1)]) _) xs) = (text "case") <> (renderJS (NS (JSStringLiteral sepa s) s1)) - <> (char ':') <> (renderJS xs) -rn (JSCase e xs) = (text "case") <+> (renderJS e) <> (char ':') <> (renderJS xs) -- <> (text ";"); +--rn (JSCase (JSExpression [JSStringLiteral sepa s]) xs) = (text "case") <> (renderJS (JSStringLiteral sepa s))+rn (JSCase (NS (JSExpression [(NS (JSStringLiteral sepa s) s1)]) _) xs) = (text "case") <> (renderJS (NS (JSStringLiteral sepa s) s1))+ <> (char ':') <> (renderJS xs)+rn (JSCase e xs) = (text "case") <+> (renderJS e) <> (char ':') <> (renderJS xs) -- <> (text ";"); rn (JSCatch i [] s) = (text "catch") <> (char '(') <> (renderJS i) <> (char ')') <> (renderJS s)-rn (JSCatch i c s) = (text "catch") <> (char '(') <> (renderJS i) <> +rn (JSCatch i c s) = (text "catch") <> (char '(') <> (renderJS i) <> (text " if ") <> (rJS c) <> (char ')') <> (renderJS s) rn (JSContinue is) = (text "continue") <> (rJS is) -- <> (char ';')@@ -109,16 +109,16 @@ rn (JSExpressionTernary c v1 v2) = (rJS c) <> (char '?') <> (rJS v1) <> (char ':') <> (rJS v2) rn (JSFinally b) = (text "finally") <> (renderJS b) -rn (JSFor e1 e2 e3 s) = (text "for") <> (char '(') <> (commaList e1) <> (char ';') +rn (JSFor e1 e2 e3 s) = (text "for") <> (char '(') <> (commaList e1) <> (char ';') <> (rJS e2) <> (char ';') <> (rJS e3) <> (char ')') <> (renderJS $ fixBlock s) rn (JSForIn e1 e2 s) = (text "for") <> (char '(') <> (rJS e1) <+> (text "in") <+> (renderJS e2) <> (char ')') <> (renderJS $ fixBlock s)-rn (JSForVar e1 e2 e3 s) = (text "for") <> (char '(') <> (text "var") <+> (commaList e1) <> (char ';') +rn (JSForVar e1 e2 e3 s) = (text "for") <> (char '(') <> (text "var") <+> (commaList e1) <> (char ';') <> (rJS e2) <> (char ';') <> (rJS e3) <> (char ')') <> (renderJS $ fixBlock s)-rn (JSForVarIn e1 e2 s) = (text "for") <> (char '(') <> (text "var") <+> (renderJS e1) <+> (text "in") +rn (JSForVarIn e1 e2 s) = (text "for") <> (char '(') <> (text "var") <+> (renderJS e1) <+> (text "in") <+> (renderJS e2) <> (char ')') <> (renderJS $ fixBlock s)- -rn (JSHexInteger i) = (text $ show i) -- TODO: need to tweak this ++rn (JSHexInteger i) = (text $ show i) -- TODO: need to tweak this rn (JSLabelled l v) = (renderJS l) <> (text ":") <> (rJS $ fixSourceElements [fixBlock v]) rn (JSObjectLiteral xs) = (text "{") <> (commaList xs) <> (text "}") rn (JSPropertyAccessor s n ps b) = (text s) <+> (renderJS n) <> (char '(') <> (rJS ps) <> (text ")") <> (renderJS b)@@ -127,7 +127,7 @@ rn (JSReturn []) = (text "return") rn (JSReturn [(NS (JSLiteral ";") _)]) = (text "return;")-rn (JSReturn xs) = (text "return") <> (if (spaceNeeded xs) then (text " ") else (empty)) <> (rJS $ fixSourceElements xs) +rn (JSReturn xs) = (text "return") <> (if (spaceNeeded xs) then (text " ") else (empty)) <> (rJS $ fixSourceElements xs) rn (JSThrow e) = (text "throw") <+> (renderJS e) @@ -135,11 +135,11 @@ rn (JSStatementList xs) = rJS (fixSourceElements $ map fixBlock xs) -rn (JSSwitch e xs) = (text "switch") <> (char '(') <> (renderJS e) <> (char ')') <> +rn (JSSwitch e xs) = (text "switch") <> (char '(') <> (renderJS e) <> (char ')') <> (char '{') <> (rJS $ fixSemis xs) <> (char '}') rn (JSTry e xs) = (text "try") <> (renderJS e) <> (rJS xs) -rn (JSVarDecl i []) = (renderJS i) +rn (JSVarDecl i []) = (renderJS i) rn (JSVarDecl i xs) = (renderJS i) <> (text "=") <> (rJS xs) rn (JSVariables kw xs) = (text kw) <+> (commaList xs)@@ -148,7 +148,7 @@ rn (JSWhile e s) = (text "while") <> (char '(') <> (renderJS e) <> (char ')') <> (renderJS s) rn (JSWith e s) = (text "with") <> (char '(') <> (renderJS e) <> (char ')') <> (rJS s)- + -- Helper functions rJS :: [JSNode] -> BB.Builder rJS xs = hcat $ map renderJS xs@@ -160,7 +160,7 @@ -- (xs', trail) = if (last xs == JSLiteral ",") then (init xs, [comma]) else (xs,[]) (xs', trail) = if (x' == JSLiteral ",") then (init xs, [comma]) else (xs,[]) (NS x' _) = last xs- + commaListList :: [[JSNode]] -> BB.Builder commaListList xs = (hcat $ punctuate comma $ map rJS xs) @@ -193,7 +193,7 @@ fixSourceElements :: [JSNode] -> [JSNode] fixSourceElements xs = fixSemis $ myFix xs- + myFix :: [JSNode] -> [JSNode] myFix [] = [] @@ -210,19 +210,19 @@ myFix ((NS (JSBlock x) s1) :(NS (JSBlock y) s2):xs) = (NS (JSBlock x) s1) :(NS (JSLiteral ";") s1):myFix ((NS (JSBlock y) s2):xs) myFix ((NS (JSBlock x) s1) :(NS (JSExpression y) s2):xs) = (NS (JSBlock x) s1) :(NS (JSLiteral ";") s1):myFix ((NS (JSExpression y) s2):xs) -myFix ((NS (JSExpression x) s1):(NS (JSStatementBlock y) s2):xs) = +myFix ((NS (JSExpression x) s1):(NS (JSStatementBlock y) s2):xs) = (NS (JSExpression x) s1):(NS (JSLiteral ";") s1):myFix ((NS (JSStatementBlock y) s2):xs)-myFix ((NS (JSStatementBlock x) s1) :(NS (JSStatementBlock y) s2):xs) = +myFix ((NS (JSStatementBlock x) s1) :(NS (JSStatementBlock y) s2):xs) = (NS (JSStatementBlock x) s1) :(NS (JSLiteral ";") s1):myFix ((NS (JSStatementBlock y) s2):xs)-myFix ((NS (JSStatementBlock x) s1) :(NS (JSExpression y) s2):xs) = +myFix ((NS (JSStatementBlock x) s1) :(NS (JSExpression y) s2):xs) = (NS (JSStatementBlock x) s1) :(NS (JSLiteral ";") s1):myFix ((NS (JSExpression y) s2):xs) -- Merge adjacent variable declarations, but only of the same type-myFix ((NS (JSVariables t1 x1s) s1):(NS (JSLiteral l) s2):(NS (JSVariables t2 x2s) s3):xs) +myFix ((NS (JSVariables t1 x1s) s1):(NS (JSLiteral l) s2):(NS (JSVariables t2 x2s) s3):xs) | t1 == t2 = myFix ((NS (JSVariables t1 (x1s++x2s)) s1):xs) | otherwise = (NS (JSVariables t1 x1s) s1):myFix ((NS (JSLiteral l) s2):(NS (JSVariables t2 x2s) s3):xs) -myFix ((NS (JSVariables t1 x1s) s1):(NS (JSVariables t2 x2s) s2):xs) +myFix ((NS (JSVariables t1 x1s) s1):(NS (JSVariables t2 x2s) s2):xs) | t1 == t2 = myFix ((NS (JSVariables t1 (x1s++x2s)) s1):xs) | otherwise = (NS (JSVariables t1 x1s) s1):myFix ((NS (JSVariables t2 x2s) s2):xs) @@ -230,7 +230,7 @@ myFix ((NS (JSLiteral ";") s1):(NS (JSLiteral ";") _s2):xs) = myFix ((NS (JSLiteral ";") s1):xs) myFix ((NS (JSLiteral ";") s1):(NS (JSLiteral "" ) _s2):xs) = myFix ((NS (JSLiteral "") s1):xs) - + myFix (x:xs) = x : myFix xs -- Merge strings split over lines and using "+"@@ -239,11 +239,11 @@ -- Old version fixLiterals ((NS (JSStringLiteral d1 s1) ss1):(NS (JSExpressionBinary "+" [(NS (JSStringLiteral d2 s2) ss2)] r) ss3):xs) | d1 == d2 = fixLiterals ((NS (JSStringLiteral d1 (s1++s2)) ss1):(r++xs))- | otherwise = (NS (JSStringLiteral d1 s1) ss1):fixLiterals ((NS (JSExpressionBinary "+" [(NS (JSStringLiteral d2 s2) ss2)] r) ss3):xs) + | otherwise = (NS (JSStringLiteral d1 s1) ss1):fixLiterals ((NS (JSExpressionBinary "+" [(NS (JSStringLiteral d2 s2) ss2)] r) ss3):xs) fixLiterals ((NS (JSExpressionBinary "+" [(NS (JSStringLiteral d1 s1) ss2)] [(NS (JSStringLiteral d2 s2) ss3)]) ss4):xs) | d1 == d2 = fixLiterals ((NS (JSStringLiteral d1 (s1++s2)) ss2):xs)- | otherwise = (NS (JSExpressionBinary "+" [(NS (JSStringLiteral d1 s1) ss2)] [(NS (JSStringLiteral d2 s2) ss3)]) ss4):fixLiterals xs + | otherwise = (NS (JSExpressionBinary "+" [(NS (JSStringLiteral d1 s1) ss2)] [(NS (JSStringLiteral d2 s2) ss3)]) ss4):fixLiterals xs fixLiterals (x:xs) = x:fixLiterals xs @@ -256,12 +256,12 @@ fixSemis' [] = [] fixSemis' [(NS (JSContinue [(NS (JSLiteral ";") _)]) s2)] = [(NS (JSContinue []) s2)] fixSemis' [x] = [x]-fixSemis' ((NS (JSIf c (NS (JSReturn [(NS (JSLiteral ";") s1)]) s2) ) s3):xs) = +fixSemis' ((NS (JSIf c (NS (JSReturn [(NS (JSLiteral ";") s1)]) s2) ) s3):xs) = (NS (JSIf c (NS (JSReturn [(NS (JSLiteral ";") s1)]) s2)) s3):(fixSemis' xs)-fixSemis' ((NS (JSIf c (NS (JSContinue [(NS (JSLiteral ";") s1)]) s2) ) s3):xs) = +fixSemis' ((NS (JSIf c (NS (JSContinue [(NS (JSLiteral ";") s1)]) s2) ) s3):xs) = (NS (JSIf c (NS (JSContinue [(NS (JSLiteral ";") s1)]) s2)) s3):(fixSemis' xs) fixSemis' (x:(NS (JSLiteral "\n") s1):xs) = x:(NS (JSLiteral "\n") s1):(fixSemis' xs) -- TODO: is this needed?-fixSemis' ((NS (JSCase e1 ((NS (JSStatementList []) s1))) s2):(NS (JSCase e2 x) s3):xs) = +fixSemis' ((NS (JSCase e1 ((NS (JSStatementList []) s1))) s2):(NS (JSCase e2 x) s3):xs) = (NS (JSCase e1 ((NS (JSStatementList []) s1))) s2):fixSemis' ((NS (JSCase e2 x) s3):xs) fixSemis' (x:xs) = x:(NS (JSLiteral ";") SpanEmpty):fixSemis' xs @@ -274,10 +274,10 @@ fixBlock (NS (JSBlock (NS (JSStatementList [x]) _) ) _) = fixBlock x fixBlock (NS (JSStatementBlock (NS (JSStatementList [x]) _) ) _) = fixBlock x -fixBlock (NS (JSBlock (NS (JSStatementList xs) s1) ) s2) = +fixBlock (NS (JSBlock (NS (JSStatementList xs) s1) ) s2) = fixBlock' (NS (JSBlock (NS (JSStatementList (fixSourceElements xs)) s1)) s2) -fixBlock (NS (JSStatementBlock (NS (JSStatementList xs) s1) ) s2) = +fixBlock (NS (JSStatementBlock (NS (JSStatementList xs) s1) ) s2) = fixBlock' (NS (JSStatementBlock (NS (JSStatementList (fixSourceElements xs)) s1)) s2) fixBlock x = x@@ -290,12 +290,12 @@ -- A space is needed if this expression starts with an identifier etc, but not if with a '(' spaceNeeded :: [JSNode] -> Bool-spaceNeeded xs = +spaceNeeded xs = let -- str = show $ rJS xs str = LB.unpack $ BB.toLazyByteString $ rJS xs- in - head str /= (fromIntegral $ ord '(')+ in+ (str /= []) && head str /= (fromIntegral $ ord '(') -- --------------------------------------------------------------------- -- Test stuff@@ -308,7 +308,7 @@ _case0 = NS (JSSourceElementsTop [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList []) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 3})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 2})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 2}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 1})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 1}) _case01 :: [JSNode]-_case01 = [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList []) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 3})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 2})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 2}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 1})] +_case01 = [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList [NS (JSStatementBlock (NS (JSStatementList []) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 3})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 3}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 2})]) (SpanPoint {span_filename = "", span_row = 1, span_column = 2}))) (SpanPoint {span_filename = "", span_row = 1, span_column = 1})] -- readJs "if(x){}{a=2}" _case1 :: JSNode
hjsmin.cabal view
@@ -1,12 +1,12 @@ name: hjsmin-version: 0.0.15+version: 0.0.16 license: BSD3 license-file: LICENSE author: Alan Zimmerman <alan.zimm@gmail.com> maintainer: Alan Zimmerman <alan.zimm@gmail.com> synopsis: Haskell implementation of a javascript minifier description:- Reduces size of javascript files by stripping out extraneous whitespace and + Reduces size of javascript files by stripping out extraneous whitespace and other syntactic elements, without changing the semantics. category: Web stability: unstable@@ -15,7 +15,7 @@ homepage: http://github.com/alanz/hjsmin bug-reports: http://github.com/alanz/hjsmin/issues -Extra-source-files: +Extra-source-files: TODO.txt, README.markdown, buildall.sh
runtests.hs view
@@ -16,17 +16,17 @@ testSuite :: Test testSuite = testGroup "Text.Jasmine.Parse"- [ - testCase "helloWorld" caseHelloWorld - , testCase "helloWorld2" caseHelloWorld2 + [+ testCase "helloWorld" caseHelloWorld+ , testCase "helloWorld2" caseHelloWorld2 , testCase "simpleAssignment" caseSimpleAssignment- , testCase "emptyFor" caseEmptyFor - , testCase "fullFor" caseFullFor - , testCase "forVarFull" caseForVarFull + , testCase "emptyFor" caseEmptyFor+ , testCase "fullFor" caseFullFor+ , testCase "forVarFull" caseForVarFull , testCase "ifelse1" caseIfElse1 , testCase "ifelse2" caseIfElse2 , testCase "0_f.js" case0_f- , testCase "01_semi1.js" case01_semi1 + , testCase "01_semi1.js" case01_semi1 , testCase "min_100_animals" case_min_100_animals , testCase "mergeStrings" caseMergeStrings , testCase "TrailingCommas" caseTrailingCommas@@ -34,111 +34,114 @@ , testCase "Unicode" caseUnicode , testCase "Issue3" caseIssue3 , testCase "Issue4" caseIssue4+ , testCase "Issue7" caseIssue7 ] testSuiteMin :: Test testSuiteMin = testGroup "Text.Jasmine.Pretty"- [ testCase "helloWorld" caseMinHelloWorld - , testCase "helloWorld2" caseMinHelloWorld2 + [ testCase "helloWorld" caseMinHelloWorld+ , testCase "helloWorld2" caseMinHelloWorld2 , testCase "simpleAssignment" caseMinSimpleAssignment , testCase "ifelse1" caseMinIfElse1 , testCase "ifelse2" caseMinIfElse2 , testCase "0_f.js" caseMin0_f- , testCase "01_semi1.js" caseMin01_semi1 + , testCase "01_semi1.js" caseMin01_semi1 , testCase "min_100_animals" caseMin_min_100_animals , testCase "minNestedSquare" caseMinNestedSquare , testCase "minMergeStrings" caseMinMergeStrings- , testCase "EitherLeft" caseEitherLeft - , testCase "EitherRight" caseEitherRight + , testCase "EitherLeft" caseEitherLeft+ , testCase "EitherRight" caseEitherRight , testCase "TrailingCommas" caseMinTrailingCommas , testCase "GetSet" caseMinGetSet , testCase "Unicode" caseMinUnicode , testCase "MinIssue3" caseMinIssue3 , testCase "MinIssue4" caseMinIssue4+ , testCase "MinIssue7" caseMinIssue7 ] testSuiteFiles :: Test testSuiteFiles = testGroup "Text.Jasmine.Pretty files" [ testCase "00_f.js" (testFile "./test/pminified/00_f.js")- , testCase "01_semi1.js" (testFile "./test/pminified/01_semi1.js") - , testCase "02_sm.js" (testFile "./test/pminified/02_sm.js") - , testCase "03_sm.js" (testFile "./test/pminified/03_sm.js") - , testCase "04_if.js" (testFile "./test/pminified/04_if.js") - , testCase "05_comments_simple.js" (testFile "./test/pminified/05_comments_simple.js") - , testCase "05_regex.js" (testFile "./test/pminified/05_regex.js") - , testCase "06_callexpr.js" (testFile "./test/pminified/06_callexpr.js") - , testCase "06_newexpr.js" (testFile "./test/pminified/06_newexpr.js") - , testCase "06_var.js" (testFile "./test/pminified/06_var.js") - , testCase "07_expr.js" (testFile "./test/pminified/07_expr.js") - , testCase "10_switch.js" (testFile "./test/pminified/10_switch.js") - , testCase "14_labelled_stmts.js" (testFile "./test/pminified/14_labelled_stmts.js") - , testCase "15_literals.js" (testFile "./test/pminified/15_literals.js") - , testCase "16_literals.js" (testFile "./test/pminified/16_literals.js") - , testCase "20_statements.js" (testFile "./test/pminified/20_statements.js") - , testCase "25_trycatch.js" (testFile "./test/pminified/25_trycatch.js") - , testCase "40_functions.js" (testFile "./test/pminified/40_functions.js") - , testCase "67_bob.js" (testFile "./test/pminified/67_bob.js") - , testCase "110_perfect.js" (testFile "./test/pminified/110_perfect.js") - , testCase "120_js.js" (testFile "./test/pminified/120_js.js") - , testCase "121_jsdefs.js" (testFile "./test/pminified/121_jsdefs.js") - , testCase "122_jsexec.js" (testFile "./test/pminified/122_jsexec.js") - , testCase "122_jsexec2.js" (testFile "./test/pminified/122_jsexec2.js") - , testCase "122_jsexec3.js" (testFile "./test/pminified/122_jsexec3.js") - -- , testCase "123_jsparse.js" (testFile "./test/pminified/123_jsparse.js") + , testCase "01_semi1.js" (testFile "./test/pminified/01_semi1.js")+ , testCase "02_sm.js" (testFile "./test/pminified/02_sm.js")+ , testCase "03_sm.js" (testFile "./test/pminified/03_sm.js")+ , testCase "04_if.js" (testFile "./test/pminified/04_if.js")+ , testCase "05_comments_simple.js" (testFile "./test/pminified/05_comments_simple.js")+ , testCase "05_regex.js" (testFile "./test/pminified/05_regex.js")+ , testCase "06_callexpr.js" (testFile "./test/pminified/06_callexpr.js")+ , testCase "06_newexpr.js" (testFile "./test/pminified/06_newexpr.js")+ , testCase "06_var.js" (testFile "./test/pminified/06_var.js")+ , testCase "07_expr.js" (testFile "./test/pminified/07_expr.js")+ , testCase "10_switch.js" (testFile "./test/pminified/10_switch.js")+ , testCase "14_labelled_stmts.js" (testFile "./test/pminified/14_labelled_stmts.js")+ , testCase "15_literals.js" (testFile "./test/pminified/15_literals.js")+ , testCase "16_literals.js" (testFile "./test/pminified/16_literals.js")+ , testCase "20_statements.js" (testFile "./test/pminified/20_statements.js")+ , testCase "25_trycatch.js" (testFile "./test/pminified/25_trycatch.js")+ , testCase "40_functions.js" (testFile "./test/pminified/40_functions.js")+ , testCase "67_bob.js" (testFile "./test/pminified/67_bob.js")+ , testCase "110_perfect.js" (testFile "./test/pminified/110_perfect.js")+ , testCase "120_js.js" (testFile "./test/pminified/120_js.js")+ , testCase "121_jsdefs.js" (testFile "./test/pminified/121_jsdefs.js")+ , testCase "122_jsexec.js" (testFile "./test/pminified/122_jsexec.js")+ , testCase "122_jsexec2.js" (testFile "./test/pminified/122_jsexec2.js")+ , testCase "122_jsexec3.js" (testFile "./test/pminified/122_jsexec3.js")+ -- , testCase "123_jsparse.js" (testFile "./test/pminified/123_jsparse.js") -- TODO: something strange here, assigning code block to variable? -- See http://msdn.microsoft.com/en-us/library/77kz8hy0.aspx, get/set keywords for object accessors- - --, testCase "130_htojs2.js" (testFile "./test/parsingonly/130_htojs2.js") - --, testCase "" (testFile "./test/pminified/") - ] + --, testCase "130_htojs2.js" (testFile "./test/parsingonly/130_htojs2.js")+ --, testCase "" (testFile "./test/pminified/")+ ]+ testSuiteFilesUnminified :: Test testSuiteFilesUnminified = testGroup "Text.Jasmine.Pretty filesUnminified" [ testCase "00_f.js" (testFileUnminified "00_f.js")- , testCase "01_semi1.js" (testFileUnminified "01_semi1.js") - , testCase "02_sm.js" (testFileUnminified "02_sm.js") - , testCase "03_sm.js" (testFileUnminified "03_sm.js") - , testCase "04_if.js" (testFileUnminified "04_if.js") - , testCase "05_comments_simple.js" (testFileUnminified "05_comments_simple.js") - , testCase "05_regex.js" (testFileUnminified "05_regex.js") - , testCase "06_callexpr.js" (testFileUnminified "06_callexpr.js") - , testCase "06_newexpr.js" (testFileUnminified "06_newexpr.js") - , testCase "06_var.js" (testFileUnminified "06_var.js") - , testCase "07_expr.js" (testFileUnminified "07_expr.js") - , testCase "10_switch.js" (testFileUnminified "10_switch.js") - , testCase "14_labelled_stmts.js" (testFileUnminified "14_labelled_stmts.js") - , testCase "15_literals.js" (testFileUnminified "15_literals.js") - , testCase "16_literals.js" (testFileUnminified "16_literals.js") - , testCase "20_statements.js" (testFileUnminified "20_statements.js") - , testCase "25_trycatch.js" (testFileUnminified "25_trycatch.js") - , testCase "40_functions.js" (testFileUnminified "40_functions.js") - , testCase "67_bob.js" (testFileUnminified "67_bob.js") - , testCase "110_perfect.js" (testFileUnminified "110_perfect.js") - , testCase "120_js.js" (testFileUnminified "120_js.js") - , testCase "121_jsdefs.js" (testFileUnminified "121_jsdefs.js") - , testCase "122_jsexec.js" (testFileUnminified "122_jsexec.js") - - --, testCase "122_jsexec2.js" (testFileUnminified "122_jsexec2.js") - ] + , testCase "01_semi1.js" (testFileUnminified "01_semi1.js")+ , testCase "02_sm.js" (testFileUnminified "02_sm.js")+ , testCase "03_sm.js" (testFileUnminified "03_sm.js")+ , testCase "04_if.js" (testFileUnminified "04_if.js")+ , testCase "05_comments_simple.js" (testFileUnminified "05_comments_simple.js")+ , testCase "05_regex.js" (testFileUnminified "05_regex.js")+ , testCase "06_callexpr.js" (testFileUnminified "06_callexpr.js")+ , testCase "06_newexpr.js" (testFileUnminified "06_newexpr.js")+ , testCase "06_var.js" (testFileUnminified "06_var.js")+ , testCase "07_expr.js" (testFileUnminified "07_expr.js")+ , testCase "10_switch.js" (testFileUnminified "10_switch.js")+ , testCase "14_labelled_stmts.js" (testFileUnminified "14_labelled_stmts.js")+ , testCase "15_literals.js" (testFileUnminified "15_literals.js")+ , testCase "16_literals.js" (testFileUnminified "16_literals.js")+ , testCase "20_statements.js" (testFileUnminified "20_statements.js")+ , testCase "25_trycatch.js" (testFileUnminified "25_trycatch.js")+ , testCase "40_functions.js" (testFileUnminified "40_functions.js")+ , testCase "67_bob.js" (testFileUnminified "67_bob.js")+ , testCase "110_perfect.js" (testFileUnminified "110_perfect.js")+ , testCase "120_js.js" (testFileUnminified "120_js.js")+ , testCase "121_jsdefs.js" (testFileUnminified "121_jsdefs.js")+ , testCase "122_jsexec.js" (testFileUnminified "122_jsexec.js") + --, testCase "122_jsexec2.js" (testFileUnminified "122_jsexec2.js")++ ]+ srcHelloWorld = "function Hello(a) {}"-caseHelloWorld = +caseHelloWorld = "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Hello\") [JSIdentifier \"a\"] (JSFunctionBody [])])" @=? (showStrippedMaybe $ parseProgram srcHelloWorld)-caseMinHelloWorld = +caseMinHelloWorld = -- "function Hello(a){}" @=? (minify (U.fromString srcHelloWorld)) testMinify "function Hello(a){}" srcHelloWorld- -srcHelloWorld2 = "function Hello(a) {b=1}" -caseHelloWorld2 = ++srcHelloWorld2 = "function Hello(a) {b=1}"+caseHelloWorld2 = "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Hello\") [JSIdentifier \"a\"] (JSFunctionBody [JSSourceElements [JSExpression [JSIdentifier \"b\",JSOperator \"=\",JSDecimal \"1\"]]])])" @=? (showStrippedMaybe $ parseProgram srcHelloWorld2)-caseMinHelloWorld2 = +caseMinHelloWorld2 = -- "function Hello(a){b=1}" @=? (minify (U.fromString srcHelloWorld2)) testMinify "function Hello(a){b=1}" srcHelloWorld2 -srcSimpleAssignment = "a=1;" -caseSimpleAssignment = +srcSimpleAssignment = "a=1;"+caseSimpleAssignment = "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"a\",JSOperator \"=\",JSDecimal \"1\"],JSLiteral \";\"])" @=? (showStrippedMaybe $ parseProgram srcSimpleAssignment) caseMinSimpleAssignment =@@ -147,12 +150,12 @@ srcEmptyFor = "for (i = 0;;){}" caseEmptyFor = "Right (JSSourceElementsTop [JSFor [JSExpression [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]] [] [] (JSStatementBlock (JSStatementList []))])"- @=? (showStrippedMaybe $ parseProgram srcEmptyFor) + @=? (showStrippedMaybe $ parseProgram srcEmptyFor) srcFullFor = "for (i = 0;i<10;i++){}" caseFullFor = "Right (JSSourceElementsTop [JSFor [JSExpression [JSIdentifier \"i\",JSOperator \"=\",JSDecimal \"0\"]] [JSExpression [JSExpressionBinary \"<\" [JSIdentifier \"i\"] [JSDecimal \"10\"]]] [JSExpression [JSExpressionPostfix \"++\" [JSIdentifier \"i\"]]] (JSStatementBlock (JSStatementList []))])" @=? (showStrippedMaybe $ parseProgram srcFullFor)- + srcForVarFull = "for(var i=0,j=tokens.length;i<j;i++){}" caseForVarFull = "Right (JSSourceElementsTop [JSForVar [JSVarDecl (JSIdentifier \"i\") [JSDecimal \"0\"],JSVarDecl (JSIdentifier \"j\") [JSMemberDot [JSIdentifier \"tokens\"] (JSIdentifier \"length\")]] [JSExpression [JSExpressionBinary \"<\" [JSIdentifier \"i\"] [JSIdentifier \"j\"]]] [JSExpression [JSExpressionPostfix \"++\" [JSIdentifier \"i\"]]] (JSStatementBlock (JSStatementList []))])"@@ -180,84 +183,100 @@ @=? (showStrippedMaybe $ parseProgram src0_f) caseMin0_f = testMinify "function Hello(a){ExprArray(1,1)}" src0_f- + src01_semi1 = ( "{zero.one1;zero}\n"++ "one1\n"++ "two;three\n"++ "{{}} four;\n"++ "// five\n"++- "five") + "five") case01_semi1 = "Right (JSSourceElementsTop [JSStatementBlock (JSStatementList [JSExpression [JSMemberDot [JSIdentifier \"zero\"] (JSIdentifier \"one1\")],JSLiteral \";\",JSExpression [JSIdentifier \"zero\"]]),JSExpression [JSIdentifier \"one1\"],JSExpression [JSIdentifier \"two\"],JSLiteral \";\",JSExpression [JSIdentifier \"three\"],JSStatementBlock (JSStatementList [JSStatementBlock (JSStatementList [])]),JSExpression [JSIdentifier \"four\"],JSLiteral \";\",JSExpression [JSIdentifier \"five\"]])" @=? (showStrippedMaybe $ parseProgram src01_semi1) caseMin01_semi1 = testMinify "{zero.one1;zero};one1;two;three;four;five" src01_semi1- -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\"" ++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 [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\"]]])" @=? (showStrippedMaybe $ parseProgram src_min_100_animals) caseMin_min_100_animals = testMinify src_min_100_animals src_min_100_animals- + srcMergeStrings = "throw new TypeError(\"Function.prototype.apply called on\"+\" uncallable object\");"-caseMergeStrings = +caseMergeStrings = "Right (JSSourceElementsTop [JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"TypeError\",JSArguments [[JSExpressionBinary \"+\" [JSStringLiteral '\"' \"Function.prototype.apply called on\"] [JSStringLiteral '\"' \" uncallable object\"]]]]),JSLiteral \";\"])" @=? (showStrippedMaybe $ parseProgram srcMergeStrings)-caseMinMergeStrings = +caseMinMergeStrings = testMinify "throw new TypeError(\"Function.prototype.apply called on uncallable object\")" srcMergeStrings- + srcNestedSquare = "this.cursor+=match[0].length;" caseNestedSquare = "Right (JSSourceElementsTop [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"cursor\"),JSOperator \"+=\",JSMemberDot [JSMemberSquare [JSIdentifier \"match\"] (JSExpression [JSDecimal \"0\"])] (JSIdentifier \"length\")],JSLiteral \";\"])" @=? (showStrippedMaybe $ parseProgram srcNestedSquare)-caseMinNestedSquare = +caseMinNestedSquare = testMinify "this.cursor+=match[0].length" srcNestedSquare- -caseEitherLeft = ++caseEitherLeft = 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 = ++caseEitherRight = Right (LB.fromChunks [(E.encodeUtf8 $ T.pack "a=\"no syntax error\"")]) @=? minifym (LB.fromChunks [(E.encodeUtf8 $ T.pack "a=\"no syntax error\";")])- + srcTrailingCommas = "x={a:1,};y=[d,e,];" caseTrailingCommas = "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\",JSOperator \"=\",JSObjectLiteral [JSPropertyNameandValue (JSIdentifier \"a\") [JSDecimal \"1\"],JSLiteral \",\"]],JSLiteral \";\",JSExpression [JSIdentifier \"y\",JSOperator \"=\",JSArrayLiteral [JSIdentifier \"d\",JSElision [],JSIdentifier \"e\",JSLiteral \",\"]],JSLiteral \";\"])" @=? (showStrippedMaybe $ parseProgram srcTrailingCommas)-caseMinTrailingCommas = +caseMinTrailingCommas = testMinify "x={a:1,};y=[d,e,]" srcTrailingCommas- + srcGetSet = "x={get foo() {return 1},set foo(a) {x=a}}" caseGetSet = "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\",JSOperator \"=\",JSObjectLiteral [JSPropertyAccessor \"get\" (JSIdentifier \"foo\") [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSDecimal \"1\"],JSLiteral \"\"]]]),JSPropertyAccessor \"set\" (JSIdentifier \"foo\") [JSIdentifier \"a\"] (JSFunctionBody [JSSourceElements [JSExpression [JSIdentifier \"x\",JSOperator \"=\",JSIdentifier \"a\"]]])]]])" @=? (showStrippedMaybe $ parseProgram srcGetSet)-caseMinGetSet = +caseMinGetSet = testMinify "x={get foo(){return 1},set foo(a){x=a}}" srcGetSet- + srcUnicode = "var x = \"שלום\";" caseUnicode = "Right (JSSourceElementsTop [JSVariables \"var\" [JSVarDecl (JSIdentifier \"x\") [JSStringLiteral '\"' \"\\1513\\1500\\1493\\1501\"]]])" @=? (showStrippedMaybe $ parseProgram srcUnicode)-caseMinUnicode = +caseMinUnicode = testMinify "var x=\"שלום\"" srcUnicode srcIssue3 = "var myLatlng = new google.maps.LatLng(56.8379100, 60.5806664);" caseIssue3 = "Right (JSSourceElementsTop [JSVariables \"var\" [JSVarDecl (JSIdentifier \"myLatlng\") [JSLiteral \"new \",JSMemberDot [JSMemberDot [JSIdentifier \"google\"] (JSIdentifier \"maps\")] (JSIdentifier \"LatLng\"),JSArguments [[JSDecimal \"56.8379100\"],[JSDecimal \"60.5806664\"]]]]])" @=? (showStrippedMaybe $ parseProgram srcIssue3)-caseMinIssue3 = +caseMinIssue3 = testMinify "var myLatlng=new google.maps.LatLng(56.8379100,60.5806664)" srcIssue3 srcIssue4 = "/* * geolocation. пытаемся определить свое местоположение * если не получается то используем defaultLocation * @Param {object} map экземпляр карты * @Param {object LatLng} defaultLocation Координаты центра по умолчанию * @Param {function} callbackAfterLocation Фу-ия которая вызывается после * геолокации. Т.к запрос геолокации асинхронен */x" caseIssue4 = "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\"]])" @=? (showStrippedMaybe $ parseProgram srcIssue4)-caseMinIssue4 = +caseMinIssue4 = testMinify "x" srcIssue4 ++--srcIssue7="var hljs=new function(){function k(){if(k.called){return}k.called=true;var r=document.getElementsByTagName(\"pre\");for(var p=0;p<r.length;p++){}}}();"+srcIssue7="var hljs=new function(){function k(){if(k.called){return}}}();"+caseIssue7 =+ "Right (JSSourceElementsTop [JSVariables \"var\" [JSVarDecl (JSIdentifier \"hljs\") [JSLiteral \"new \",JSFunctionExpression [] [] (JSFunctionBody [JSSourceElements [JSFunction (JSIdentifier \"k\") [] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSMemberDot [JSIdentifier \"k\"] (JSIdentifier \"called\")]) (JSStatementBlock (JSStatementList [JSReturn [JSLiteral \"\"]]))]])]]),JSArguments []]]])"+ @=? (showStrippedMaybe $ parseProgram srcIssue7)+caseMinIssue7 =+ testMinify "var hljs=new function(){function k(){if(k.called)return}}()" srcIssue7++caseIssue7file =+ do+ x <- readFile ("./test/parsingonly/issue7.js")+ y <- readFile ("./test/parsingonly/issue7.js")+ let x' = trim x+ testMinify x' y+ -- --------------------------------------------------------------------- -- utilities @@ -266,16 +285,16 @@ testFile :: FilePath -> IO () testFile filename =- do + do x <- readFile (filename) let x' = trim x -- x' @=? (minify (U.fromString x') )- testMinify x' x' + testMinify x' x' testFileUnminified :: FilePath -> IO () testFileUnminified filename =- do + do x <- readFile ("./test/pminified/" ++ filename) y <- readFile ("./test/parsingonly/" ++ filename) let x' = trim x@@ -288,6 +307,6 @@ where f = reverse . dropWhile isSpace -- For language-javascript-parseProgram src = parse src "src" - +parseProgram src = parse src "src"+ -- EOF