@babel/plugin-proposal-pipeline-operator
安装
🌐 Installation
- npm
- Yarn
- pnpm
- Bun
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
bun add --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" | Hack 风格管道 |
"fsharp" | 带 await 的 F# 风格管道 |
如果省略 "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 "#".
示例
🌐 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 的以往提案表格。)
使用配置文件(推荐)
🌐 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
因为这个插件需要一个配置选项,它不能直接从命令行配置。请改用配置文件与命令行一起使用,以添加和配置这个插件。
🌐 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: "@@" } ],
],
});