@babel/plugin-transform-property-mutators

NOTE: This plugin is included in @babel/preset-env

Example

In

  1. var foo = {
  2. get bar() {
  3. return this._bar;
  4. },
  5. set bar(value) {
  6. this._bar = value;
  7. },
  8. };

Out

  1. var foo = Object.defineProperties(
  2. {},
  3. {
  4. bar: {
  5. get: function() {
  6. return this._bar;
  7. },
  8. set: function(value) {
  9. this._bar = value;
  10. },
  11. configurable: true,
  12. enumerable: true,
  13. },
  14. }
  15. );

Installation

  1. npm install --save-dev @babel/plugin-transform-property-mutators

Usage

  1. {
  2. "plugins": ["@babel/plugin-transform-property-mutators"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-transform-property-mutators script.js

Via Node API

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-property-mutators"],
  3. });