Fix issues with duplicate key logic#79
Conversation
spec.html
Outdated
| <emu-alg> | ||
| 1. Let _extras_ be a new empty List. | ||
| 1. Let _finishers_ be a new empty List. | ||
| 1. Let _placementKeys_ be *undefined*. |
There was a problem hiding this comment.
I think that it should be ~empty~, since *undefined* is the JavaScript value. Also, maybe it can just be used
1. If _element_.[[Placement]] is `"own"`, let _placementKeys_ to _keys_.[[OwnKeys]].
...
without declaring _placementKeys_ first.
spec.html
Outdated
| 1. Else if _element_.[[Placement]] is `"static"`, then | ||
| 1. set _placementKeys_ to _keys_.[[StaticKeys]]. | ||
| 1. Else, | ||
| 1. set _placementKeys_ to _keys_.[[PrototypeKeys]]. |
There was a problem hiding this comment.
Since this if/else if/else steps are used different times, maybe we can extract them into a different "function"?
e.g.
1. Let _placementKeys_ be GetPlacementKeys(_keys_, _element_.[[Placement]])
There was a problem hiding this comment.
I didn't want to pollute the spec with an additional tangential function.
There was a problem hiding this comment.
Personally I’d prefer more abstract operations if it can clean up the algorithms, but generally it’s best to only do so when things are very complex or needed in more than one place.
ac4a9ad to
86d108b
Compare
spec.html
Outdated
| 1. Append _element_.[[Key]] to _keys_. | ||
| 1. Perform ? AddElementPlacement(_element_, _placements_). | ||
| 1. For each _element_ in _elements_, do | ||
| 1. Let _elementFinishersExtras_ be ? DecorateElement(_element_, _keys_). |
There was a problem hiding this comment.
Should you pass placements rather than keys here?
| 1. Assert: _element_.[[Key]] is an element of _keys_. | ||
| 1. Remove _element_.[[Key]] from _keys_. | ||
| 1. For each _decorator_ in _element_.[[Decorators]], in reverse list order do | ||
| 1. Perform RemoveElementPlacement(_element_, _placements_). |
There was a problem hiding this comment.
This process of removing and re-adding the elements will change the enumeration order, e.g. extras may precede the element. Is this intentional?
There was a problem hiding this comment.
This doesn't change order at all. placements are just bags of property names.
|
I made an additional change to not throw a TypeError when initially creating |
|
@littledan I've addressed PR feedback and fixed merge conflicts with master. Can you take another look? |
| 1. Let _placements_ be the Record { [[StaticKeys]]: « », [[PrototypeKeys]]: « », [[OwnKeys]]: « » }. | ||
| 1. For each _element_ in _elements_, do | ||
| 1. Append _element_.[[Key]] to _keys_. | ||
| 1. Perform ? AddElementPlacement(_element_, _placements_, *true*). |
There was a problem hiding this comment.
Initially I assumed that elements was already deduplicated from CoalesceClassElements, so it would be fine to reuse AddElementPlacement as it wouldn't introduce an error for user-supplied declarations. However, upon rereading that algorithm it seems that we don't coalesce field initializers, so there exists the possibility of user-written duplicates. Since this mechanism is only to prevent decorators from adding a duplicate definition, I've modified AddElementPlacement to accept an optional silent argument to suppress errors when we initially create placements.
There was a problem hiding this comment.
Good call, makes sense to me.
littledan
left a comment
There was a problem hiding this comment.
Thanks for thinking this all through.
| 1. Assert: _element_.[[Key]] is an element of _keys_. | ||
| 1. Remove _element_.[[Key]] from _keys_. | ||
| 1. For each _decorator_ in _element_.[[Decorators]], in reverse list order do | ||
| 1. Perform RemoveElementPlacement(_element_, _placements_). |
| 1. Let _placements_ be the Record { [[StaticKeys]]: « », [[PrototypeKeys]]: « », [[OwnKeys]]: « » }. | ||
| 1. For each _element_ in _elements_, do | ||
| 1. Append _element_.[[Key]] to _keys_. | ||
| 1. Perform ? AddElementPlacement(_element_, _placements_, *true*). |
There was a problem hiding this comment.
Good call, makes sense to me.
|
Could you rebase the patch? |
02ca37d to
5a4f66d
Compare
|
@littledan rebased |
|
Thanks! |
Fixes #78