-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add Class and Class Element Decorators and accessor
Keyword
#2417
base: main
Are you sure you want to change the base?
Conversation
Rather than make a ton of "suggested changes" here, I've made a PR against the pzuraq:decorators branch. |
Since Decorators are only used with Class definitions, would it make sense to put the Decorators clause within the Class Definitions clause? |
They’re only used with classes for now- there’s lots of interest in follow up proposals to add them in other places. |
(I did look for follow-up proposals, but only found a couple at stage 0.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the following SDOs need to be modified to handle the new syntax for ClassDeclaration, ClassExpression, and/or ClassElement:
- BoundNames
- ClassElementKind
- ComputedPropertyContains
- Early Errors
- IsConstantDeclaration
- IsFunctionDefinition
- IsStatic
- PrivateBoundIdentifiers
- PropName
(Note that currently, 4 of the 5 RHSs of ClassElement are chain productions, and so often have implicit definitions for SDOs, but they aren't chain productions in this PR, and so will need explicit definitions.)
3d0c24c
to
7a79833
Compare
4e4deae
to
f210f0e
Compare
@jmdyck regarding this comment, I'm not quite sure I understand what needs to be done here. Why do these productions need to be updated exactly? |
Consider the production But this PR replaces that production with And likewise for the other alternatives of |
1. Let _scope_ be the LexicalEnvironment of the running execution context. | ||
1. Let _privateScope_ be the running execution context's PrivateEnvironment. | ||
1. Let _sourceText_ be the empty sequence of Unicode code points. | ||
1. Let _initializer_ be ! OrdinaryFunctionCreate(%Function.prototype%, _sourceText_, _formalParameterList_, _Initializer_, ~non-lexical-this~, _scope_, _privateScope_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an initializer x = 123
it will return a function with the proper env and private env.
function () {
= 123
}
The result function does not have a valid Body (the Initializer is passed in).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still an issue? Not sure I understood it, I would think that this is a syntax error
Still working on addressing the feedback items, but I made a number of updates so far and wanted to get those updates up so folks could start reviewing sooner rather than later. Updates since last draft:
Open Todos
Sidenote: It would be really nice to put comments inline in the spec to clarify the thinking for a specific portion, unsure if that's a feature anyone would be interested in? |
PR has been rebased, I squashed the existing commits to make rebasing easier overall. The only new commit contains non-normative fixes. The remaining issues open in this thread are all normative I believe, and I will be opening up separate PRs for each of them so we can discuss at the upcoming plenary. |
Hi, esmeta typecheck is failing because
Changing the return type of |
Class field accessors are part of the decorators proposal. tc39/ecma262#2417
Class field accessors are part of the decorators proposal. tc39/ecma262#2417
Updates - Refactor to use ClassElementDefinition more extensively - Separate parsing class elements and defining them so that we can control the order of definition and decorator application - Extract and centralize class element decoration into a single place - Fix completions in ClassDefinitionEvaluation (need to reset the env after each possible abrupt completion). - Refactor adding private methods to instance to pull directly from `Class.[[Elements]]`, so we don't have multiple sources of truth for the elements that are defined on a class. `Class.[[Elements]]` is the canonical source of truth after ClassDefinitionEvaluation, and any operations afterward such as instantiation should base themselves on that. - Refactor to use anonymous function syntax. Non-normative fixes Fixes based on feedback from @jmdyck Remove dynamic [[HomeObject]] from decorator return values Throw an error if the value passed to `addInitializer` is not callable Set the name of the `addInitializer` function Remove setFunctionName from decorator application Call decorators with their natural `this` value. For more details, see this issue: tc39/proposal-decorators#487 Reverse initializer order Update field and accessor extra initializers to run after definition
PR has been updated and rebased, and all changes have been addressed! |
The DecoratorDefinition type is a Record used in the specification of | ||
decorators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DecoratorDefinition type is a Record used in the specification of | |
decorators. | |
The DecoratorDefinition type is a Record used in the specification of decorators. |
are defined by | ||
<emu-xref href="#table-decoratordefinition-fields"></emu-xref>. Such | ||
values are referred to as | ||
<dfn variants="DecoratorDefinition Record">DecoratorDefinition Records</dfn>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we soft-wrap pretty consistently, not hard-wrap
1. If _kind_ is ~method~, then | ||
1. Let _kindStr_ be *"method"*. | ||
1. Else if _kind_ is ~getter~, then | ||
1. Let _kindStr_ be *"getter"*. | ||
1. Else if _kind_ is ~setter~, then | ||
1. Let _kindStr_ be *"setter"*. | ||
1. Else if _kind_ is ~accessor~, then | ||
1. Let _kindStr_ be *"accessor"*. | ||
1. Else if _kind_ is ~field~, then | ||
1. Let _kindStr_ be *"field"*. | ||
1. Else, | ||
1. Assert: _kind_ is ~class~. | ||
1. Let _kindStr_ be *"class"*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside for the editors: kind of feels like we need a SpecValueToString()
AO or something for cases like this. i think atomics has one too.
1. Let _existing_ be *undefined*. | ||
1. If _privateMethods_ contains a PrivateElement _e_ such that _e_.[[Key]] is _element_.[[Key]], then | ||
1. Assert: _e_.[[Kind]] is ~accessor~. | ||
1. Set _existing_ to _e_. | ||
1. If _e_.[[Get]] is not *undefined*, set _getter_ to _existing_.[[Get]]. | ||
1. If _e_.[[Set]] is not *undefined*, set _setter_ to _existing_.[[Set]]. | ||
1. Let _privateElement_ be PrivateElement { [[Key]]: _element_.[[Key]], [[Kind]]: ~accessor~, [[Get]]: _getter_, [[Set]]: _setter_ }. | ||
1. If _existing_ is not *undefined*, replace _existing_ in _privateMethods_ with _privateElement_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that steps 6 through 9 define a no-op if there is already a private accessor pair with a setter and a getter and the same key, is this correct? If so, could we reword 7.c and 7.d? It seems a little strange to use _e_
and _existing_
in the same line when _existing_
was set to _e_
in the previous step.
<emu-clause id="sec-applydecoratorstoelementdefinition" type="abstract operation"> | ||
<h1> | ||
ApplyDecoratorsToElementDefinition ( | ||
_homeObject_: an Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like _homeObject_
is not used here.
This PR includes the spec changes for the current iteration of the decorators proposal. This proposal is still in progress, currently in stage 2, and the PR is mainly being opened for reviewing and iteration purposes.