Skip to main content

@babel/plugin-proposal-discard-binding

将丢弃绑定 const [void, x] = arr 转换为 const [, x] = arr

🌐 Transforms discard binding const [void, x] = arr to const [, x] = arr

示例​

🌐 Example

JavaScript
const [void, x] = arr;
using void = getResource();

将转变为

🌐 will be transformed to

JavaScript
const [, x] = arr;
using _ = getResource();

该插件尊重这些编译器假设:

🌐 The plugin respects these compiler assumptions:

安装​

🌐 Installation

npm install --save-dev @babel/plugin-proposal-discard-binding

用法​

🌐 Usage

🌐 With a configuration file (Recommended)

babel.config.json
{
"plugins": ["@babel/plugin-proposal-discard-binding"]
}

通过 CLI​

🌐 Via CLI

Shell
babel --plugins @babel/plugin-proposal-discard-binding script.js

通过 Node API​

🌐 Via Node API

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

选项​

🌐 Options

syntaxType​

必需的。

🌐 Required.

"void"

选择语法类型来表示丢弃绑定。目前唯一支持的值是 "void"。

🌐 Choose the syntax type to represent the discard binding. Currently the only supported value is "void".

参考​

🌐 References