Socket
Socket
Sign inDemoInstall

babel-plugin-transform-class-properties

Package Overview
Dependencies
28
Maintainers
6
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-class-properties

This plugin transforms static class properties as well as properties declared with the property initializer syntax


Version published
Maintainers
6
Weekly downloads
813,487
decreased by-12%

Weekly downloads

Readme

Source

babel-plugin-transform-class-properties

This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.

Example

Below is a class with four class properties which will be transformed.

  class Bork {
    //Property initializer syntax
    instanceProperty = "bork";
    boundFunction = () => {
      return this.instanceProperty;
    }

    //Static class properties
    static staticProperty = "babelIsCool";
    static staticFunction = function() {
      return Bork.staticProperty;
    }
  }

  let myBork = new Bork;

  //Property initializers are not on the prototype.
  console.log(myBork.prototype.boundFunction); // > undefined

  //Bound functions are bound to the class instance.
  console.log(myBork.boundFunction.call(undefined)); // > "bork"

  //Static function exists on the class.
  console.log(Bork.staticFunction()); // > "babelIsCool"

Installation

npm install --save-dev babel-plugin-transform-class-properties

Usage

.babelrc

// without options
{
  "plugins": ["transform-class-properties"]
}

// with options
{
  "plugins": [
    ["transform-class-properties", { "spec": true }]
  ]
}

Via CLI

babel --plugins transform-class-properties script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-class-properties"]
});

Options

spec

boolean, defaults to false.

Class properties are compiled to use Object.defineProperty. Static fields are now defined even if they are not initialized.

References

  • Proposal: ES Class Fields & Static Properties

Keywords

FAQs

Last updated on 07 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc