Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add support for class private methods #703
This adds support for private methods, as described in https://github.com/littledan/proposal-private-methods.
I haven't made an issue for this proposal yet, but if we want it to be separate from #540, I can do so.
I'll also need to submit changes to
NOTE: There's still a little bit I'm not exactly sure about (tick means handled):
littledan left a comment
This seems like a correct implementation of the grammar to me!
One surprising thing to me here, which I unfortunately missed in the earlier Private Fields PR, is that there's no single AST node for a private name. Instead, an Identifier is used inside of various different node types--previously, ClassPrivateProperty and PrivateName, now also ClassPrivateMethod. I would've expected that ClassPrivateProperty and ClassPrivateMethod would contain a PrivateName which contains an Identifier, instead of directly containing the Identifier.
I assume that the private methods plugin will be responsible for throwing early errors (such as duplicate method definitions); is that right?
I appreciate the tests here. Although I can think of some more tests for syntax edge cases, maybe those are best developed in test262.
bakkot left a comment
If I'm reading it right, this allows methods and fields named
Otherwise looks good to me.
I've done some updates to the PR -- will squash later once review done.
While I'm at it, I'm just wondering whether the one test failure is important or not.
This roughly equivalent non-private code just throws
Do we need it to check whether a semicolon should be there, and if so, how would I go about doing that?
This commit adds parser support for the TC39 Stage 2 Private Methods proposal. This commit also changes "key" in ClassPrivateProperty from an Identifier to a PrivateName, as well as disallowing #constructor as a valid private field name.
This also removes a test from the Test262 whitelist that failed before the changes for private methods support and now passes.