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

feat: rax jsx runtime #2101

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

feat: rax jsx runtime #2101

wants to merge 13 commits into from

Conversation

7213
Copy link
Contributor

@7213 7213 commented Mar 10, 2021

Support jsx-runtime

This module is adapted to react's jsx-runtime module. For more information, please see:introducing-the-new-jsx-transform

usage

{
  "presets": [
    [
      "@babel/preset-react",
      {
        "runtime": "automatic",
        "importSource": "rax/jsx-runtime"
      }
    ]
  ]
}

@CLAassistant
Copy link

CLAassistant commented Mar 10, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


songzheng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@7213 7213 changed the title Feat/rax jsx runtime feat:rax jsx runtime Mar 23, 2021
@7213 7213 changed the title feat:rax jsx runtime feat: rax jsx runtime Mar 23, 2021
@SoloJiang
Copy link
Collaborator

这个包直接打在 rax 里就好了吧?

@7213
Copy link
Contributor Author

7213 commented Apr 8, 2021

这个包直接打在 rax 里就好了吧?

jsx runtime应该避免使用者对具体jsx库的感知。由编译器自动引入 import {jsx as _jsx} from "xx-jsx-runtime" 应该放到单独的包更合适点。

@SoloJiang
Copy link
Collaborator

这个包直接打在 rax 里就好了吧?

jsx runtime应该避免使用者对具体jsx库的感知。由编译器自动引入 import {jsx as _jsx} from "xx-jsx-runtime" 应该放到单独的包更合适点。

react 现在是怎么做的?

@SoloJiang
Copy link
Collaborator

编译成这样是不是更好:rax/jsx-runtime

独立包造成的问题是,runtime 核心能力和 rax 核心包之间可能存在版本差异问题,以及开发者是否感知到这个包的版本

@7213
Copy link
Contributor Author

7213 commented Apr 12, 2021

编译成这样是不是更好:rax/jsx-runtime

独立包造成的问题是,runtime 核心能力和 rax 核心包之间可能存在版本差异问题,以及开发者是否感知到这个包的版本

react是在react package里,已放入jsx-runtime放在rax包中。

@SoloJiang
Copy link
Collaborator

  1. commit 信息可以明确点
  2. jsxs/jsx/jsxDEV 应该是不一样的 3 个方法

This module is adapted to react's jsx-runtime module.
Implement Babel's "automatic" JSX runtime API:
 * 1.jsx(type, props, key)
 * 2.jsxs(type, props, key)
 * 3.jsxDEV(type, props, key, __source, __self)
@7213
Copy link
Contributor Author

7213 commented Apr 17, 2021

  1. commit 信息可以明确点
  2. jsxs/jsx/jsxDEV 应该是不一样的 3 个方法

react实现中:jsxs是jsx完全等价的别名哈
jsxDEV babel编译时会自动注入source和self调试信息,generateVNode 的实现均已包含

@SoloJiang
Copy link
Collaborator

我指的不是生产模式

}
}

return {
Copy link
Collaborator

Choose a reason for hiding this comment

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

最后返回 RaxElement 是不是更好点

@7213
Copy link
Contributor Author

7213 commented Apr 19, 2021

我指的不是生产模式

我来处理,目前是为了体积进行了最小实现,忽略了DEV环境下jsxjsxs对DEV下校验部分的代码区别

@SoloJiang
Copy link
Collaborator

可以通过环境变量移除掉 DEV 的代码

songzheng added 3 commits April 19, 2021 17:46
 1.jsx-runtime和createElement组织结构保持一致
 2.区分环境导出不同jsx-runtime,和react一致
 1.jsx-runtime和createElement组织结构保持一致
 2.区分环境导出不同jsx-runtime,和react一致
 1.jsx-runtime和createElement组织结构保持一致
 2.区分环境导出不同jsx-runtime,和react一致
@7213 7213 requested a review from SoloJiang April 19, 2021 11:32
@@ -0,0 +1 @@
export {Fragment, jsxDEV} from './index';
Copy link
Collaborator

@SoloJiang SoloJiang Apr 19, 2021

Choose a reason for hiding this comment

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

大括号前后加个空格 export { Fragment }....

Copy link
Contributor Author

@7213 7213 Apr 19, 2021

Choose a reason for hiding this comment

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

ok,不过npm run lint:fix似乎没有自动修正这个style

Copy link
Collaborator

Choose a reason for hiding this comment

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

仓库有点老,没敢升级新的 lint 规则 =。=

@@ -0,0 +1 @@
export {Fragment, jsx, jsxs, jsxDEV} from './index';
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

writable: true,
value: __self
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里抽成一个 utils,避免浪费体积

return _jsxWithValidation(type, props, key, true, __source, __self);
}

const jsx = __DEV__ ? jsxWithValidation : jsxRuntime;
Copy link
Collaborator

Choose a reason for hiding this comment

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

jsxWithValidation 用额外的文件实现,避免最后生产代码里还遗存

优化构建体积
Copy link
Collaborator

@SoloJiang SoloJiang left a comment

Choose a reason for hiding this comment

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

整体没啥大的问题了,这两天我来切个 next 分支

export function jsxWithValidation(type, props, key) {
return _jsxWithValidation(type, props, key, false);
}
export function jsxsWithValidation(type, props, key) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里的函数命名可以参考 React,可读性更强一点

songzheng added 2 commits April 20, 2021 10:00
修改jsxValidator导出的命名
修改jsxValidator导出的命名
@7213
Copy link
Contributor Author

7213 commented Apr 23, 2021

整体没啥大的问题了,这两天我来切个 next 分支

ok,到时我逐步提供为Rax App提供一个jsx-runtime的版本

@yuchonghua
Copy link

rax 近期能发一个支持jsx-runtime 的版本吗

@yuchonghua
Copy link

期待有更多rax的文档 ,而非rax-app的文档

@SoloJiang
Copy link
Collaborator

rax 近期能发一个支持jsx-runtime 的版本吗

双十二之后发布

@yuchonghua
Copy link

rax 近期能发一个支持jsx-runtime 的版本吗

双十二之后发布

您好,最近这个有推进吗?已经3月了哦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants