Skip to content

Commit 90050e4

Browse files
authoredFeb 3, 2022
Support React 18 prereleases and experimental versions with automatic JSX runtime (#7642)
1 parent 5b38bdf commit 90050e4

File tree

14 files changed

+44
-2
lines changed

14 files changed

+44
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = <div />;

‎packages/core/integration-tests/test/integration/jsx-automatic-18/node_modules/react/jsx-dev-runtime.js

Whitespace-only changes.

‎packages/core/integration-tests/test/integration/jsx-automatic-18/node_modules/react/jsx-runtime.js

Whitespace-only changes.

‎packages/core/integration-tests/test/integration/jsx-automatic-18/node_modules/react/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"react": "18.0.0-rc.0-next-9a7e6bf0d-2022011"
5+
}
6+
}

‎packages/core/integration-tests/test/integration/jsx-automatic-18/yarn.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = <div />;

‎packages/core/integration-tests/test/integration/jsx-automatic-experimental/node_modules/react/jsx-dev-runtime.js

Whitespace-only changes.

‎packages/core/integration-tests/test/integration/jsx-automatic-experimental/node_modules/react/jsx-runtime.js

Whitespace-only changes.

‎packages/core/integration-tests/test/integration/jsx-automatic-experimental/node_modules/react/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"react": "0.0.0-d5e1bf0-aee1b"
5+
}
6+
}

‎packages/core/integration-tests/test/integration/jsx-automatic-experimental/yarn.lock

Whitespace-only changes.

‎packages/core/integration-tests/test/transpilation.js

+20
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ describe('transpilation', function () {
203203
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
204204
});
205205

206+
it('should support the automatic JSX runtime with React 18 prereleases', async function () {
207+
let b = await bundle(
208+
path.join(__dirname, '/integration/jsx-automatic-18/index.js'),
209+
);
210+
211+
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
212+
assert(file.includes('react/jsx-dev-runtime'));
213+
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
214+
});
215+
216+
it('should support the automatic JSX runtime with experimental React versions', async function () {
217+
let b = await bundle(
218+
path.join(__dirname, '/integration/jsx-automatic-experimental/index.js'),
219+
);
220+
221+
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
222+
assert(file.includes('react/jsx-dev-runtime'));
223+
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
224+
});
225+
206226
it('should support the automatic JSX runtime with preact with alias', async function () {
207227
let b = await bundle(
208228
path.join(

‎packages/transformers/js/src/JSTransformer.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const JSX_PRAGMA = {
2222
react: {
2323
pragma: 'React.createElement',
2424
pragmaFrag: 'React.Fragment',
25-
automatic: '>= 17.0.0',
25+
automatic: '>= 17.0.0 || >= 0.0.0-0 < 0.0.0',
2626
},
2727
preact: {
2828
pragma: 'h',
@@ -220,7 +220,9 @@ export default (new Transformer({
220220
automaticVersion &&
221221
!compilerOptions?.jsxFactory &&
222222
minReactLibVersion != null &&
223-
semver.satisfies(minReactLibVersion, automaticVersion);
223+
semver.satisfies(minReactLibVersion, automaticVersion, {
224+
includePrerelease: true,
225+
});
224226

225227
if (automaticJSXRuntime) {
226228
jsxImportSource = reactLib;

0 commit comments

Comments
 (0)
Please sign in to comment.