Skip to content

Commit

Permalink
fix: when code has declare @jsx createElement comment, swc config run…
Browse files Browse the repository at this point in the history
…time: 'classic' (#5976)

* feat: 遇到注释信息 应该走 classic 的编译模式

* chore: add version and changelog

* chore: add changesets

* feat: hasJSXComment 的逻辑放在 isRaxComponent

* feat: 内部声明
  • Loading branch information
MrpandaLiu authored Feb 27, 2023
1 parent 6824ad6 commit efba0cc
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-dryers-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/plugin-rax-compat': major
---

- [fix] Using runtime: 'classic' mode when source has declare `@jsx createElement` comment
12 changes: 12 additions & 0 deletions packages/plugin-rax-compat/src/index.ts
Original file line number Diff line number Diff line change
@@ -70,6 +70,18 @@ const plugin: Plugin<CompatRaxOptions> = (options = {}) => ({
compilationConfig: (source: string) => {
const isRaxComponent = /from\s['"]rax['"]/.test(source);
if (isRaxComponent) {
const hasJSXComment = source.indexOf('@jsx createElement') !== -1;
if (hasJSXComment) {
return {
jsc: {
transform: {
react: {
runtime: 'classic',
},
},
},
};
}
return {
jsc: {
transform: {

0 comments on commit efba0cc

Please sign in to comment.