Skip to content

Normative: Remove PrivateName constructor from decorators#127

Merged
littledan merged 2 commits intomasterfrom
no-private-name-fn
Jul 11, 2018
Merged

Normative: Remove PrivateName constructor from decorators#127
littledan merged 2 commits intomasterfrom
no-private-name-fn

Conversation

@littledan
Copy link
Copy Markdown
Member

The constructor can be polyfilled in 5 lines of code; there may
be a cleaner way to include it in the standard library in the
future, or it may be made unnecessary in favor of certain future
syntax. Therefore, it is not necessary to pass it as the second
argument for all decorators.

This patch also updates the code samples in the documentation
(some of which was a bit out of date).

This PR addresses some comments by @caridy in #124.

The constructor can be polyfilled in 5 lines of code; there may
be a cleaner way to include it in the standard library in the
future, or it may be made unnecessary in favor of certain future
syntax. Therefore, it is not necessary to pass it as the second
argument for all decorators.

This patch also updates the code samples in the documentation
(some of which was a bit out of date).
Copy link
Copy Markdown
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include this in the presentation slides. It feels weird, but I'm not opposed since a native PrivateName instance can be extracted without much hassle.

this.#names.set(string, key);
return descriptor;
expose = descriptor => {
let key = descriptor.key;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it impossible here for the key to be null or undefined?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key will always be either a String, a Symbol, or a PrivateName.

friend.js Outdated
expose = descriptor => {
let key = descriptor.key;
let string = key.toString();
if (typeof key !== "privatename") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is privatename still a new primitive? I thought it was a normal object now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch, it's definitely an object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@littledan
Copy link
Copy Markdown
Member Author

@jridgewell Yes, I'll add a slide about this change (and #124)

@littledan
Copy link
Copy Markdown
Member Author

Given the positive response so far, I'll land this PR, but I'm still open to reasons to reconsider.

@littledan littledan merged commit 94af627 into master Jul 11, 2018
@nicolo-ribaudo
Copy link
Copy Markdown
Member

Btw, this will make the Babel implementation of PrivateName easier, since I had to implement a "public constructor" and an "internal constructor"

nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Jul 11, 2018
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Jul 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants