![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
babel-plugin-transform-class-properties
Advanced tools
This plugin transforms static class properties as well as properties declared with the property initializer syntax
The babel-plugin-transform-class-properties package is a Babel plugin that allows you to use class properties in your JavaScript code. This plugin transforms class properties to be compatible with older JavaScript environments that do not support this feature natively.
Public Class Fields
This feature allows you to define public class fields directly within the class body. The plugin transforms this syntax to be compatible with older JavaScript environments.
class MyClass {
myField = 'Hello, world!';
}
Static Class Fields
This feature allows you to define static class fields directly within the class body. Static fields are shared among all instances of the class. The plugin ensures this syntax works in environments that do not support it natively.
class MyClass {
static myStaticField = 'Hello, static world!';
}
Instance Property Initialization
This feature allows you to initialize instance properties directly within the class body, making the code more concise and readable. The plugin transforms this syntax to be compatible with older JavaScript environments.
class MyClass {
myField = 'Hello, world!';
constructor() {
console.log(this.myField);
}
}
The babel-plugin-transform-es2015-classes package transforms ES2015 class syntax to ES5. While it does not specifically focus on class properties, it is often used in conjunction with other plugins to achieve similar functionality.
This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.
Below is a class with four class properties which will be transformed.
class Bork {
//Property initializer syntax
instanceProperty = "bork";
boundFunction = () => {
return this.instanceProperty;
}
//Static class properties
static staticProperty = "babelIsCool";
static staticFunction = function() {
return Bork.staticProperty;
}
}
let myBork = new Bork;
//Property initializers are not on the prototype.
console.log(myBork.prototype.boundFunction); // > undefined
//Bound functions are bound to the class instance.
console.log(myBork.boundFunction.call(undefined)); // > "bork"
//Static function exists on the class.
console.log(Bork.staticFunction()); // > "babelIsCool"
npm install --save-dev babel-plugin-transform-class-properties
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["transform-class-properties"]
}
// with options
{
"plugins": [
["transform-class-properties", { "spec": true }]
]
}
babel --plugins transform-class-properties script.js
require("babel-core").transform("code", {
plugins: ["transform-class-properties"]
});
spec
boolean
, defaults to false
.
Class properties are compiled to use Object.defineProperty
. Static fields are now defined even if they are not initialized.
FAQs
This plugin transforms static class properties as well as properties declared with the property initializer syntax
The npm package babel-plugin-transform-class-properties receives a total of 989,461 weekly downloads. As such, babel-plugin-transform-class-properties popularity was classified as popular.
We found that babel-plugin-transform-class-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.