What is @babel/helper-create-class-features-plugin?
The @babel/helper-create-class-features-plugin is a helper package used internally by Babel plugins to handle the transformation of class features. It is not intended to be used directly by end users, but rather as a utility for plugin authors to create transformations for class properties, private methods, and other class-related syntax in a consistent way.
What are @babel/helper-create-class-features-plugin's main functionalities?
Class Properties
This feature allows the transformation of class properties so that they can be compiled into a format that is compatible with environments that do not support the latest ECMAScript standards. The code sample shows how a class property is transformed into a constructor assignment with a helper function.
"use strict";
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
class Example {
constructor() {
_defineProperty(this, "state", {});
}
}
Private Methods
This feature enables the transformation of private methods in a class. The code sample illustrates how a private method is transformed using WeakSets and helper functions to ensure that the method remains private and is not accessible outside the class.
"use strict";
function _classPrivateMethodInitSpec(obj, privateSet) {
// ...implementation details
}
function _classPrivateMethodGet(receiver, privateSet, fn) {
// ...implementation details
}
class Example {
constructor() {
_classPrivateMethodInitSpec(this, _privateMethod);
}
}
var _privateMethod = new WeakSet();
Other packages similar to @babel/helper-create-class-features-plugin
@babel/plugin-proposal-class-properties
This package is a Babel plugin that transforms static class properties as well as properties declared with the property initializer syntax. It is similar to @babel/helper-create-class-features-plugin in that it handles class properties, but it is a full plugin that can be added to a Babel configuration, whereas the helper package is used internally by such plugins.
@babel/plugin-proposal-private-methods
Similar to @babel/helper-create-class-features-plugin, this Babel plugin transforms private methods and accessors in classes. It provides the functionality to use private syntax in class bodies and is intended for direct use in Babel configurations, unlike the helper package which is used under the hood by this and other plugins.
@babel/helper-create-class-features-plugin
Compile class public and private fields, private methods and decorators to ES6
See our website @babel/helper-create-class-features-plugin for more information.
Install
Using npm:
npm install --save-dev @babel/helper-create-class-features-plugin
or using yarn:
yarn add @babel/helper-create-class-features-plugin --dev