Skip to content

Commit

Permalink
PLAT-121645: Add support for new JSX Transform (#236)
Browse files Browse the repository at this point in the history
* PLAT-121645: Add support for new JSX Transform

Enact-DCO-1.0-Signed-off-by: Mikyung Kim ([email protected])

* fix lint error

Enact-DCO-1.0-Signed-off-by: Mikyung Kim ([email protected])

* fix lint

Enact-DCO-1.0-Signed-off-by: Mikyung Kim ([email protected])

* Added a guard

Enact-DCO-1.0-Signed-off-by: Mikyung Kim ([email protected])
  • Loading branch information
MikyungKim authored Feb 3, 2021
1 parent e500555 commit 4170360
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
16 changes: 15 additions & 1 deletion config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
*/
const path = require('path');

// Check if JSX transform is able
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();

module.exports = function (api) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const es5Standalone = process.env.ES5 && process.env.ES5 !== 'false';
Expand Down Expand Up @@ -47,7 +61,7 @@ module.exports = function (api) {
development: env !== 'production' && !es5Standalone,
// Will use the native built-in instead of trying to polyfill
// behavior for any plugins that require one.
useBuiltIns: true
...(!hasJsxRuntime ? {useBuiltIns: true} : {runtime: 'automatic'})
}
],
['@babel/preset-typescript']
Expand Down
22 changes: 21 additions & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ module.exports = function (env) {
// Sets the browserslist default fallback set of browsers to the Enact default browser support list.
app.setEnactTargetsAsDefault();

// Check if JSX transform is able
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();

// Check if TypeScript is setup
const useTypeScript = fs.existsSync('tsconfig.json');

Expand Down Expand Up @@ -463,7 +477,13 @@ module.exports = function (env) {
resolvePluginsRelativeTo: __dirname,
// @remove-on-eject-begin
baseConfig: {
extends: [require.resolve('eslint-config-enact')]
extends: [require.resolve('eslint-config-enact')],
rules: {
...(!hasJsxRuntime && {
'react/jsx-uses-react': 'warn',
'react/react-in-jsx-scope': 'warn'
})
}
},
useEslintrc: false,
// @remove-on-eject-end
Expand Down

0 comments on commit 4170360

Please sign in to comment.