Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Spec: Static private methods? #37

Closed
rwaldron opened this issue Aug 6, 2018 · 3 comments
Closed

Spec: Static private methods? #37

rwaldron opened this issue Aug 6, 2018 · 3 comments

Comments

@rwaldron
Copy link
Contributor

rwaldron commented Aug 6, 2018

From README.md:

This proposal adds three features to JavaScript classes, building on the previous class fields and private methods proposals:

  • Static public fields
  • Static private methods
  • Static private fields

But the specification itself doesn't appear to include anything to support "Static private methods". The new grammar:

    static FieldDefinition [?Yield, ?Await] ;

Expands to:

    FieldDefinition [Yield, Await] :
        ClassElementName [?Yield, ?Await] Initializer [In, ~Yield, ~Await] opt

    ClassElementName [Yield, Await] :
        PropertyName [?Yield, ?Await]
        PrivateName

    PrivateName ::
        # IdentifierName

Which means that a static private method cannot be produced by this grammar; only a static private field can be produced by the grammar defined in proposal-class-fields, with the addition made to the ClassElement production:

    static FieldDefinition

    static ClassElementName Initializer

    static PrivateName Initializer

    static #IdentifierName Initializer

@littledan
Copy link
Member

My intention was that removing the early error in https://tc39.github.io/proposal-static-class-features/#sec-static-semantics-early-errors would be sufficient. I believe the instance private methods grammar already supports static private methods, except for this error.

@rwaldron
Copy link
Contributor Author

rwaldron commented Aug 8, 2018

I believe my misinterpretation was the result of confusion while navigating the multiple inter-connected specs. When I reviewed this: https://tc39.github.io/proposal-static-class-features/#sec-static-semantics-early-errors and saw there was no definition of PrivateBoundNames in that spec, I went to the "base" proposal-class-fields spec and found PrivateBoundNames, where I read:

    ClassElement :
        MethodDefinition ;

    ClassElement :
        static MethodDefinition ;

    ClassElement :
        ;

    1. Return a new empty List.

So then I opened proposal-private-methods and did control-f for "PrivateBoundNames", which brought me directly to 1.2 Static Semantics: Early Errors, where I saw this:

    PropertyDefinition : MethodDefinition

    - It is a Syntax Error if PrivateBoundNames of MethodDefinition is non-empty.

At this point I'm not sure what happened... maybe I saw PropertyDefinition, but thought "PropertyName"?

Would you mind adding an Editor's note to https://tc39.github.io/proposal-static-class-features/#sec-static-semantics-early-errors that clarifies the removal of this error "enables" static private methods?

@littledan
Copy link
Member

This text is really obscure; you're probably not the only one confused. Thanks for the recommendation. It can be hard for me to see which parts of my own text are hard to read. I've added the note you suggested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants