Replace the unmaintained OCaml Flow parser dependency
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ocaml
- 领域
- compilers
调研方向
先阅读现有的 Flow parser 集成,以及 compiler/js_parser 下之前 vendored 的源文件。围绕语法验证、错误位置、regexp 验证、函数元数、字面量分类和注释处理,定义聚焦的 parser 接口,然后为列出的情况添加测试。完成的标准是两个 parser 实现都可以针对同一个语料库进行比较,并且在兼容性足够时可以移除该依赖。
由索引模型根据 Issue 内容生成。
描述
Problem
ReScript depends on the unmaintained OCaml implementation of flow_parser to validate and classify JavaScript in %raw expressions.
Our fork supports ppxlib 0.36, which requires OCaml < 5.4. This blocks upgrades to OCaml 5.4 and 5.5. Updating the fork for each ppxlib release would only postpone the problem.
ReScript currently depends directly on Flow AST and parser types, although it only needs syntax validation, error locations, regexp validation, and classification of literals, functions and comment-only statements.
Possible solutions
1. Vendor the Flow parser
ReScript previously vendored these sources under compiler/js_parser.
We could restore the currently used parser sources and maintain them inside the repository. Ideally, we would commit the PPX-generated OCaml code so the parser no longer depends on ppxlib.
This is the lowest-risk solution and can preserve the existing direct Flow AST integration. However, it leaves ReScript responsible for roughly 33,000 lines of parser code whose JavaScript syntax support will no longer receive upstream updates.
2. Move to js_of_ocaml’s JavaScript parser
js_of_ocaml-compiler's Parse_js API provides maintained OCaml functions for parsing JavaScript expressions and programs.
For a safe migration, we should first introduce a small ReScript-owned parser interface backed by the existing Flow parser. This interface would expose only the operations ReScript needs and remove direct uses of Flow_ast, Parser_flow, Loc, and Parse_error from the rest of the compiler.
We should add focused tests for parsing, error locations, regexp validation, function arity, literal classification, leading comments and comment-only programs. The js_of_ocaml implementation could then be tested against the same corpus before switching.
js_of_ocaml maintains its parser to read JavaScript runtimes and user-provided stubs before linking and optimizing them with generated JavaScript. Its primary goal is therefore not to be a universal parser supporting every new TC39 feature immediately. Its syntax coverage, diagnostics, comment handling and classifications must be compared with the current Flow implementation.
A migration could be split into two independent changes:
- Introduce the internal parser abstraction backed by Flow Parser and strengthen test coverage.
- Implement the abstraction using js_of_ocaml, compare both implementations, and remove
flow_parserif compatibility is sufficient.
Decision
- Vendoring is the quickest and least disruptive solution, but makes ReScript the permanent owner of an unmaintained parser.
- Moving to js_of_ocaml requires more migration work, but offers a maintained long-term dependency with much less parser-specific coupling.
- 主要语言
- 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
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
JakeChampion/lang#10213 ·
-
bug language-server
难度 2/5 1-3 小时 新手友好度 70/100
purefunctor/purescript-iris#552 ·
-
enhancement good first issue needs testing
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
bradcypert/plum#58 ·