tc39 / proposal-decorators

Decorators for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=2417
2.76k stars 106 forks source link

Clarification. Can auto-accessors be redeclared? #531

Closed lpardosixtosMs closed 5 months ago

lpardosixtosMs commented 5 months ago

I'm implementing the proposal in V8 and I'd like to clarify if public auto-accessors can be redeclared.

Step 5 of the second part of this section of the draft spec creates a new Private Name whose description is the concatenation of the field's readable name and the "accessor storage" string. Since this is a new Private Name and not one taken from the private env names list, I conclude that it wouldn't collide with other private names when calling PrivateFieldAdd on it; and as a consequence, the following snippet is valid JavaScript:

class C {
  accessor x = 1;
  accessor x = 2;
}

Is this the intended behavior?

pzuraq commented 5 months ago

Yes, this is the intended behavior, it should work like any other public element in most aspects, so redeclarations are allowed and overwrite the previous declaration fully. This also prevents something like a subclass somehow colliding with a parent class.

lpardosixtosMs commented 5 months ago

Thanks for the quick response!