-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Lexer: Backticks should allow adding code to class body #4464
Comments
See also coffeescript6/discuss#17 |
Recommended escape valve atm would be to use class A
Object.defineProperty @prototype, 'x', get: -> 42 |
After reading that other thread I understand all the objections to mucking around with syntax, and yeah, just going back to ES5 works (though now I'm doing the job my transpiler is supposed to do for me!) However, I would think that on general principle, there should be some backtick-esque escape valve for getting stuff inside of the inner class body. |
Perhaps this issue should be more about “backticks should allow inserting code into class body” or whatever you call the area that’s not the executable class body? And we can keep the other issue for discussing adding support for getters/setters. |
If done right, you could probably kill both birds with one stone. If my example C wasn't a syntax error, but instead caused the backticked code to be directly inserted into the class body, you would have solved both getters and decorators. I think it might also bypass the grammar ambiguities referenced int he other thread too, but I am not familiar with the CS lexer so I could be wrong about that. |
Well we never want to require people to use backticks. We went through the trouble of adding support for Decorators is an unusual case as the spec isn’t finalized yet, and it’s our policy not to support unfinalized specs. So backtick support for what you’re talking about would be a good thing to have, so that people can use decorators until the spec is finalized and then we add native support for them. |
I think if it could be made to work, it would be a winning move on the whole, even if you went on to add a full syntax for getters and setters later.
|
…ft in the body, not hoisted
See #4668. That PR would allow your example E. |
… the initializer
…ft in the body, not hoisted
This uses more of the existing machinery for moving class body expressions into the initializer.
This uses more of the existing machinery for moving class body expressions into the initializer.
Closed prematurely. |
No worries. I think the comment should also say something along the lines of “class properties and class fields go here when they reach Stage 4.” I found such comments very helpful when updating things for CS2. |
ES2015 spc allows method definitions to be prefixed by
get
orset
in which case they are transformed to property getters and setters.Of the following, only A generates the corresponding ES2015 output:
B makes a hoisted class body (as expected), C and D are syntax errors, and E, which would seem like it should be the ultimate escape valve, generates a hoisted class body as well.
It would be nice to have some kind of escape valve for modifying the definitions within the non-hoisted portion of ES2015 class body. It would be particularly nice if backticks could be made to serve this function, as they can help support other possible future syntax (e.g. decorators) as well.
The text was updated successfully, but these errors were encountered: