
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@babel/plugin-transform-private-methods
Advanced tools
This plugin transforms private class 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.
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'
This package allows developers to use class properties, which includes static and instance properties. It can be used in conjunction with @babel/plugin-transform-private-methods to support private class properties, but it does not handle private methods or accessors on its own.
This plugin provides support for checking if a private field is in an object. It is complementary to @babel/plugin-transform-private-methods, which handles the transformation of private methods and accessors, but does not include the functionality to check for private field existence.
This plugin transforms private class methods
See our website @babel/plugin-transform-private-methods for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-private-methods
or using yarn:
yarn add @babel/plugin-transform-private-methods --dev
v7.25.9 (2024-10-22)
babel-parser
, babel-template
, babel-types
syntacticPlaceholders
mode (@liuxingbaoyu)babel-helper-compilation-targets
, babel-preset-env
ClassAccessorProperty
to prevent the no-undef
rule (@victorenator)babel-parser
, babel-types
VISITOR_KEYS
etc. faster to access (@liuxingbaoyu)FAQs
This plugin transforms private class methods
The npm package @babel/plugin-transform-private-methods receives a total of 18,376,479 weekly downloads. As such, @babel/plugin-transform-private-methods popularity was classified as popular.
We found that @babel/plugin-transform-private-methods demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.