Revisit JSX syntax
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 38/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, ocaml
调研方向
从 ReScript JSX 差异文档和 issue 中链接的官方 JSX 规范开始。跟踪 formatter 和 parser 的入口点,以确定当前如何处理 JSX 子元素。对于纯文本、标识符、表达式和自定义组件子元素,提议的 formatter 和 parser 行为均已定义并覆盖后,即可视为完成。
由索引模型根据 Issue 内容生成。
描述
Proposal: Bring ReScript JSX Closer to the JavaScript JSX Spec
Currently, ReScript JSX differs from JavaScript’s JSX in a few key ways (docs).
I propose moving ReScript JSX closer to the official JSX spec in a future release.
Example
// Current
let foo = <p>{React.string("Hello")}</p>
// Proposed
let foo = <p>Hello</p>
Right now, Hello is treated as a React.element rather than as JSXText.
This means plain text inside JSX must be wrapped in React.string(...), unlike in JavaScript JSX.
Suggested Path Forward
Step 1: Formatter update
The formatter could automatically insert braces for identifiers used as children, making the output more consistent.
// Original
let foo = <p>children</p>
// After format
// (notice how there's no space before the opening curly brace and after the closing one)
let foo = <p>{children}</p>
Step 2: Parser update
Next, the parser could be extended to handle JSXText as valid child input—bringing ReScript JSX semantics in line with the JSX spec.
[!NOTE]
This change will only affect syntax and won't change the type of JSX children.
Inside curly braces you'll still need React.string:<div> {switch count { | 1 => "once" | n => `Int.toString(n) times` }->React.string} </div>This could also affect custom components where children are not typed as JSX element and that are often used with literals, eg before:
<Counter>6</Counter>after:
<Counter>{6}</Counter>
This is still an early-stage idea, so feedback is welcome. Don't hesitate to chime in if you think your codebase would be affected by this change.
Please use 👍 / 👎 / 👀 to indicate your opinion.
This is just a signal, not a binding vote.
- 主要语言
- OCaml
- 星标
- 7.5k
- 派生
- 485
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 55
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8659 · 2 条评论 · 2 个 reaction ·
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8647 ·
-
rescript-lang/rescript#8632 · 已指派 1 人 ·
-
难度 5/5 一周以上 新手友好度 28/100
rescript-lang/rescript#8624 ·
-
难度 5/5 一周以上 新手友好度 30/100
rescript-lang/rescript#8596 · 2 条评论 ·
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
JakeChampion/lang#10260 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
objectionary/jeo-maven-plugin#1811 ·
-
`String.Parser.chompUntilEndOr` leaves the column one short when it runs to the end past a newline 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
-
enhancement PyCDE
难度 2/5 1-3 小时 新手友好度 78/100
-
llvm:support
难度 2/5 1-3 小时 新手友好度 76/100
llvm/llvm-project#226296 ·