flow-parser 0.322.0 → 0.324.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,37 +1,30 @@
1
- # The flow-parser package
1
+ # flow-parser
2
2
 
3
- This package contains the Flow parser in its JavaScript package form.
3
+ A JavaScript parser built from the Flow's parser compiled to WebAssembly. Can parse ES6, Flow, and JSX syntax.
4
4
 
5
- # What is Flow
5
+ ## What is Flow
6
6
 
7
7
  See [flow.org](https://flow.org/). The code for the Flow parser [lives on GitHub](https://github.com/facebook/flow/tree/master/src/parser).
8
8
 
9
- # What is the Flow Parser
10
-
11
- The Flow Parser is a JavaScript parser for Flow syntax. It produces an AST that conforms to the [ESTree spec](https://github.com/estree/estree). This npm package contains the Flow Rust parser compiled to WASM with JavaScript bindings.
12
-
13
- # Usage
14
-
15
- You can use the Flow parser in node:
16
-
17
- ```JavaScript
18
- const {parse} = require('flow-parser');
19
- parse('1+1', {});
20
- ```
21
-
22
- ## Options
23
-
24
- The second argument to `parse` is the options object. Common options:
25
-
26
- ### Basic options
27
- * `flow` (`'detect'` or `'all'`, default `'detect'`) - parse Flow syntax only with an `@flow` pragma, or always parse Flow syntax
28
- * `sourceType` (`'module'`, `'script'`, or `'unambiguous'`) - parse the file as a module, script, or infer it from the contents
29
- * `tokens` (boolean, default `false`) - include a list of all parsed tokens in a top-level `tokens` property
30
- * `babel` (boolean, default `false`) - return a Babel-shaped AST
31
-
32
- ### Language features
33
- * `enableEnums` (boolean, default `true`) - enable parsing of [enums](https://flow.org/en/docs/enums/)
34
- * `enableExperimentalFlowMatchSyntax` (boolean, default `true`) - enable parsing of [match expressions and match statements](https://flow.org/en/docs/match/)
35
- * `enableExperimentalComponentSyntax` (boolean, default `true`) - enable parsing of [component syntax](https://flow.org/en/docs/react/component-syntax/)
36
- * `assertOperator` (boolean, default `false`) - enable parsing of the assert operator
37
- * `enableExperimentalDecorators` (boolean, default `true`) - enable parsing of decorators
9
+ ## What is the Flow Parser
10
+
11
+ The Flow Parser is a JavaScript parser for Flow syntax. It produces an AST that conforms to the [ESTree spec](https://github.com/estree/estree).
12
+
13
+ ## API
14
+ The Flow parser exposes a single `parse(code, [options])` function, where `code` is the source code to parse as a string, and `options` is an optional object that may contain the following properties:
15
+ - **babel**: `boolean`, defaults to `false`. If `true`, output an AST conforming to Babel's AST format. If `false`, output an AST conforming to the ESTree AST format.
16
+ - **allowReturnOutsideFunction**: `boolean`, defaults to `false`. If `true`, do not error on return statements found outside functions.
17
+ - **assertOperator**: `boolean`, defaults to `false`. If `true`, enable Flow's postfix non-null assertion syntax (`value!`).
18
+ - **flow**: `"all"` or `"detect"`, defaults to `"detect"`. If `"detect"`, only parse syntax as Flow syntax where it is ambiguous whether it is a Flow feature or regular JavaScript when the `@flow` pragma is present in the file. Otherwise if `"all"`, always parse ambiguous syntax as Flow syntax regardless of the presence of an `@flow` pragma. For example `foo<T>(x)` in a file without an `@flow` pragma will be parsed as two comparisons if set to `"detect"`, otherwise if set to `"all"` or the `@flow` pragma is included it will be parsed as a call expression with a type argument.
19
+ - **enableExperimentalComponentSyntax**: `boolean`, defaults to `true`. Controls parsing of Flow component syntax.
20
+ - **enableExperimentalFlowMatchSyntax**: `boolean`, defaults to `true`. Controls parsing of Flow match syntax.
21
+ - **enableExperimentalFlowRecordSyntax**: `boolean`, defaults to `true`. Controls parsing of Flow record syntax.
22
+ - **reactRuntimeTarget**: `"18"` or `"19"`, defaults to `"18"`. Controls how component `ref` parameters are lowered when `babel` is `true`. React 18 treats `ref` as a separate parameter; React 19 treats it as a regular prop.
23
+ - **sourceFilename**: `string`, defaults to `null`. The filename corresponding to the code that is to be parsed. If non-null, the filename will be added to all source locations in the output AST.
24
+ - **sourceType**: `"module"`, `"script"`, or `"unambiguous"` (default). If `"unambiguous"`, source type will be automatically detected and set to `"module"` if any ES6 imports or exports are present in the code, otherwise source type will be set to `"script"`.
25
+ - **throwOnParseErrors**: `boolean`, defaults to `true`. If `true`, throw a `SyntaxError` for the first parse error. If `false`, return the partial AST with parse errors in the root node's `errors` property.
26
+ - **tokens**: `boolean`, defaults to `false`. If `true`, add all tokens to a `tokens` property on the root node.
27
+ - **transformOptions**: `object`. Options to be supplied to relevant transforms.
28
+ - `TransformEnumSyntax`
29
+ - `enable`: `boolean` - Whether to enable the transform. By default, `false`.
30
+ - `getRuntime` (optional): `() => Expression` - The expression which should be a reference to the Flow Enums runtime. By default, is `require('flow-enums-runtime')`.