Skip to main content

@babel/plugin-proposal-pipeline-operator

安装

¥Installation

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

用法

¥Usage

管道运算符有几个相互竞争的提议。使用所需的 "proposal" 选项配置要使用的提议。默认值为 "hack"

¥The pipeline operator has several competing proposals. Configure which proposal to use with the required "proposal" option. Its value is "hack" by default.

提议添加的版本
"hack"黑客式管道v7.15.0
"fsharp"带有 await 的 F# 样式管道v7.5.0
"minimal"最小的 F# 风格的管道v7.0.0
"smart"智能混合管道(弃用)v7.3.0

如果省略 "proposal",或者使用 "proposal": "hack",则必须包含 "topicToken" 选项。topicToken 必须是 "%""^^""@@""^""#" 之一。

¥If "proposal" is omitted, or if "proposal": "hack" is used, then a "topicToken" option must be included. The topicToken must be one of "%", "^^", "@@", "^", or "#".

"proposal": "minimal""smart" 选项已弃用,并将在未来的主要版本中删除。

¥The "proposal": "minimal" and "smart" options are deprecated and subject to removal in a future major version.

示例

¥Examples

以下示例使用 topicToken: "^^"

¥The following examples use topicToken: "^^".

来自 react/scripts/jest/jest-cli.js

¥From react/scripts/jest/jest-cli.js.

JavaScript
// Status quo
console.log(
chalk.dim(
`$ ${Object.keys(envars)
.map(envar => `${envar}=${envars[envar]}`)
.join(' ')}`,
'node',
args.join(' ')
)
);

// With pipes
Object.keys(envars)
.map(envar => `${envar}=${envars[envar]}`)
.join(' ')
|> `$ ${^^}`
|> chalk.dim(^^, 'node', args.join(' '))
|> console.log(^^);

来自 jquery/src/core/init.js

¥From jquery/src/core/init.js.

JavaScript
// Status quo
jQuery.merge( this, jQuery.parseHTML(
match[ 1 ],
context && context.nodeType ? context.ownerDocument || context : document,
true
) );

// With pipes
context
|> (^^ && ^^.nodeType ? ^^.ownerDocument || ^^ : document)
|> jQuery.parseHTML(match[1], ^^, true)
|> jQuery.merge(^^);

(有关已弃用的提案模式行为的摘要,请参阅 pipe wiki 的先前提案表。)

¥(For a summary of deprecated proposal modes’ behavior, see the pipe wiki’s table of previous proposals.)

¥With a configuration file (recommended)

使用 ^^ 主题令牌:

¥With ^^ topic token:

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

使用 @@ 主题令牌:

¥With @@ topic token:

babel.config.json
{
"plugins": [
["@babel/plugin-proposal-pipeline-operator", { "topicToken": "@@" }]
]
}

通过 CLI

¥Via CLI

因为这个插件需要一个配置选项,所以 不能直接从 CLI 配置。使用 配置文件 代替 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.

通过 Node API

¥Via Node API

使用 ^^ 主题令牌:

¥With ^^ topic token:

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

使用 @@ 主题令牌:

¥With @@ topic token:

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