Nesting Penguins Molt

    babel-plugin-transform-decorators

    6.24.1 • Public • Published

    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

    Via .babelrc (Recommended)

    .babelrc

    {
      "plugins": ["transform-decorators"]
    }

    Via CLI

    babel --plugins transform-decorators script.js

    Via Node API

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

    References

    Keywords

    Install

    npm i babel-plugin-transform-decorators

    DownloadsWeekly Downloads

    503,865

    Version

    6.24.1

    License

    MIT

    Last publish

    Collaborators

    • hzoo
    • loganfsmyth
    • existentialism