tc39 / proposal-static-class-features

The static parts of new class features, in a separate proposal
https://arai-a.github.io/ecma262-compare/?pr=1668
127 stars 27 forks source link

Spec: Static private methods? #37

Closed rwaldron closed 6 years ago

rwaldron commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.