Skip to content

Commit

Permalink
Use new JSX setting with TypeScript 4.1.0 (facebook#9734)
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu authored and Krivega committed Oct 26, 2020
1 parent 5992629 commit 763cb0b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ const resolve = require('resolve');
const path = require('path');
const paths = require('../../config/paths');
const os = require('os');
const semver = require('semver');
const immer = require('react-dev-utils/immer').produce;
const globby = require('react-dev-utils/globby').sync;

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime', { paths: [paths.appPath] });
return true;
} catch (e) {
return false;
}
})();

function writeJson(fileName, object) {
fs.writeFileSync(
fileName,
Expand Down Expand Up @@ -132,8 +146,15 @@ function verifyTypeScriptSetup() {
isolatedModules: { value: true, reason: 'implementation limitation' },
noEmit: { value: true },
jsx: {
parsedValue: ts.JsxEmit.React,
suggested: 'react',
parsedValue:
hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
? ts.JsxEmit.ReactJsx
: ts.JsxEmit.React,
value:
hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
? 'react-jsx'
: 'react',
reason: 'to support the new JSX transform in React 17',
},
paths: { value: undefined, reason: 'aliased imports are not supported' },
};
Expand Down

0 comments on commit 763cb0b

Please sign in to comment.