Registry / type-stubs / flow-parser

flow-parser

JSON →
library0.309.0jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · FLOW-PARSER
F
flow-parser
type-stubsjavascriptv0.309.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
const flowParser = require('flow-parser'); flowParser.parse('code', {});
import { parse } from 'flow-parser';
The primary API is accessed via a property on the default CommonJS export. Direct named ESM imports are not typically supported for the top-level `parse` function.
flow
<script src="flow_parser.js"></script> <script> flow.parse('code', {}); </script>
When used in a browser environment via a `<script>` tag, the parser exposes a global `flow` object. Ensure `flow_parser.js` is loaded first.

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.

const flowParser = require('flow-parser'); const code = ` // @flow enum Status { Active, Inactive }; function greet(name: string): string { return 'Hello, ' + name + '!'; } const status: Status = Status.Active; `; const options = { types: true, // Enable parsing of Flow types comments: true, // Attach comments to AST nodes enums: true, // Enable parsing of enums tokens: false }; try { const ast = flowParser.parse(code, options); console.log('Successfully parsed code. AST root type:', ast.type); console.log('Function declaration:', ast.body.find(node => node.type === 'FunctionDeclaration').id.name); console.log('Enum declaration:', ast.body.find(node => node.type === 'EnumDeclaration').id.name); } catch (e) { console.error('Parsing error:', e.message); }
Debug
Known issues
breakingThe AST structure for Enum body nodes has been significantly refactored. The five specific enum body ESTree node types (`EnumBooleanBody`, `EnumNumberBody`, etc.) have been replaced with a single `EnumBody` node. Its `members` property is now a flat array of per-type member nodes, and `explicitType` is a string or `null` instead of a boolean.
fix
Update AST traversal logic and type checks to accommodate the new `EnumBody` structure and its `members` property for accessing individual enum members.
affects: >=0.308.0
breakingParsing now errors when an optional modifier `?` appears in invalid contexts, such as `const x? = 1;`. Code that previously parsed but was syntactically incorrect in Flow will now throw a `ParseError`.
fix
Ensure that the code being parsed adheres strictly to Flow's grammar for optional modifiers, removing any incorrect usages.
affects: >=0.307.0
gotchaMany Flow-specific language features, such as `enums`, `match` expressions, `components`, and `esproposal_decorators`, require explicit enabling via options passed to the `parse` method. By default, these advanced features are not parsed.
fix
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.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: flowParser.parse is not a function
Attempting to call `flowParser.parse()` after `require('flow-parser')` when `flow-parser` does not export a direct `parse` function, but rather an object that contains the `parse` method.
fix
Access the `parse` method as a property of the imported object: `const flowParser = require('flow-parser'); flowParser.parse('code', {});`
SyntaxError: Unexpected token (X:Y)
Using Flow-specific syntax (e.g., enums, components, decorators) without enabling the corresponding parsing option.
fix
Pass the appropriate option to `flowParser.parse()`, for example, `flowParser.parse(code, { enums: true, components: true });`
Upgrade
Version history
0.309.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
node
36
OpenAI (training)
1
Resources
flow-parser — npm install flow-parser · libregistry