メインコンテンツへスキップ

@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 install --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"],
});

参照