Skip to main content

@babel/plugin-proposal-optional-chaining-assign

转换赋值表达式左侧的可选链。

¥Transform optional chaining on the left-hand side of assignment expressions.

示例

¥Example

input.js
function doSomething(maybeOptions) {
maybeOptions?.retries = 5;
}

将转变为

¥will be transformed to

output.js
function doSomething(maybeOptions) {
maybeOptions !== null && maybeOptions !== void 0 && maybeOptions.retries = 5;
}

安装

¥Installation

npm install --save-dev @babel/plugin-proposal-optional-chaining-assign

用法

¥Usage

¥With a configuration file (Recommended)

babel.config.json
{
"plugins": [
[
"@babel/plugin-proposal-optional-chaining-assign",
{
"version": "2023-07"
}
]
]
}

通过 Node API

¥Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: [["@babel/plugin-proposal-optional-chaining-assign", {
"version": "2023-07"
}]],
});

选项

¥Options

假设

¥Assumptions

该插件受 noDocumentAll 假设的影响。

¥This plugin is affected by the noDocumentAll assumption.

version

必需的。

¥Required.

"2023-07"

选择要使用的提案:

¥Selects the proposal to use:

参考

¥References