-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Class properties should be copied over when inheriting #2450
Comments
You can either override |
Thanks. Do you not think this is a useful default? |
As in, copy the properties by default? |
At least if (And maybe in loose mode even when it is? Supposedly setting prototypes is slow. I haven't been following Babel 6 so I don't know if you even have something called "loose mode" any more.) |
Not convinced that implementing your own If it changes behavior between IE10 and other browsers, you'll end up with weird bugs. Personally, I prefer being consistent than compliant for production code. IE10 is still a very much alive unfortunately. However, the perf argument is probably even better since that affects a lot more users. |
Is there a usecase that the plugin I linked doesn't cover? It will replace |
(As a little more context: We were planning to set |
Using that plugin means you can't feature-test for and use Object.setPrototypeOf in your own code, doesn't it? @sebmarkbage suggested doing the transformation only for classes (only for the inherits helper). |
There is also babel-plugin-proto-to-assign. I'm somewhat torn on this. I understand the desire for it to "just work". Most of us have to support IE 10 - there just isn't an option. The solutions mentioned adds a lot of friction. Especially for @spicyj and his team who then have to educate React developers who use babel to properly transform their helpers. Copying breaks inheritance. So it shouldn't be "always-on" as that would break code in other platforms. However, falling back to copying might not be such a bad thing, if developers are made aware of the caveats. One way to handle this is by throwing warnings when static properties are used, which link to the caveats of using static properties in IE 10 and below. That could be done using an on by default plugin. To silence the warnings you could either blacklist that plugin or provide a comment annotation where the warnings occur. |
Nope. I'm not sure if that's an issue since you're forgoing proper semantics anyway in favor of your copy method
I don't think that having different semantics for static inheritance is a very good idea. Especially when you can achieve what you want reliably and across all possible environments through other methods. |
Quick question, is babel-plugin-proto-to-assign always a plugin? Doing like it says here (putting it in optionals) doesn't seem to work. I can't get IE <= 10 to work anyway, but at least my |
I'm having a similar problem with IE <= 10, but worse. It seems like I can't call parent constructors anymore on babel 6 because the call gets transpiled to I've tried using babel-plugin-transform-object-set-prototype-of-to-assign, but it didn't work. I think it's because the I'm commenting on this issue instead of creating another one since it's due to the same cause, but it's a different consequence. |
@mairatma |
This code logs
5
in most browsers, butB.foo
is undefined in IE10 and older:This happens because core-js doesn't define Object.setPrototypeOf if the browser doesn't support
__proto__
so this line does effectively nothing:babel/packages/babel/src/transformation/templates/helper-inherits.js
Line 13 in 8ab4a5d
Perhaps the static properties could be copied instead? That's what jstransform did.
cc @sebmarkbage
The text was updated successfully, but these errors were encountered: