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 1d6bcf5
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions scripts/transform-pipe.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
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 }) => ({
visitor: {
ImportDeclaration(path, state) {
if (path.node.source.value === 'wonka') {
const { specifiers } = path.node
const { specifiers } = path.node;
const pipeSpecifierIndex = specifiers.findIndex(spec => {
return spec.imported.name === 'pipe';
});
Expand Down

0 comments on commit 1d6bcf5

Please sign in to comment.