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 mixins support to the _decorate helper #9166
Add mixins support to the _decorate helper #9166
Conversation
4038db5
to
91ffe20
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9599/ |
We could use decorators instead of mixins 😝
If I understand it correctly it might be hard though at some point when there are multiple mixins and they all have to stay compatible to each other. I guess at least we can make sure they will always be applied in the same order. We should make sure we have enough runtime tests for all the combinations. But as I said I don't know much about helpers nor about the concrete status of the decorators proposal. |
Yeah exactly, the number of possible combinations will grow exponentially. I guess we should just be good and write all the needed tests. |
I'm merging this so that I can rebase the privates and initializers PRs, and because the actual changes are quite small: babel/packages/babel-helpers/src/helpers.js Lines 1233 to 1238 in 91ffe20
If you have any concern, we can follow-up. |
This reverts commit 9d1d0fe.
The decorators transform has a very big runtime helper: almost every change to the proposal will impact the runtime behavior.
There are already different cases where we shouldn't enable some decorators functionality by default:
class-properties
orprivate-methods
plugins are enabled. Also, there should be two different versions: spec and loose.I considered three ways of handling this runtime flags:
_decorate
helper and implement everything there.Pro: It is probably easier to maintain
Con: The helper will became bigger and bigger, since we will need to include, at least, 1. initializers, 2. spec PrivateName, and 3. loose PrivateName
Con: It won't scale well with different runtime flags
_decorators
helper using completely separated helpers, using mixins. This is what I implemented in this PR.Pro: Only needed helpers will be added to the output code.
Con: Harder to maintain that option 1.
I rewrote #9008 using this new pattern, you can see how it works at nicolo-ribaudo/babel@66cbf54
How to review this PR:
The only meaningful changes introduced by this PR are inside the
_decorate
function. Everything else is just moving all the functions to theapi
objects and change function calls from_foo()
tothis.foo()
.What is most important is whether you think that this mixins pattern is ok or not.