Skip to content

Commit 7cbc90c

Browse files
authored
fix(testing): transform jsx failed when use React 18 (web-infra-dev#5047)
1 parent c2fa7c4 commit 7cbc90c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/wicked-colts-warn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/plugin-testing': patch
3+
---
4+
5+
fix(testing): transform jsx failed when use React 18
6+
7+
fix(testing): 修复使用 React 18 时 JSX 编译错误的问题

packages/runtime/plugin-testing/src/base/config/transformer/babelTransformer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import babelJest from 'babel-jest';
2+
import { isBeyondReact17 } from '@modern-js/utils';
3+
4+
const isNewJsx = isBeyondReact17(process.cwd());
25

36
const babelTransformer = (babelJest.createTransformer as any)?.({
47
presets: [
@@ -10,7 +13,12 @@ const babelTransformer = (babelJest.createTransformer as any)?.({
1013
},
1114
},
1215
],
13-
require.resolve('@babel/preset-react'),
16+
[
17+
require.resolve('@babel/preset-react'),
18+
{
19+
runtime: isNewJsx ? 'automatic' : 'classic',
20+
},
21+
],
1422
],
1523
configFile: false,
1624
babelrc: false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy