-
Notifications
You must be signed in to change notification settings - Fork 358
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
Decorators on exported classes #315
Comments
As for I believe the |
I wonder if we could simply this a bit by using the orphan approach for both? I'm not a fan of having Would it make sense to have the start of a class declaration always be at the |
As long as we consistently specify that for the class elements' decorators as well, I am personally fine with it, though an element's decorators share the same evaluation scope with its key. As for now Babel will stay the current approach where a class / class element may start with |
Yeah this is why I raised it - given this spec is an agreement between tools - I'm happy with whatever solution as long as we agree to implement it that way! The orphan approach is fine for me because that's how we already implement it! If we want the non-export case to be orphaned too then I'm happy to make that change. Its probably easier that way as its always consistent then |
Yes, I think this makes sense. The consistency seems important here (at least, to me). @JLHwung do you think it's possible for Babel to re-evaluate the approach taken before decorators reach stage 4? |
@nzakas That ship has long sailed. It has been implemented in Babel for a long time anyway, and it supports Babel's transform well. We would like to avoid orphan nodes that start before their parent node. Currently, the exception case in Babel is I also checked the typescript AST: Both decorated class and class element start at |
Okay, then I guess that's the way it has to be. In the future, I recommend we include discussion of source ranges in proposed ESTree additions so we can surface those issues early. |
Yeah issue is that both babel and TS have had decorators since long before the thought of standardising an experimental AST in here was a twinkle in our eye! The AST we use now is the same as before, given that the switch from the old, experimental decorators to the new almost standard ones didn't include any real syntax changes. So we're stuck with the decisions of the past here. It should be possible for typescript-eslint to migrate to babel's approach - it should be a small change to make but a breaking change for a major release. |
Yeah, the history of ESTree is the history of one implementation getting ahead of others and then whoever is most flexible adapts to that. A lot of the weirdness in ESTree is a direct result of this. Before closing this out, it seems like we should add guidance about the expected syntax ranges to the decorators section? |
These are both valid syntax in the spec https://github.com/tc39/proposal-decorators?tab=readme-ov-file#syntax
The difficult thing is handling the locations. The decorator is owned by the class declaration, not the export declaration.
Accordingly the current estree spec https://github.com/estree/estree/blob/master/stage3/decorators.md places the decorator on the class and never the export. Which makes complete sense.
However when one is calculating the "range" / "location" for the class - things get tricky. The class includes the decorator but the decorator lies before the class's parent node. You can't really expand the class's range to include the decorator because that would include the export node as well. But if you don't do that then instead the decorator becomes an orphan of sorts.
I know that estree doesn't technically spec out the location side of things - but given this is something all tools need to implement it bears a discussion at least.
How should this case be handled?
Currently both babel and typescript-eslint go the orphan approach.
The text was updated successfully, but these errors were encountered: