-
Notifications
You must be signed in to change notification settings - Fork 106
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
Clarification on field vs. method destination #529
Comments
This is intentional: #329
Also I wonder, can static private methods be called in any way when there is a class decorator that returns a subclass? |
This is intentional, class decorators should have access to the class when it is as complete as possible. The only reason that class decorators do not run after fields/static blocks is because you can end up in a split world, e.g. class C {
static f = new C();
}
const c = new C(); If decorators ran after fields are assigned, then Class extra initializers ( |
It seems like perhaps Babel's implementation of
One easy way to tell is that the getter (which can be accessed via Note: I'm using Firefox and it considers the code that Babel generates to be a syntax error (specifically |
(off topic for this discussion, I'll hide it when you react to this comment) Already reported, and it's already fixed in Firefox nightly I think :) When running with |
@pzuraq About |
@nicolo-ribaudo yes that was the intention, I think I misunderstood what the |
I don't see anything about decorators on the June agenda. Does this need to be added to that agenda for it to be addressed? Sorry, I'm not too familiar on how TC39 meetings work. |
@evanw unfortunately I didn't get around to making the updates in time. I don't work full time on TC39 stuff anymore unfortunately, haven't for the past couple of years, so I have been pushing along the spec on mostly personal time. I usually find a chunk of time every several months or so to do maintenance, address issues, etc. This last chunk was spent writing the tests for decorators in There are a few small updates like this one that need to make it into the spec, and that writing the tests has helped identify, so I'll be bundling those together for the next plenary after June. Hopefully now that we have tests, this will be the last round of updates. |
I'm currently working on writing some tests for decorators in preparation for adding support for them to esbuild. My reading of the specification is that decorators on the class itself can return a new object, which then becomes the ultimate value for the class binding. That happens in
ClassDefinitionEvaluation
here:When that happens, I believe that causes methods to end up on the old object (because they are added to the old value of
F
earlier) and fields to end up on the new object (because they are added to the new value ofF
later). Am I reading the specification correctly? Specifically methods are applied here:and fields are initialized here:
Note that this means accessors (which are methods that reference fields) end up being split between the old object and the new object, with the getter/setter on the old object and the storage field on the new object.
Is this intentional? Neither TypeScript nor Babel seem to do this. I wanted to check that my interpretation is correct and that this is by design before locking in my implementation and tests like that. I don't use decorators myself so I don't have any intuition for whether this is a useful thing to do or not. I'm just trying to make an accurate implementation of this specification. It just seems kind of weird that e.g. decorating a class could seemingly break all private accessors in that class.
For example:
The text was updated successfully, but these errors were encountered: