Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-decorators

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-decorators

Compile class and object decorators to ES5

  • 7.0.0-alpha.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
117K
decreased by-83.43%
Maintainers
4
Weekly downloads
 
Created
Source

babel-plugin-transform-decorators

Compile class and object decorators to ES5

Example

(examples are from proposal)

Simple class decorator

@annotation
class MyClass { }

function annotation(target) {
   target.annotated = true;
}

Class decorator

@isTestable(true)
class MyClass { }

function isTestable(value) {
   return function decorator(target) {
      target.isTestable = value;
   }
}

Class function decorator

class C {
  @enumerable(false)
  method() { }
}

function enumerable(value) {
  return function (target, key, descriptor) {
     descriptor.enumerable = value;
     return descriptor;
  }
}

Installation

npm install --save-dev babel-plugin-transform-decorators

Usage

Add the following line to your .babelrc file:

{
  "plugins": ["transform-decorators"]
}
NOTE: Order of Plugins Matters!

If you are including your plugins manually and using transform-class-properties, make sure that transform-decorators comes before transform-class-properties.

Wrong:

{
  "plugins": [
    "transform-class-properties",
    "transform-decorators"
  ]
}

Right:

{
  "plugins": [
    "transform-decorators",
    "transform-class-properties"
  ]
}

Via CLI

babel --plugins transform-decorators script.js

Via Node API

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

References

  • Proposal: Javascript Decorators

Keywords

FAQs

Package last updated on 31 May 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc