Skip to content

Switch to oxidized flow parser#19398

Merged
fisker merged 20 commits into
prettier:mainfrom
pieterv:flow-parser-oxidized
Jun 23, 2026
Merged

Switch to oxidized flow parser#19398
fisker merged 20 commits into
prettier:mainfrom
pieterv:flow-parser-oxidized

Conversation

@SamChou19815

@SamChou19815 SamChou19815 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

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-parser used by prettier is produced by js_of_ocaml which is serious perf issues. We are unhappy about the perf, so we also separately maintain hermes-parser powered by wasm compiled from hermes c++ code. So Prettier also ends up with both flow-parser and hermes-parser which are mostly in sync but not exactly in sync.

Current Status

We have completed our rust port and we have just released flow-bin based 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 for hermes-parser, apart from a few newer syntax we haven't ported to hermes-parser yet 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 the hermes-parser package, and I believe the hermes-parser based plugin in Prettier will also stop being useful.

This PR

The code changes were initially generated by AI using the prompt

bump flow-parser to latest, and use flow-parser/oxidized instead of just flow-parser. the new one has similar api to the hermes-parser.

It went through several rounds of revision, and it's now a clean replacement except a few parsing error differences.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

@netlify

netlify Bot commented Jun 17, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit dd9a379
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a392f1a621ba50008b7326e
😎 Deploy Preview https://deploy-preview-19398--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/language-js/parse/postprocess/index.js Outdated
Comment thread src/language-js/parse/flow.js Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@19398.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@19398.tgz
yarn add https://pkg.pr.new/prettier@19398.tgz

commit: dd9a379

@fisker

fisker commented Jun 17, 2026

Copy link
Copy Markdown
Member

Any plan to ship ESM version?

@SamChou19815

Copy link
Copy Markdown
Collaborator Author

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
@SamChou19815

Copy link
Copy Markdown
Collaborator Author

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") {

@fisker fisker Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change still needed? If it's needed we can just revert #19127

@fisker

fisker commented Jun 19, 2026

Copy link
Copy Markdown
Member

Looks good except #19398 (comment)

@SamChou19815 SamChou19815 changed the title [experimental][wip] Switch to oxidized flow parser Switch to oxidized flow parser Jun 21, 2026
@SamChou19815 SamChou19815 marked this pull request as ready for review June 21, 2026 02:29
@fisker

fisker commented Jun 21, 2026

Copy link
Copy Markdown
Member

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?

@SamChou19815

Copy link
Copy Markdown
Collaborator Author

We are close to release v3.9, should we include this in v3.9 or merge after 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.

What's the future of hermes-parser? Should Prettier deprecate support for it?

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.

Comment thread scripts/build/esbuild-plugins/throw-warnings.js Outdated
@fisker

fisker commented Jun 22, 2026

Copy link
Copy Markdown
Member

@fisker

fisker commented Jun 22, 2026

Copy link
Copy Markdown
Member

@SamChou19815 Can you add a changelog entry? Instructions

It would be great if there were some data about performance improvements.

@fisker fisker added this to the 3.9 milestone Jun 22, 2026
@kachkaev kachkaev mentioned this pull request Jun 22, 2026
6 tasks
@fisker fisker merged commit 9c0e48c into prettier:main Jun 23, 2026
40 checks passed
@SamChou19815 SamChou19815 deleted the flow-parser-oxidized branch June 23, 2026 02:14
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.

2 participants