New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for automatic JSX runtime #740
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes #585 Tech plan: https://github.com/alangpierce/sucrase/wiki/JSX-Automatic-Runtime-Transform-Technical-Plan This PR adds two new options: * `jsxRuntime`, which can be "classic" (the existing behavior) or "automatic" (the transform behavior released with React 17). * `jsxImportSource`, which configures the import prefix when using the automatic runtime. This PR also makes these options available for the website.
Codecov Report
@@ Coverage Diff @@
## main #740 +/- ##
==========================================
+ Coverage 87.23% 87.43% +0.19%
==========================================
Files 54 54
Lines 5751 5856 +105
Branches 1357 1389 +32
==========================================
+ Hits 5017 5120 +103
Misses 466 466
- Partials 268 270 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Benchmark resultsBefore this PR: 414.1 thousand lines per second Measured change: 0.8% slower (1.34% slower to 0.3% faster) |
alangpierce
added a commit
that referenced
this pull request
Sep 2, 2022
This PR has a few details pulled from #740 to make it easier to read the substantial changes in that PR: * Reorder the options interface to better group related options together. * Reorder the methods in JSXTransformer to be in (roughly) top-down topological order rather than the more scattered order that it was previously. * Change website advanced options to dynamically only show the ones relevant based on what is selected.
alangpierce
added a commit
that referenced
this pull request
Sep 2, 2022
This PR has a few details pulled from #740 to make it easier to read the substantial changes in that PR: * Reorder the options interface to better group related options together. * Reorder the methods in JSXTransformer to be in (roughly) top-down topological order rather than the more scattered order that it was previously. * Change website advanced options to dynamically only show the ones relevant based on what is selected.
alangpierce
added a commit
that referenced
this pull request
Sep 2, 2022
This PR has a few details pulled from #740 to make it easier to read the substantial changes in that PR: * Reorder the options interface to better group related options together. * Reorder the methods in JSXTransformer to be in (roughly) top-down topological order rather than the more scattered order that it was previously. * Change website advanced options to dynamically only show the ones relevant based on what is selected.
alangpierce
added a commit
that referenced
this pull request
Sep 2, 2022
This PR has a few details pulled from #740 to make it easier to read the substantial changes in that PR: * Reorder the options interface to better group related options together. * Reorder the methods in JSXTransformer to be in (roughly) top-down topological order rather than the more scattered order that it was previously. * Change website advanced options to dynamically only show the ones relevant based on what is selected.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #585
Tech plan that includes many major details:
https://github.com/alangpierce/sucrase/wiki/JSX-Automatic-Runtime-Transform-Technical-Plan
This PR adds two new options:
jsxRuntime
, which can be "classic" (the existing behavior) or "automatic"(the transform behavior released with React 17).
jsxImportSource
, which configures the import prefix when using the automaticruntime.
This PR also adds docs for the new options and makes them available to demo on the website.
While it may have been possible to split the
JSXTransform
code into multiple files, theconfiguration space is intertwined enough that it seemed better for now to just have a unified
implementation for now. This leads to a little extra abstraction when resolving function names
as well as some special cases about where to place commas, but the overall flow of logic is the
same.
Unfortunately, it looks like the new implementation is slower than the old one, regardless of
configuration, which isn't too surprising given the added complexity. Some measurements,
using a higher-scale variation of
yarn benchmark sample
(which specifically tests scale forthe JSX transform):
There's certainly some possible room for improvement, e.g. by more aggressively caching/
precomputing resolved names or duplicating and individually simplifying the code path for
each configuration, but that can be done as future work.