Generalize copying logic by using descriptors #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a revival of #28.
First, it does something simple, which is to use
defineProperty
instead of an equality-based assignment. This is better JS hygiene when copying properties, since equality assignment results in the loss of metadata and can sometimes trigger side-effects.Second, it removes the enumerable-or-function conditional. Judging by how the 'or-function' was added to this condition only 18 days ago (65f3d58), I think we can reasonably agree that this condition is arbitrary. As discussed in my earlier PR (#28), both static functions and complex properties (those with getter/setter methods) are non-enumerable, and both are desirable for hoisting. However, complex properties cannot be 'detected' with a
typeof
operator.In the end, if we have a complete blacklist (as we do), there should be no harm in copying all non-blacklisted static properties from one component to another, so that's what I'm proposing here.