@babel/plugin-proposal-destructuring-private
プライベートなデストラクチャリング`var { #y: y } = this`を`var y = this.#y`に変換します。
例
JavaScript
class Foo {
x;
#y;
equalsTo({ x, #y: y }) {
return this.x === x && this.#y === y;
}
}
は以下に変換されます
JavaScript
class Foo {
x;
#y;
equalsTo(_p) {
var { x } = _p, y = _p.#y;
return this.x === x && this.#y === y;
}
}
このプラグインは以下のコンパイラの仮定を尊重します
インストール
- 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
使用方法
設定ファイルを使用する場合(推奨)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-destructuring-private"]
}
出力コードにはプライベートフィールドが含まれているため、他のクラス機能プラグイン(例:`@babel/plugin-transform-class-properties`)を既に使用している場合は、それらの**前**に配置してください。
babel.config.json
{
"plugins": [
"@babel/plugin-proposal-destructuring-private",
"@babel/plugin-transform-class-properties"
]
}
CLI経由
シェル
babel --plugins @babel/plugin-proposal-destructuring-private script.js
Node API経由
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-destructuring-private"],
});