-
Notifications
You must be signed in to change notification settings - Fork 149
Support static fields in class transform #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah, static methods and fields are currently not supported. |
I really appreciate you guys making this. You have saved me so much time. |
Adding support for static fields is currently problematic as this is not part of official ECMAScript syntax and Espree parser (which Lebab uses) doesn't support it. Supporting static methods should be simpler. At least as long as they are attached to functions that also have methods in their prototype: MyFunction() {}
MyFunction.prototype.doX = function(){}
MyFunction.staticX = function(){} When a function has no methods defined in its prototype we currently don't detect it as a class. I think that won't change with static methods - without the prototype it's a bit too vague of a guess whether it should be a class or not. So the following would not be transformed: MyFunction() {}
MyFunction.staticX = function(){} Similarly a common pattern in e.g. Java is to have a class with only static methods, while in JavaScript one would just write an object: const MyStaticObj = {
staticFoo() {},
staticBar() {}
}; This too would be left as-is. @seanrowe if you have some example real-world code with ES5 static methods that you could share, that would be helpful (just to gather some additional real-world examples). |
When you have code like
ClassName.someFunction = function() {}
It does not become a static method in the class.
Also, if you have code like this
Object.defineProperty(ClassName, "variableName", { value: true })
it does not become a static variable of the generated class.
The text was updated successfully, but these errors were encountered: