@babel/plugin-proposal-destructuring-private
Transforms private destructuring var { #y: y } = this
to var y = this.#y
.
Example
JavaScript
class Foo {
x;
#y;
equalsTo({ x, #y: y }) {
return this.x === x && this.#y === y;
}
}
will be transformed to
JavaScript
class Foo {
x;
#y;
equalsTo(_p) {
var { x } = _p, y = _p.#y;
return this.x === x && this.#y === y;
}
}
The plugin respects these compiler assumptions:
Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-proposal-destructuring-private
yarn add --dev @babel/plugin-proposal-destructuring-private
pnpm add --save-dev @babel/plugin-proposal-destructuring-private
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-destructuring-private"]
}
Because the output code includes private fields, if you are already using other class feature plugins (e.g. `@babel/plugin-transform-class-properties), be sure to place it before the others.
babel.config.json
{
"plugins": [
"@babel/plugin-proposal-destructuring-private",
"@babel/plugin-transform-class-properties"
]
}
Via CLI
Shell
babel --plugins @babel/plugin-proposal-destructuring-private script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-destructuring-private"],
});