The flow-parser package provides a JavaScript parser, originally written in OCaml and compiled to JavaScript. It is designed to produce an Abstract Syntax Tree (AST) that largely conforms to the ESTree specification, similar to parsers like Esprima. This package is specifically built to understand and parse Flow's type annotations, making it a crucial component for tools that process Flow-typed code. As of April 2026, the current stable version is `0.309.0`, with releases appearing to follow a regular, often monthly or bi-monthly, cadence. Its key differentiator lies in its deep integration with the Flow type system and its ability to parse advanced Flow-specific syntax, while still outputting a widely compatible ESTree AST. It runs in both Node.js environments (requiring Node.js >= 0.4.0) and web browsers through a script tag.
npm install flow-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a Flow-typed JavaScript code snippet using the `flow-parser` in Node.js, enabling Flow types and specific features like enums, and logging the root AST type and specific node names.
Update AST traversal logic and type checks to accommodate the new `EnumBody` structure and its `members` property for accessing individual enum members.
Ensure that the code being parsed adheres strictly to Flow's grammar for optional modifiers, removing any incorrect usages.
Always provide an options object to `flowParser.parse()` and set the relevant boolean flags (e.g., `enums: true`, `components: true`) to `true` for features present in the source code.
Access the `parse` method as a property of the imported object: `const flowParser = require('flow-parser'); flowParser.parse('code', {});`Pass the appropriate option to `flowParser.parse()`, for example, `flowParser.parse(code, { enums: true, components: true });`No dependency data recorded yet.