Skip to content

Commit 1af9e97

Browse files
committed
Attempt to add back jsx transform detection
1 parent b70cb5d commit 1af9e97

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

packages/babel-preset-react-app/create.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
const path = require('path');
1010

11-
const useJsxTransform = process.env.DISABLE_NEW_JSX_TRANSFORM !== 'true';
12-
1311
const validateBoolOption = (name, value, defaultValue) => {
1412
if (typeof value === 'undefined') {
1513
value = defaultValue;
@@ -56,6 +54,10 @@ module.exports = function (api, opts, env) {
5654
);
5755
}
5856

57+
var hasJsxRuntime = Boolean(
58+
api.caller(caller => !!caller && caller.hasJsxRuntime)
59+
);
60+
5961
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
6062
throw new Error(
6163
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -97,8 +99,8 @@ module.exports = function (api, opts, env) {
9799
development: isEnvDevelopment || isEnvTest,
98100
// Will use the native built-in instead of trying to polyfill
99101
// behavior for any plugins that require one.
100-
...(!useJsxTransform ? { useBuiltIns: true } : {}),
101-
runtime: useJsxTransform ? 'automatic' : 'classic',
102+
...(!hasJsxRuntime ? { useBuiltIns: true } : {}),
103+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
102104
},
103105
],
104106
isTypeScriptEnabled && [require('@babel/preset-typescript').default],

packages/eslint-config-react-app/base.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// React App support, and is used as the `baseConfig` for `eslint-loader`
1212
// to ensure that user-provided configs don't need this boilerplate.
1313

14-
const useJsxTransform = process.env.DISABLE_NEW_JSX_TRANSFORM !== 'true';
15-
1614
module.exports = {
1715
root: true,
1816

@@ -45,8 +43,5 @@ module.exports = {
4543
rules: {
4644
'react/jsx-uses-vars': 'warn',
4745
'react/jsx-uses-react': 'warn',
48-
...(!useJsxTransform && {
49-
'react/react-in-jsx-scope': 'error',
50-
}),
5146
},
5247
};

packages/react-scripts/config/webpack.config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ const cssModuleRegex = /\.module\.css$/;
7171
const sassRegex = /\.(scss|sass)$/;
7272
const sassModuleRegex = /\.module\.(scss|sass)$/;
7373

74+
const hasJsxRuntime = (() => {
75+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
76+
return false;
77+
}
78+
79+
try {
80+
require.resolve('react/jsx-runtime');
81+
return true;
82+
} catch (e) {
83+
return false;
84+
}
85+
})();
86+
7487
// This is the production and development configuration.
7588
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
7689
module.exports = function (webpackEnv) {
@@ -396,7 +409,14 @@ module.exports = function (webpackEnv) {
396409
// @remove-on-eject-begin
397410
babelrc: false,
398411
configFile: false,
399-
presets: [require.resolve('babel-preset-react-app')],
412+
presets: [
413+
[
414+
require.resolve('babel-preset-react-app'),
415+
{
416+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
417+
},
418+
],
419+
],
400420
// Make sure we have a unique cache identifier, erring on the
401421
// side of caution.
402422
// We remove this when the user ejects because the default
@@ -737,6 +757,11 @@ module.exports = function (webpackEnv) {
737757
resolvePluginsRelativeTo: __dirname,
738758
baseConfig: {
739759
extends: [require.resolve('eslint-config-react-app/base')],
760+
rules: {
761+
...(!hasJsxRuntime && {
762+
'react/react-in-jsx-scope': 'error',
763+
}),
764+
},
740765
},
741766
}),
742767
].filter(Boolean),

0 commit comments

Comments
 (0)