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

babel-plugin-transform-evacuate-features

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-evacuate-features

Turn proposal ES features into comments for parsers not supporting them

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-evacuate-features

Turn proposal ES features (like class-properties or decorators) into class methods for parsers which does not support these syntax. It is expected to use with unevacuate plugin to restore the evacuated feature.

Example

Input

class A {
  a;

  @annotateProp
  b = 1;
  
  @annotateMethod({ flag: true })
  print() {
    console.log('a = ', this.a, ', b = ', this.b);
  }
}

Output

class A {
  __evacuated_0() {
    this.__evacuated__("classProperty", "a", []);
  }

  __evacuated_1() {
    this.__evacuated__("classProperty", "b", [["annotateProp"]], 1);
  }

  __evacuated_2() {
    this.__evacuated__("classMethod", "print", [["annotateMethod", {
      flag: true
    }]]);
  }

  print() {
    console.log('a = ', this.a, ', b = ', this.b);
  }

}

Install

$ npm install babel-plugin-transform-evacuate-features --save-dev

Setup

Add transform-evacuate-features in config file (babel.config.js or .babelrc), or babel.transform() options.

Note that parserOpts.plugins might be needed to tell babel parser to recognize these syntax.

{
  "plugins": ["transform-evacuate-features"],
  "parserOpts": {
    "plugins": ["class-properties", "decorator-legacy"]
  }
}

If you want to restore the evacuated class property / class method decorators, it is required to import unevacuateFeaturesPlugin and pass to the babel plugin.

import { unevacuateFeaturesPlugin } from 'babel-plugin-transform-evacuate-features';
module.exports = {
  plugins: [unevacuateFeaturesPlugin],
  parserOpts: {
    plugins: ["class-properties", "decorator-legacy"]
  }
};

Keywords

FAQs

Package last updated on 20 Mar 2020

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