Switch to oxidized flow parser#19398
Conversation
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
|
Any plan to ship ESM version? |
This would be something we could do in the future, but right now we are just focusing on shipping the rust port powered the one and delete the ocaml code. |
with this we can kill some of the ugly patches. if it's good we can eventually remove these vendoring and cut a new release on the flow side
|
In the latest version with a temporarily checked-in latest build of flow-parser, we are able to completely remove those ast patching hack in earlier commits. The newly disabled tests are due to the intentional decision of dropping support for special casing comment-syntax to align with hermes-parser, and hermes-parser have same behavior on these two files. @fisker let me know if the implementation looks good for you. If it's good, we can cut a new parser release on the flow side so that we can remove the temp vendor and have a proper PR. |
| // https://github.com/facebook/flow/blob/HEAD/Changelog.md#03130 | ||
| case "TypeParameter": | ||
| if (astType !== "flow" && node.bound?.type === "TypeAnnotation") { | ||
| if (node.bound?.type === "TypeAnnotation") { |
There was a problem hiding this comment.
This change still needed? If it's needed we can just revert #19127
|
Looks good except #19398 (comment) |
|
How should we process? We are close to release v3.9, should we include this in v3.9 or merge after it? What's the future of hermes-parser? Should Prettier deprecate support for it? |
I don't have a strong opinion on this: we are not in a rush wanting a new release. On the Flow side, we are mostly interested in deleting the old OCaml powered parser code, so once we have the confirmation on the Prettier side that this PR is good we will go ahead and delete the old OCaml based parser. However, based on my understanding of the changes in v3.9, this PR does fit in. It is probably far less disruptive than the other formatting changes.
We have already de-facto stopped adding new syntax support to hermes-parser for a while, knowing that the Rust based flow-parser will be available soon. For example, you can see that syntax support like abstract class was added to flow-parser but never made it to the hermes-parser. Therefore, given these facts on the ground, Prettier should probably deprecate support for it. |
|
Can you fix this script? https://github.com/prettier/prettier/blob/main/scripts/generate-flow-estree-type-definition.js |
|
@SamChou19815 Can you add a changelog entry? Instructions It would be great if there were some data about performance improvements. |
Description
This PR switches over the flow parsing in prettier to the upcoming flow parser powered by wasm based on our rust port.
Background
Historically, Flow is always written in OCaml, which has the ability to be compiled to JS. The current
flow-parserused by prettier is produced byjs_of_ocamlwhich is serious perf issues. We are unhappy about the perf, so we also separately maintainhermes-parserpowered by wasm compiled from hermes c++ code. So Prettier also ends up with bothflow-parserandhermes-parserwhich are mostly in sync but not exactly in sync.Current Status
We have completed our rust port and we have just released
flow-binbased on the rust port binaries. We have also released the rust port based parser in'flow-parser/oxidized'(while the ocaml based one still remain importable via'flow-parser'before we migrate the Prettier use case away from it). 'flow-parser/oxidized' aims to be mostly a drop in replacement forhermes-parser, apart from a few newer syntax we haven't ported tohermes-parseryet and a few expected AST shape changes.I believe now
'flow-parser/oxidized'is good for prettier use, so it will eventually just becomes'flow-parser'. At that point, we will stop updating thehermes-parserpackage, and I believe thehermes-parserbased plugin in Prettier will also stop being useful.This PR
The code changes were initially generated by AI using the prompt
It went through several rounds of revision, and it's now a clean replacement except a few parsing error differences.
Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.