Skip to content
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

Support React 18 prereleases and experimental versions with automatic JSX runtime #7642

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = <div />;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"react": "18.0.0-rc.0-next-9a7e6bf0d-2022011"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = <div />;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"react": "0.0.0-d5e1bf0-aee1b"
}
}
20 changes: 20 additions & 0 deletions packages/core/integration-tests/test/transpilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ describe('transpilation', function () {
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with React 18 prereleases', async function () {
let b = await bundle(
path.join(__dirname, '/integration/jsx-automatic-18/index.js'),
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('react/jsx-dev-runtime'));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with experimental React versions', async function () {
let b = await bundle(
path.join(__dirname, '/integration/jsx-automatic-experimental/index.js'),
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('react/jsx-dev-runtime'));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with preact with alias', async function () {
let b = await bundle(
path.join(
Expand Down
6 changes: 4 additions & 2 deletions packages/transformers/js/src/JSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const JSX_PRAGMA = {
react: {
pragma: 'React.createElement',
pragmaFrag: 'React.Fragment',
automatic: '>= 17.0.0',
automatic: '>= 17.0.0 || >= 0.0.0-0 < 0.0.0',
},
preact: {
pragma: 'h',
Expand Down Expand Up @@ -220,7 +220,9 @@ export default (new Transformer({
automaticVersion &&
!compilerOptions?.jsxFactory &&
minReactLibVersion != null &&
semver.satisfies(minReactLibVersion, automaticVersion);
semver.satisfies(minReactLibVersion, automaticVersion, {
includePrerelease: true,
});

if (automaticJSXRuntime) {
jsxImportSource = reactLib;
Expand Down