-
Notifications
You must be signed in to change notification settings - Fork 14
Transform private named instance fields #15
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
Transform private named instance fields #15
Conversation
@@ -621,6 +621,9 @@ declare namespace ts { | |||
type?: TypeNode; | |||
initializer?: Expression; | |||
} | |||
interface PrivatePropertyDeclaration extends PropertyDeclaration { |
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.
since this is public API:
- maybe we don't need another interface for this
- if we keep it,
PrivateNamedPropertyDeclaration
is probably more accurate, since there are already private properties
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 don't have a strong opinion on the interface, but I'm with Max on the name. "private-named" is our official shortest adjective for this.
@@ -621,6 +621,9 @@ declare namespace ts { | |||
type?: TypeNode; | |||
initializer?: Expression; | |||
} | |||
interface PrivatePropertyDeclaration extends PropertyDeclaration { |
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.
@@ -3637,6 +3637,10 @@ namespace ts { | |||
let excludeFlags = TransformFlags.NodeExcludes; |
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.
@joeywatts I think we can merge this soon. Would help if you could:
- add a little bit more to the PR description:
- what were some judgment calls or design decisions made in this PR?
- are there outstanding issues with private-named fields not covered in this PR?
- please note that this PR builds on Keep class properties in ESNext target #10
- rebase this down to a few smaller commits
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.
✔️
/** | ||
* A mapping of private names to information needed for transformation. | ||
*/ | ||
type PrivateNameEnvironment = UnderscoreEscapedMap<PrivateNamedInstanceField>; |
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.
as discussed, we will fiddle with this structure more in subsequent PRs (so that methods + static methods + getters can share the same WeakSet of instances)
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 good.
@@ -621,6 +621,9 @@ declare namespace ts { | |||
type?: TypeNode; | |||
initializer?: Expression; | |||
} | |||
interface PrivatePropertyDeclaration extends PropertyDeclaration { |
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 don't have a strong opinion on the interface, but I'm with Max on the name. "private-named" is our official shortest adjective for this.
b416c58
to
4f59597
Compare
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.
psyched about this
4f59597
to
2641392
Compare
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
2641392
to
fa17cdf
Compare
Downlevel transform for ESNext private named instance fields. Uses WeakMaps to store the value for each private field, and helper functions to access and mutate the field.
Design Notes (and Insights for Implementation of Private Named Methods, Accessors, etc)
++
,--
) piggy-back off of the instance field access and assignment transformations by first transforming to an intermediate representation and then transforming that.this.#x++
will first transform tothis.#x = this.#x + 1
and then will finally transform to_classPrivateFieldSet(this, _x, _classPrivateFieldGet(this, _x) + 1)
. So for private named get/set accessors, if the access and assignment transformations are implemented, most things should just work! Another example of this is the transformation of call expressions on private names,this.#myFunc()
will first transform tothis.#myFunc.call(this, /*...args*/)
then it will rely on the private name property access transformation to perform the rest of the work. If property accesses are implemented for private named methods, then calling them should just work!