Skip to content

Latest commit

 

History

History
371 lines (258 loc) · 5.5 KB

plugin-proposal-pipeline-operator.md

File metadata and controls

371 lines (258 loc) · 5.5 KB
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 8
---
id: babel-plugin-proposal-pipeline-operator
title: @babel/plugin-proposal-pipeline-operator
sidebar_label: pipeline-operator
---

Installation

$ npm install --save-dev @babel/plugin-proposal-pipeline-operator

Usage

The pipeline operator has several competing proposals. Configure which proposal to use with the required "proposal" option.

Value Proposal Version added
"minimal" Minimal F#-style pipes v7.0.0
"fsharp" F#-style pipes with await v7.5.0
"hack" Hack-style pipes v7.15.0
"smart" Smart-mix pipes (deprecated) v7.3.0

If "proposal": "hack" is used, then a "topicToken": "%", "topicToken": "^", or "topicToken": "#" option must also be included.

The "proposal": "smart" option is deprecated and subject to removal in a future major version.

When TC39 accepts one of the proposals, that proposal will become the default and the "proposal" option will no longer be required.

Summary of proposals’ behavior

Original expression

Minimal F# pipes
{proposal: "minimal"}

F# pipes with await
{proposal: "fsharp"}

Hack pipes
{proposal: "hack",
topicToken: "%"}

o.m(x)

x |> o.m

x |> o.m

x |> o.m(%)

o.m(0, x)

x |> y=>o.m(0, y)

x |> y=>o.m(0, y)

x |> o.m(0, %)

new o.m(x)

x |> y=>new o.m(y)

x |> y=>new o.m(y)

x |> new o.m(%)

o[x]

x |> y=>o[x]

x |> y=>o[y]

x |> o[%]

x[i]

x |> y=>x[i]

x |> y=>y[i]

x |> %[i]

x + 1

x |> y=>y + 1

x |> y=>y + 1

x |> % + 1

[0, x]

x |> y=>[0, y]

x |> y=>[0, y]

x |> [0, %]

{ key: x }

x |> y=>({ key: y })

x |> y=>({ key: y })

x |> { key: % }

await o.m(x)

Not supported

x |> o.m |> await

x |> await o.m(%)

yield o.m(x)

Not supported Not supported

x |> (yield o.m(%))

With a configuration file (Recommended)

For minimal F# pipes:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }]
  ]
}

For F# pipes with await:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "fsharp" }]
  ]
}

For Hack pipes with % topic token:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "hack", "topicToken": "%" }]
  ]
}

For Hack pipes with ^ topic token:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "hack", "topicToken": "^" }]
  ]
}

For Hack pipes with # topic token:

{
  "plugins": [
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "hack", "topicToken": "#" }]
  ]
}

Via CLI

Because this plugin requires a configuration option, it cannot be directly configured from the CLI. Use a config file instead with the CLI, to add and configure this plugin.

Via Node API

For minimal F# pipes
{proposal: "minimal"}:

require("@babel/core").transformSync("code", {
  plugins: [
    [ "@babel/plugin-proposal-pipeline-operator", { proposal: "minimal" } ],
  ],
});

For F# pipes with await:

require("@babel/core").transformSync("code", {
  plugins: [
    [ "@babel/plugin-proposal-pipeline-operator", { proposal: "fsharp" } ],
  ],
});

For Hack pipes with % topic token:

require("@babel/core").transformSync("code", {
  plugins: [
    [ "@babel/plugin-proposal-pipeline-operator", { proposal: "hack", topicToken: "%" } ],
  ],
});

For Hack pipes with ^ topic token:

require("@babel/core").transformSync("code", {
  plugins: [
    [ "@babel/plugin-proposal-pipeline-operator", { proposal: "hack", topicToken: "^" } ],
  ],
});

For Hack pipes with # topic token:

require("@babel/core").transformSync("code", {
  plugins: [
    [ "@babel/plugin-proposal-pipeline-operator", { proposal: "hack", topicToken: "#" } ],
  ],
});