From 8bb1341ff4be1e5849e569676204784b2470dbe1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 15 Jan 2026 10:24:52 +0800 Subject: [PATCH] Update flow parse options (#18641) --- scripts/sync-flow-tests.cjs | 6 +++++- src/language-js/parse/flow.js | 31 +++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/scripts/sync-flow-tests.cjs b/scripts/sync-flow-tests.cjs index bd75abf8d..af3a77447 100644 --- a/scripts/sync-flow-tests.cjs +++ b/scripts/sync-flow-tests.cjs @@ -14,8 +14,12 @@ function tryParse(file, content) { const ast = flowParser.parse(content, { comments: false, enums: true, + match: true, + components: true, + // assert_operator: true, esproposal_decorators: true, - esproposal_export_star_as: true, + pattern_matching: true, + records: true, }); if (ast.errors.length > 0) { diff --git a/src/language-js/parse/flow.js b/src/language-js/parse/flow.js index 527e16e40..b33c75045 100644 --- a/src/language-js/parse/flow.js +++ b/src/language-js/parse/flow.js @@ -6,27 +6,34 @@ import createParser from "./utilities/create-parser.js"; // https://github.com/facebook/flow/tree/main/packages/flow-parser#options // Keep this sync with `/scripts/sync-flow-test.js` const parseOptions = { - // `all_comments` (boolean, default `true`) - include a list of all comments from the whole program - // all_comments: true, + /* Basic options */ + // `types` (boolean, default true) - enable parsing of Flow types + // types: true, + // `use_strict` (boolean, default false) - treat the file as strict, without needing a "use strict" directive + // use_strict: false, // `comments` (boolean, default `true`) - attach comments to AST nodes (`leadingComments` and `trailingComments`) comments: false, + // `all_comments` (boolean, default `true`) - include a list of all comments from the whole program + // all_comments: true, + // `tokens` (boolean, default `false`) - include a list of all parsed tokens in a top-level `tokens` property + // tokens: false, + + /* Language features */ + // `enums` (boolean, default `false`) - enable parsing of enums https://flow.org/en/docs/enums/ + enums: true, + // `match` (boolean, default `false`) - enable parsing of match expressions and match statements https://flow.org/en/docs/match/ + match: true, // `components` (boolean, default `false`) - enable parsing of Flow component syntax components: true, - // `enums` (boolean, default `false`) - enable parsing of Flow enums - enums: true, + // TODO: Support it + // `assert_operator` (boolean, default `false`) - enable parsing of the assert operator + // assert_operator: true, // `esproposal_decorators` (boolean, default `false`) - enable parsing of decorators esproposal_decorators: true, - // `esproposal_export_star_as` (boolean, default `false`) - enable parsing of `export * as` syntax - esproposal_export_star_as: true, // Undocumented pattern_matching: true, + // Undocumented records: true, - // `types` (boolean, default `true`) - enable parsing of Flow types - // types: true, - // `use_strict` (boolean, default `false`) - treat the file as strict, without needing a "use strict" directive - // use_strict: false, - // `tokens` (boolean, default `false`) - include a list of all parsed tokens in a top-level `tokens` property - tokens: false, }; function createParseError(error) {