Skip to content

Commit

Permalink
Fix pipeExpression order
Browse files Browse the repository at this point in the history
This imitates Wonka's pipe algo so that it's easier
to follow. Also the previous one was incorrect
  • Loading branch information
kitten committed Sep 6, 2019
1 parent b92798c commit cd09d7f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions scripts/transform-pipe.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
const pipeExpression = (t, pipeline) => {
if (pipeline.length === 1) {
return pipeline[0];
} else {
const operator = pipeline[pipeline.length - 1];
const rest = pipeline.slice(0, -1);
return t.callExpression(
pipeExpression(t, rest),
[operator]
);
}
let x = pipeline[0];
for (let i = 1; i < pipeline.length; i++)
x = t.callExpression(pipeline[i], [x]);
return x;
};

const pipePlugin = ({ types: t }) => ({
Expand Down

0 comments on commit cd09d7f

Please sign in to comment.