babel-plugin-pipe-operator
babel-plugin-pipe-operator copied to clipboard
Can't this be done using |> instead?
Unfortunately, no. Constructions like this
a |> b
will give syntax error in JavaScript. It will be possible if Babel team provide API for parser plugins, but I don't know if they're planning to do that.
To avoid syntax error, Babel seem to use two kinds of plugins : syntax and transform.
I think syntax allow the parser to work well with non standard syntax.
And transform, made the new syntax to JS one.
Yes, but API for parser (syntax) plugins isn't public and really poor. Actually babels "official" syntax plugins are hardcoded into babylon. For example, function bind syntax plugin: plugin code and babylon check.
Oh. I am just starting with Babel plugins.
So, the best way is to play with mrapogee/babel-plugin-syntax-pipeline-operator and mrapogee/babel-plugin-transform-pipeline-operator and to made a PR on babel/babylon to work well with the pipelineOperator option ?
Someone is interested about this functionality or this one work well for your needs ?
( cc @mrapogee )
Looks like there's already been PR from @mrapogee but it never was merged.
Oh. Got it ! Thanks for all your answers.
Hey all,
I was playing around with this a few months ago and I forked babel to get this working on my setup, but the PR and code referenced above is actually from @mindeavor
I did make babylon branch mrapogee/babylon/tree/feature-pipeline that adds the pipeline operator to the syntax. If you get babel-core to import the source from that branch, you may be able to compile the pipeline operator if you include babel-plugin-transform-pipeline-operator in your .babelrc, though I haven't fully tested.
I want to keep my hands on the official babylon.
This plugin works well, and finally the | operator is sweet.
I do not need bitwise operators in javascript.
But.. In the esnext proposal about pipeline, @mindeavor works with currying.
So ...
let result = "hello"
|> doubleSay
become
let result = doubleSay("hello")
Here, you choose to unshift it in the arguments array like Elm.
So ...
let result = "hello"
|> doubleSay(null)
become
let result = doubleSay("hello", null)
I think currying is a better way to do that stuff. I will work on an alternative which implements currying stuffs.