@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"
}
]
]
}
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:
"2023-07"
: The stage 1 proposal as defined attc39/proposal-optional-chaining-assignment@49d055c44b
, presented in the July 2023 TC39 meeting.