Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when code has declare @jsx createElement comment, swc config runtime: 'classic' #5976

Merged
merged 5 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -69,7 +69,19 @@ const plugin: Plugin<CompatRaxOptions> = (options = {}) => ({
config.swcOptions = merge(config.swcOptions || {}, {
compilationConfig: (source: string) => {
const isRaxComponent = /from\s['"]rax['"]/.test(source);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package 里面 version 加一下,changelog 补充

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 changeset 流程:

  1. 不需要修改版本号
  2. 项目根路径下执行 pnpm run changeset, 根据 cli 提示操作
  3. 提交所有文件

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 changeset 流程:

  1. 不需要修改版本号
  2. 项目根路径下执行 pnpm run changeset, 根据 cli 提示操作
  3. 提交所有文件

这个好像还没有补充到 CONTRIBUTING.md 中

const hasJSXComment = source.indexOf('@jsx createElement') !== -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个检测可以卸载判断条件内部,提升效率

if (isRaxComponent) {
if (hasJSXComment) {
return {
jsc: {
transform: {
react: {
runtime: 'classic',
},
},
},
};
}
return {
jsc: {
transform: {
Expand Down