babel-plugin-pipe-operator icon indicating copy to clipboard operation
babel-plugin-pipe-operator copied to clipboard

Can't this be done using |> instead?

Open imranismail opened this issue 9 years ago • 8 comments

imranismail avatar Mar 17 '16 17:03 imranismail

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.

miraks avatar Mar 17 '16 18:03 miraks

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.

More informations.

Swizz avatar Jun 16 '16 10:06 Swizz

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.

miraks avatar Jun 16 '16 14:06 miraks

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 )

Swizz avatar Jun 16 '16 14:06 Swizz

Looks like there's already been PR from @mrapogee but it never was merged.

miraks avatar Jun 16 '16 15:06 miraks

Oh. Got it ! Thanks for all your answers.

Swizz avatar Jun 16 '16 15:06 Swizz

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.

samdesota avatar Jun 16 '16 15:06 samdesota

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.

Swizz avatar Jun 17 '16 09:06 Swizz