Use object bracket access test for RESERVED_PROPS #12530
Closed
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.
Continuing from #12370 with different solution (ping @gaearon)
hasOwnProperty(if my benchmark works correctly anyway)objects if properties aren't accessed dynamically. Using bracket access
will make Closure to keep these properties in optimized code.
I thought
preserveTypeAnnotationswould keep all JSDoc annotations but@nocollapseseems to be different than "general" JSDoc comments, so it is not kept.After failure with that approach I started looking into why https://github.com/facebook/react/blob/master/packages/shared/isTextInputElement.js#L13-L29 works with Closure optimizations (with externs to keep the property names). The function is transpiled into static object and a function which uses brackets to access the object. Turns out, that because the code is using brackets to access the object Closure doesn't optimize the properties away.
I checked performance difference between hasOwnProperty and brackets, and looks like object bracket access is faster: https://jsperf.com/static-object-check-if-prop-exists/1