You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that the <Class Name>.#<static private field/method> notation is within the lexical scope of <Class Name> - Checked during transform
Check that the this.#<static private field/method> has a provenance of <Class Name> - See Subclassing Hazard in the slides (around slide 13) - Checked at runtime
ESTree/Parsing
For the static keyword, we use the existing parser
For the # character, we use (or enhance) the existing parser (thanks to the work done in Class private properties #7842 - Class private properties)
Transform
Public
Public static fields/methods will be added to the <Class Name> object
Accessors will be added using Object.assign
Private
Transform to use helper functions similar to private instance fields: classStaticPrivateFieldGet and classStaticPrivateFieldSet
Add an in-closure _<static private fields/method> variable outside of the class that will be manipulated by the helper functions
Here is a potential output of the two last examples put together, in order to explain how to achieve privacy:
Static Class Features: Stage 3
Proposal co-written with @tim-mc and @robpalme. We also intend to follow up and implement it with @rpamely, @tim-mc, @mkubilayk .
Info
Proposed at TC39 Meeting: May 2018
Slides at the meeting: https://docs.google.com/presentation/d/1YzFr7EIGiX2YagfFMjkI-lVR6ouoRfPbTNLY--NGbC4/edit?usp=sharing
Proposal Repo: https://github.com/tc39/proposal-static-class-features/
Complete article on the subject by Shu-yu Guo: https://rfrn.org/%7Eshu/2018/05/02/the-semantics-of-all-js-class-elements.html
Babel contribution recommended by @jridgewell to @robpalme
The work to be done towards Stage 3 will be added in
plugin-proposal-class-properties.Examples
Static Public Fields
Static Public Methods
Static private fields
Static private methods
Basic Rules
<Class Name>.#<static private field/method>notation is within the lexical scope of<Class Name>- Checked during transformthis.#<static private field/method>has a provenance of<Class Name>- See Subclassing Hazard in the slides (around slide 13) - Checked at runtimeESTree/Parsing
statickeyword, we use the existing parser#character, we use (or enhance) the existing parser (thanks to the work done in Class private properties #7842 - Class private properties)Transform
Public
<Class Name>objectObject.assignPrivate
classStaticPrivateFieldGetandclassStaticPrivateFieldSet_<static private fields/method>variable outside of the class that will be manipulated by the helper functionsNote that those implementation details are not final but a way to start the conversation and the actual implementation.
cc @jridgewell, @robpalme, @rpamely, @tim-mc, @mkubilayk