@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
- Yarn
- pnpm
npm install --save-dev @babel/plugin-proposal-optional-chaining-assign
yarn add --dev @babel/plugin-proposal-optional-chaining-assign
pnpm add --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:
-
"2023-07"
:tc39/proposal-optional-chaining-assignment@49d055c44b
中定义的第一阶段提案在 2023 年 7 月的 TC39 会议上提出。¥
"2023-07"
: The stage 1 proposal as defined attc39/proposal-optional-chaining-assignment@49d055c44b
, presented in the July 2023 TC39 meeting.
参考
¥References