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
Fix class inheritance in IE <=10 (T3041) #3527
Conversation
Interesting idea. Right now IE9/10 would be expected to use loose-mode to avoid this issue, but you are right this may be another approach. |
The problem with loose-mode for us is that we are not always in control how projects transpile their code. In the concrete example of babylon (which we use in the browser for our internal styleguide) we can't control the transpiling configuration it uses (currently it uses babel6 non-loose since v6.8). |
[ | ||
this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype")) | ||
] | ||
t.logicalExpression( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth making a simple helper function for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I extracted the logic into a helper within babel-helper-replace-supers
I would have liked to share this method also with the transform-class package, but not sure where to put the helper function then.
Current coverage is 87.44%@@ master #3527 diff @@
==========================================
Files 194 194
Lines 8949 9175 +226
Methods 1007 1024 +17
Messages 0 0
Branches 2004 2062 +58
==========================================
+ Hits 7829 8023 +194
- Misses 1120 1152 +32
Partials 0 0
|
Any progress on this? Both loose mode and "broken on IE 9 and 10" aren't fun places to be :-( |
Internet Explorer 9&10 do not support __proto__ at all, don't have Object.setPrototypeOf(), but have Object.getPrototypeOf(). Because of this setting the prototype is not possible, which makes the babelHelpers.inherits() function to set __proto__ although not supported. Afterwards Object.getPrototypeOf() is used, but this one is not respecting the "custom" property __proto__ that we set. The solution is to check for __proto__ first and afterwards fallback to Object.getPrototypeOf().
Fixes facebook#6929 See babel/babel#3527 for more details
We use Babel 6.26.0, which has been patched for this already; see babel/babel#3041 and babel/babel#3527
We use Babel 6.26.0, which has been patched for this already; see babel/babel#3041 and babel/babel#3527
Hello, Class inheritance does not work again in Any plans for IE9/10 supporting? |
Problem summary
Internet Explorer 10 and below do not support
__proto__
at all, they don't haveObject.setPrototypeOf()
, but they haveObject.getPrototypeOf()
.When babel is doing the inheritance it is trying to use
Object.setPrototypeOf()
if this function is available. As mentioned this function isn't available (even with core-js, as also core-js can't polyfill this). In this case the helper falls back to just set__proto__
on the object. For IE <=10 this is just some custom property that gets set on the target, with no special meaning.In the constructor after the inherit helper finished its work, babel uses
Object.getPrototypeOf()
to get the prototype. This is supported by IE, but as babel can't set the prototype on the target, this will just return the base Object-prototype and not the wanted superclass.Proposed solution
The solution simply changes the retrieval of the prototype by first trying to get
__proto__
and if not available falling back toObject.getPrototypeOf()
. This fixes the behavior in IE as babel reads the custom prop__proto__
that the inherit helper was setting. In all other browsers this should not have any effect, as__proto__
should be the same asObject.getPrototypeOf()
.Does anyone see a problem with this solution? Anything that I maybe have missed?
P.S.: I did not yet change any of the tests, as I wanted to get feedback first on the solution.