JSX preserve mode generates invalid JSX for external component bindings
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, ocaml
调研方向
从链接的最小复现开始,使用 rescript.json、Preact.res 和 Test.res,然后运行 npx rescript build,观察生成的 Test.jsx。追踪编译器针对外部组件绑定的通用 JSX preserve 处理,并添加一个涵盖无效箭头函数输出的回归测试;当生成与预期 SomeLib.Head 形式匹配的有效 JSX 时即完成。
由索引模型根据 Issue 内容生成。
描述
Thank you for filing! Check list:
- Is it a bug? Usage questions should often be asked in the forum instead.
- Concise, focused, friendly issue title & description.
- A minimal, reproducible example.
- OS and browser versions, if relevant.
- Is it already fixed in master? Instructions
Summary
When using the generic JSX transform with "preserve": true, external component bindings generate invalid JSX syntax like <prim => Module.Component(prim)> instead of valid JSX.
ReScript Version
12.0.0
Minimal Reproduction
https://github.com/han-tyumi/rescript-jsx-preserve-bug
git clone https://github.com/han-tyumi/rescript-jsx-preserve-bug.git
cd rescript-jsx-preserve-bug
npm install
npx rescript build
cat Test.jsx
Files
rescript.json:
{
"name": "preserve-bug",
"sources": ["."],
"package-specs": {
"module": "esmodule",
"in-source": true
},
"suffix": ".jsx",
"jsx": {
"module": "Preact",
"preserve": true
}
}
Preact.res (minimal bindings):
type element
type component<'props> = 'props => element
@module("preact/jsx-runtime")
external jsx: (component<'props>, 'props) => element = "jsx"
@module("preact/jsx-runtime")
external jsxs: (component<'props>, 'props) => element = "jsxs"
type fragmentProps = {children?: element}
@module("preact/jsx-runtime")
external jsxFragment: component<fragmentProps> = "Fragment"
type domProps = {children?: element}
module Elements = {
external someElement: element => option<element> = "%identity"
@module("preact/jsx-runtime")
external jsx: (string, domProps) => element = "jsx"
@module("preact/jsx-runtime")
external jsxs: (string, domProps) => element = "jsxs"
}
Test.res:
// Component module pattern with external make
module Head = {
type props = {children?: Preact.element}
@module("some-lib")
external make: props => Preact.element = "Head"
}
// Using the component
let test = <Head> <div /> </Head>
Expected Output
Valid JSX that can be processed by standard JSX transformers:
let test = <SomeLib.Head>
<div />
</SomeLib.Head>;
Actual Output
Invalid JSX with arrow function syntax:
let test = <prim => SomeLib.Head(prim)>
{Primitive_option.some(<div />)}
</prim => SomeLib.Head(prim)>;
Notes
- Lowercase DOM elements work correctly in preserve mode (e.g.,
<div>stays as<div>) - Internal component modules (with ReScript-defined
makefunctions) work correctly (e.g.,<MyComponent.make>) - External component bindings produce the invalid arrow function syntax shown above
This prevents using preserve mode with frameworks like Preact/Fresh where you need to bind to external components.
- 主要语言
- OCaml
- 星标
- 7.5k
- 派生
- 485
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 52
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 68/100
rescript-lang/rescript#8688 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 76/100
rescript-lang/rescript#8687 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8659 · 2 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8647 ·
维护者通常 1 天内回复
-
Untagged variants: boolean literal/payload overlap is rejected while string, int, float and bigint overlap is allowed可能已有人在做 @cknitt 于 22 天前认领。 未关闭
rescript-lang/rescript#8632 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
confirmed llvm:optimizations miscompilation
难度 2/5 1-3 小时 新手友好度 88/100
llvm/llvm-project#227071 · 1 条评论 ·
维护者通常 1 天内回复
-
Every compiled IO program carries ~1 MiB of zeros: io_eff_rows is baked into .data.rel.ro by clang未关闭
难度 2/5 1-3 小时 新手友好度 84/100
HigherOrderCO/Bend#1163 ·