Skip to content

Commit

Permalink
Reversed pipe call support
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Jul 20, 2017
1 parent c4c91a5 commit ca983c3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/pipe.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
} from 'ast-loc-utils'

export transformPipeOperator(path) ->
{ node: { left, right } } = path
{ node: { left, right, reversed } } = path
loc = getSurroundingLoc([left, right])
path.replaceWith(t.callExpression(right, [left])~atLoc(loc))
if not reversed:
path.replaceWith(t.callExpression(right, [left])~atLoc(loc))
else:
path.replaceWith(t.callExpression(left, [right])~atLoc(loc))
2 changes: 2 additions & 0 deletions test/fixtures/pipe-call/basic/actual.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
a |> b |> c

a <| b <| c
4 changes: 3 additions & 1 deletion test/fixtures/pipe-call/basic/expected.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
c(b(a));
c(b(a));

a(b(c));
6 changes: 6 additions & 0 deletions test/fixtures/pipe-call/recompose-pattern/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MyComponent = pure <|
withSomething(stuff) <|
withSomethingElse(stuff) <|
(props) ->
<div>{props.thing}</div>

3 changes: 3 additions & 0 deletions test/fixtures/pipe-call/recompose-pattern/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const MyComponent = pure(withSomething(stuff)(withSomethingElse(stuff)(function (props) {
return <div>{props.thing}</div>;
})));

0 comments on commit ca983c3

Please sign in to comment.