Skip to content

Commit 7fa3eb5

Browse files
iansuabhiisheek
authored andcommitted
Use new JSX setting with TypeScript 4.1.0 (facebook#9734)
1 parent a0bf104 commit 7fa3eb5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ const resolve = require('resolve');
1414
const path = require('path');
1515
const paths = require('../../config/paths');
1616
const os = require('os');
17+
const semver = require('semver');
1718
const immer = require('react-dev-utils/immer').produce;
1819
const globby = require('react-dev-utils/globby').sync;
1920

21+
const hasJsxRuntime = (() => {
22+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
23+
return false;
24+
}
25+
26+
try {
27+
require.resolve('react/jsx-runtime', { paths: [paths.appPath] });
28+
return true;
29+
} catch (e) {
30+
return false;
31+
}
32+
})();
33+
2034
function writeJson(fileName, object) {
2135
fs.writeFileSync(
2236
fileName,
@@ -132,8 +146,15 @@ function verifyTypeScriptSetup() {
132146
isolatedModules: { value: true, reason: 'implementation limitation' },
133147
noEmit: { value: true },
134148
jsx: {
135-
parsedValue: ts.JsxEmit.React,
136-
suggested: 'react',
149+
parsedValue:
150+
hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
151+
? ts.JsxEmit.ReactJsx
152+
: ts.JsxEmit.React,
153+
value:
154+
hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
155+
? 'react-jsx'
156+
: 'react',
157+
reason: 'to support the new JSX transform in React 17',
137158
},
138159
paths: { value: undefined, reason: 'aliased imports are not supported' },
139160
};

0 commit comments

Comments
 (0)