optimize __createBinding #168
Merged
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.
Reflect microsoft/TypeScript#46997:
When the binding is itself one that was created by
__createBinding,re-use its descriptor, which avoids piling multiple levels of getters in
the case of multiple levels of exports.
In addition, reuse a descriptor if the bindings is marked as
non-writable and non-configurable, which makes a getter not
necessary. (This can be done manually if needed, even though tsc
doesn't do it now.)
Could be considered as a fix for #165 -- first, this PR prevents piling
up multiple layers of getters. Second, it allows a hack of adding
to avoid getters altogether. (And in the future, tsc could mark
constexports as non-writable and non-configurable which would make it
possible to avoid this hack.)