Skip to content

Commit

Permalink
Support React 18 prereleases and experimental versions with automatic…
Browse files Browse the repository at this point in the history
… JSX runtime (#7642)
  • Loading branch information
devongovett committed Feb 3, 2022
1 parent 5b38bdf commit 90050e4
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 2 deletions.
@@ -0,0 +1 @@
module.exports = <div />;

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

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

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

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"react": "0.0.0-d5e1bf0-aee1b"
}
}
Empty file.
20 changes: 20 additions & 0 deletions packages/core/integration-tests/test/transpilation.js
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
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

0 comments on commit 90050e4

Please sign in to comment.