File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
packages/react-scripts/scripts/utils Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,23 @@ const resolve = require('resolve');
1414const path = require ( 'path' ) ;
1515const paths = require ( '../../config/paths' ) ;
1616const os = require ( 'os' ) ;
17+ const semver = require ( 'semver' ) ;
1718const immer = require ( 'react-dev-utils/immer' ) . produce ;
1819const 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+
2034function 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 } ;
You can’t perform that action at this time.
0 commit comments