Optimize React.createElement property accesses #8848
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 fixes #5435 and addresses #6219 (comment) by employing a new Babel plugin that replaces calls to
React.createElement
with calls to a local variable that is bound toReact.createElement
.Originally I aimed for a babel plugin implementation that makes use of JSX pragmas to instruct the translator to use the local variable. That did not work out in the context of CRA, so the current implementation is based on what was proposed in #6219.
Right now, the plugin lives in my GitHub profile at https://github.com/NeoLegends/babel-plugin-transform-react-create-element. If desired, I'll happily transfer ownership of the code and the npm package here and remove the usage of TypeScript.
I tested the changes using
yarn build
, inspecting the build output and verifying things work in the browser. The babel plugin itself also features tests.