跳到主要内容

@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

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

Via Node API

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

Options

Assumptions

This plugin is affected by the noDocumentAll assumption.

version

Required.

"2023-07"

Selects the proposal to use:

References