Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-private-methods

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-private-methods

This plugin transforms private class methods


Version published
Weekly downloads
17M
decreased by-1.9%
Maintainers
4
Weekly downloads
 
Created

What is @babel/plugin-transform-private-methods?

The @babel/plugin-transform-private-methods package is a Babel plugin that allows developers to use private methods and accessors in classes, according to the ECMAScript specifications. This plugin transforms private methods and accessors so that they can be used in environments that do not support them natively.

What are @babel/plugin-transform-private-methods's main functionalities?

Private Method Transformation

This feature allows developers to define private methods in a class, which are not accessible from outside of the class. The plugin will transform these methods so that they are functionally private in environments that do not have native support for private methods.

class MyClass {
  #privateMethod() {
    return 'Hello from private method';
  }

  publicMethod() {
    return this.#privateMethod();
  }
}

const instance = new MyClass();
console.log(instance.publicMethod()); // 'Hello from private method'

Private Accessor Transformation

This feature enables the use of private getters and setters within a class. Similar to private methods, these accessors are transformed by the plugin to maintain their privacy outside of the class.

class MyClass {
  #privateField = 'private value';

  get #privateAccessor() {
    return this.#privateField;
  }

  publicMethod() {
    return this.#privateAccessor;
  }
}

const instance = new MyClass();
console.log(instance.publicMethod()); // 'private value'

Other packages similar to @babel/plugin-transform-private-methods

Keywords

FAQs

Package last updated on 22 Aug 2024

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