diff --git a/src/ElmFormat/Upgrade_0_19.hs b/src/ElmFormat/Upgrade_0_19.hs index 601aca946..d71713bf9 100644 --- a/src/ElmFormat/Upgrade_0_19.hs +++ b/src/ElmFormat/Upgrade_0_19.hs @@ -14,6 +14,10 @@ import qualified Reporting.Region as Region transform :: Expr -> Expr transform expr = case RA.drop expr of + -- + -- Basics.flip + -- + VarExpr var | isBasics "flip" var -> noRegion $ Lambda [makeArg "f", makeArg "b", makeArg "a"] [] @@ -48,6 +52,59 @@ transform expr = noRegion $ Parens (Commented pre (noRegion $ App arg1 (arg3:arg2:argRest) multiline) []) + -- + -- Basics.curry + -- + + VarExpr var | isBasics "curry" var -> + noRegion $ Lambda + [makeArg "f", makeArg "a", makeArg "b"] [] + (noRegion $ App + (makeVarRef "f") + [([], noRegion $ AST.Expression.Tuple + [ Commented [] (makeVarRef "a") [] + , Commented [] (makeVarRef "b") [] + ] False + )] + (FAJoinFirst JoinAll) + ) + False + + App (A _ (VarExpr var)) [(pre1, arg1)] _ | isBasics "curry" var -> + noRegion $ Lambda + [makeArg "a", makeArg "b"] pre1 + (noRegion $ App arg1 + [([], noRegion $ AST.Expression.Tuple + [ Commented [] (makeVarRef "a") [] + , Commented [] (makeVarRef "b") [] + ] False + )] + (FAJoinFirst JoinAll) + ) + False + + App (A _ (VarExpr var)) [(pre1, arg1),(pre2, arg2)] _ | isBasics "curry" var -> + noRegion $ Lambda + [makeArg "b"] pre1 + (noRegion $ App arg1 + [([], noRegion $ AST.Expression.Tuple + [ Commented pre2 arg2 [] + , Commented [] (makeVarRef "b") [] + ] False + )] + (FAJoinFirst JoinAll) + ) + False + + App (A _ (VarExpr var)) ((pre1, arg1):(pre2, arg2):(pre3, arg3):argRest) multiline | isBasics "curry" var -> + noRegion $ App arg1 + ((pre1, noRegion $ AST.Expression.Tuple + [ Commented pre2 arg2 [] + , Commented pre3 arg3 [] + ] False + ):argRest) + multiline + _ -> expr diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 5d0424bd2..16c9980c8 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -311,6 +311,7 @@ checkUpgrade 0.19 Elm-0.19/CommaFunctionsBecomeLambdas.elm checkUpgrade 0.19 Elm-0.19/RemoveBangOperator.elm checkUpgrade 0.19 Elm-0.19/NewStringEscapeSyntax.elm checkUpgrade 0.19 Elm-0.19/RemoveBasicsFlip.elm +checkUpgrade 0.19 Elm-0.19/RemoveBasicsCurry.elm checkGood 0.18 Simple.elm checkGood 0.18 AllSyntax/0.18/AllSyntax.elm diff --git a/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.elm b/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.elm new file mode 100644 index 000000000..57d2e728c --- /dev/null +++ b/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.elm @@ -0,0 +1,12 @@ +fullyApplied f = curry f "1" 2 +fullyApplied_comments f = curry{-A-}f{-B-}"1"{-C-}2 +partiallyApplied f = curry f "1" +partiallyApplied_comments f = curry{-A-}f{-B-}"1" +functionOnly f = curry f +functionOnly_comments f = curry{-A-}f +unapplied = curry +extraArgs f = curry f 1 2 3 4 5 + +qualified f = Basics.curry f "1" 2 + +nested f = curry f (curry f 1 2) 3 diff --git a/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.formatted.elm b/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.formatted.elm new file mode 100644 index 000000000..8c5cf570a --- /dev/null +++ b/tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.formatted.elm @@ -0,0 +1,45 @@ +module Main exposing (..) + + +fullyApplied f = + f ( "1", 2 ) + + +fullyApplied_comments f = + f {- A -} ( {- B -} "1", {- C -} 2 ) + + +partiallyApplied f = + \b -> f ( "1", b ) + + +partiallyApplied_comments f = + \b -> + {- A -} + f ( {- B -} "1", b ) + + +functionOnly f = + \a b -> f ( a, b ) + + +functionOnly_comments f = + \a b -> + {- A -} + f ( a, b ) + + +unapplied = + \f a b -> f ( a, b ) + + +extraArgs f = + f ( 1, 2 ) 3 4 5 + + +qualified f = + f ( "1", 2 ) + + +nested f = + f ( f ( 1, 2 ), 3 )