-
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
Change finishers to be normal element descriptors. #177
Comments
Interesting idea. This would definitely leave a clearer path to instance finishers in the future. Any thoughts from others? Cc @rbucktpm @wycats |
Does this remove any capabilities from the existing design? |
No it doesn't. It actually adds a feature*: it makes it possible to replace a class element with a finisher. * More than a feature, it is a side-effect of the symmetry with the other |
I'm not opposed to a As far as using a finisher as a way to replace a property, I'm wondering if the return value from a member decorator couldn't just be an array of descriptors (and we could get rid of the OT: I'm confused. When did we add |
👍👍👍👍👍👍👍👍👍👍👍 Yes please
There were a few reasons:
class A {
@useSetInsteadOfDefine x = 1;
y = this.x;
} If
|
About expressivity, wouldn't using a no-op initializer get you the same thing? @wycats told me that he previously considered returning an array of descriptors, and rejected this option for several reasons. One issue that comes to mind for me is, if there is a subsequent decorator, what do we apply it to? |
This is one of the reasons that stage 1 decorators never gave you the option of removing a member (including changes to the key), only changes to the property descriptor. This is also problematic if you can return a "finisher" descriptor in the member's place. Do the remaining decorators run against the "finisher"? This seems like a footgun for users who might only be expecting a class or member descriptor. |
One option: If you return just a finisher (or initializer), throw a TypeError if there's a subsequent decorator. The more I think about this change, the more I like it. Does anyone have strong objections to it? Would anyone be interested in writing up a PR? |
I am ok with it, but probably we should also throw with initializers? |
@rbuckton We discussed initializer in #44, merged it in #165, and then I presented on it in the November 2018 TC39 meeting (slides). I believe it's essential for v1 decorators to avoid the "dead private field" idiom that several people have been advocating, which is likely to cause un-optimizable space overhead in practice. I am thinking that we should go ahead and make this change to finishers, as proposed by @nicolo-ribaudo, before moving to Stage 3. Any concerns? |
This was done in #199 (together with name changes). |
Conceptually, finishers are like initializers but they run at a different time (and they can alter the class declaration value). However, they are declared in two different ways:
I propose to declare finishers like normal element descriptors:
The text was updated successfully, but these errors were encountered: