-
Notifications
You must be signed in to change notification settings - Fork 48.6k
Issues with ES6 classes #2575
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
This seems to be a bug in 6to5. Methods in ES6 classes should be enumerable. Please report it to the 6to5 project. |
It seems that methods are not enumerable on ES6 classes.
|
That document is outdated. AFAIK, the spec draft has changed since then.
|
Yes it would seem so, however on IE 11 preview and Chrome 39, it seems that still class methods are not enumerable. var Y = class H {
render() {
return null;
}
};
var G = new Y();
G.propertyIsEnumerable('render');
> false Happy Thanksgiving, BTW. |
Also in the latest upcoming ES6 draft (October 2014), it seems that the PropertyDescriptor of methods on a class are as
So it seems that class methods are not |
The first one is just the constructor which is not enumerable. The rest of the elements uses PropertyDefinitionEvaluation which SHOULD make them enumerable.
|
I will report this to 6to5 as well as the browser vendors. |
Should this be re-opened because of the latest announcement given below ? Unfortunately/fortunately, 6to5 already made necessary changes to make them not enumerable. React version being used: 0.12.2.
The above code generates a prototype object with the above given methods as properties. But, |
@sebmarkbage Any thoughts ? |
@mvpspl619 FWIW you can pass the |
@ToucheSir Thanks. As that's a temporary way to make React work with ES6, I am curious to find out if anything is being done on this front to make React work with ES6 non-enumerable class methods in the future release ? |
The problem with enumerability is that it can't be polyfilled in old IE (we still support IE8). Both the detection and definition. If we want to support IE8 we don't want there to be different React behaviors depending on which browser you use, so we can't depend on detecting enumerability. Otherwise someone may accidentally rely on it working, yet in IE8 it will break (and nobody properly tests IE8 these days). Luckily, we have first class support for ES6 classes in 0.13. http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html |
@sebmarkbage Thanks for that. I have dependency problems with react-router and react-async for using [email protected]. Trying to figure out a solution. |
@sebmarkbage http://facebook.github.io/react/blog/2015/02/24/react-v0.13-rc1.html states that class methods are no longer enumerable by default. This will break a lot of tests (as jest relies on this property) in one of my projects. Are you aware of any workaround? |
There is a flag to turn it back to the old behavior as a workaround until we can get it fixed in jest. |
In your preprocessor |
@zpao Thanks for the @sebmarkbage Is there an issue to track in the jest project? |
This issue occurs now with Traceur since this bug fix : google/traceur-compiler#1873 |
I'm having issues with ES6 classes in React. It seems that esprima-harmony differs from how 6to5 is implementing classes, as well as how classes are implemented in beta versions of browsers.
With esprima-harmony I am able to use classes (using
React.createClass(MyClass.prototype)
), however,If I use any of these methods:
with 6to5
In Chrome 39 and IE11 Windows 10 Preview
I get this error:
Error: Invariant Violation: createClass(...): Class specification must implement a
rendermethod.
. And if I try usingReact.createFactory
in 6to5 I get this error:TypeError: undefined is not an object (evaluating 'nextElement.props')
.I can't figure out what would be so different between Object.defineProperty and directly defining prototypes, other than the fact that properties set on the prototype aren't automatically enumerable.
ES6 code
esprima-harmony compiles:
6to5 compiles:
How should I resolve this issue?
The text was updated successfully, but these errors were encountered: