@babel/plugin-proposal-pipeline-operator
安装
¥Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-proposal-pipeline-operator
yarn add --dev @babel/plugin-proposal-pipeline-operator
pnpm add --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.
// 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(^^);
¥From jquery/src/core/init.js.
// 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:
{
"plugins": [
["@babel/plugin-proposal-pipeline-operator", { "topicToken": "^^" }]
]
}
使用 @@
主题令牌:
¥With @@
topic token:
{
"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:
require("@babel/core").transformSync("code", {
plugins: [
[ "@babel/plugin-proposal-pipeline-operator", { topicToken: "^^" } ],
],
});
使用 @@
主题令牌:
¥With @@
topic token:
require("@babel/core").transformSync("code", {
plugins: [
[ "@babel/plugin-proposal-pipeline-operator", { topicToken: "@@" } ],
],
});