-
-
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
Add helpers.wrapCtor
to fix T7328
#3582
Conversation
A couple concerns on this:
At the moment, we have https://github.com/loganfsmyth/babel-plugin-transform-builtin-extend which allows for extending real ES6 classes by using |
I can tweak the implementation.
I don't believe that a doable solution. Node 4 has built-ins like |
Current coverage is 87.71%@@ master #3582 diff @@
==========================================
Files 194 194
Lines 8949 9464 +515
Methods 1007 1070 +63
Messages 0 0
Branches 2004 2157 +153
==========================================
+ Hits 7829 8301 +472
- Misses 1120 1163 +43
Partials 0 0
|
Would you be up for me taking your example code and including it as a third option for https://github.com/loganfsmyth/babel-plugin-transform-builtin-extend/blob/master/src/index.js? I do think we can explore this more, but it's definitely not clear that there will be an easy way to land this as part of Babel 6 core. |
Is the issue that it's currently in Should the fix be moved to another part of the code base? |
The two points from before are my core concerns. I don't know how to do this in the general case without |
So with that are there any other concerns? Would moving the fix to a separate |
To try to elaborate more on this, the very fact that this is such a hard thing to do (and do well), to me at least, indicates that it's a better fit for an opt-in feature implemented as a plugin. Babel has always had this as one of the caveats called on in our docs: https://babeljs.io/docs/usage/caveats/#classes, and we provide the extra plugin for the cases where users do want to do this. As can be seen from your proposed implementation, getting this right is non-trivial. It requires non-standard functionality that not all ES5 environments support, combined with what amounts to a whitelist of class names to keep the performance acceptable. What's your motivation for pushing back so strongly against the existing plugin approach? I agree it's not perfect, but it seems much more desirable for Babel core to be consistent. |
It can be as simple/detailed or clean/ugly as you all would like. I'm just kicking stuff around to see what meets an acceptable bar.
It's not hard to do it right-ish.
It's using standard lang features. The same features that are already being used for class inheritance wiring. Listing of a handful spec'ed constructors is just one way to manage it.
It's core functionality that's simple enough to tackle in a few lines (~220bytes) vs. a significantly more complex and heavy plugin is all. Is there a perf goal you're trying to stay within or a benchmark to reference? |
I admit I don't understand what's heavy about the plugin specifically. In your wrapper case, if someone isn't using
Perf-wise, my main concern is avoiding the I definitely have concerned about rollout. If we wanted to get this into Babel 6 without separate plugin, I think it would have to be an opt-in feature via an option on the transform, since we don't have a great way to incorporate new helpers into things without causing regressions in existing installs. It seems doable with an opt-in You know more about this than I do, but would an approach more along the lines of
be shorter and more consistent? Part of my concern with the whitelist and I also definitely want feedback from others on this. |
It requires shimming class MapCache extends Map {
clear() {
super.clear();
return this;
}
}; is transpiled into 9kB (min+gzip) of support code using
This will only add the helper if they use
Cool!
Sounds like a great start!
I played around with
We could modify the |
Did a solution to this issue ever get merged or is it still outstanding? Is the following statement true: "it is currently not possible to instantiate a native ES class which extends a babel-transpiled ES class under Node.js v6"? Based on all my testing, the answer is "yes", which was pretty alarming to realize. |
This is still an issue for me. Is this going to be merged in soon? |
Going to close in favor of #4480 (comment) |
Ah neat! @WebReflection Thank you! |
This PR adds
helpers.wrapCtor
to fix T7328.edit:
Fixes #4269