fix(es/parser): close remaining Flow parser gaps for #11729 (phase 2)#11740
fix(es/parser): close remaining Flow parser gaps for #11729 (phase 2)#11740
Conversation
|
Binary Sizes
Commit: 11259b2 |
Merging this PR will not alter performance
Comparing Footnotes
|
PR Review: fix(es/parser): close remaining Flow parser gaps for #11729 (phase 2)OverallGood work closing the remaining Flow parser gaps. The approach of using speculative parsing ( Code Quality
Potential Issues
Test Coverage
Minor
SummaryThe core logic is correct and well-tested. The main suggestions are around reducing code duplication (especially the |
There was a problem hiding this comment.
Pull request overview
This PR extends swc_ecma_parser’s Flow support to cover additional React Native Flow syntax patterns tracked in #11729, and adds fixture coverage for the new parsing behavior.
Changes:
- Extend Flow component parameter parsing to accept rest type forms in component type contexts (e.g.
...AnimatedProps<Props>,...{ ... }) while preserving named-rest behavior in non-declarecomponent declarations. - Allow anonymous typed parameters in Flow signature/member contexts (including nested function-type params), and prevent decorator parsing from consuming
@@...in Flow mode by parsing@@identkeys as string keys. - Add a new Flow fixture suite (
issue-11729-phase2) with config + source + expected AST output.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/swc_ecma_parser/src/parser/typescript.rs | Main Flow parsing adjustments: component rest-type parsing, Flow anon signature param handling, and @@ident property name handling. |
| crates/swc_ecma_parser/src/parser/pat.rs | Makes parse_formal_param_pat pub(crate) for reuse by Flow-in-type signature parsing. |
| crates/swc_ecma_parser/src/parser/mod.rs | Adds Flow @@ident support to parse_prop_name (string key). |
| crates/swc_ecma_parser/src/parser/class_and_fn.rs | Stops decorator parsing at @@ in Flow mode so @@ident can be parsed as a key. |
| crates/swc_ecma_parser/tests/flow/issue-11729-phase2/config.json | Enables Flow components syntax for the new fixture directory. |
| crates/swc_ecma_parser/tests/flow/issue-11729-phase2/basic.js | New Flow source fixture covering the reported RN patterns. |
| crates/swc_ecma_parser/tests/flow/issue-11729-phase2/basic.js.json | Expected AST output for the new fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return peek!(self).is_some_and(|peek| peek == Token::LBrace); | ||
| } | ||
|
|
||
| cur.is_word() && peek!(self).is_some_and(|peek| peek == Token::Lt || peek == Token::LShift) |
There was a problem hiding this comment.
flow_starts_like_anon_signature_param_type only treats word tokens as anonymous parameter types when followed by </<<. This means anonymous params whose type is a plain identifier (e.g. MethodName / Foo) won’t be parsed via try_parse_flow_anon_signature_param and will instead be treated as a named parameter with no type annotation. Consider broadening the start check (or relying on the post-parse_ts_type delimiter/marker checks) so identifier-only anonymous param types are handled consistently with other anon-param types.
| cur.is_word() && peek!(self).is_some_and(|peek| peek == Token::Lt || peek == Token::LShift) | |
| if cur.is_word() { | |
| // Treat identifier-like tokens as potential anonymous parameter types | |
| // unless they are immediately followed by a delimiter that clearly | |
| // indicates a named parameter (`id:`, `id?`, or `id =`). | |
| return !peek!(self) | |
| .is_some_and(|peek| matches!(peek, Token::Colon | Token::QuestionMark | Token::Eq)); | |
| } | |
| false |
| _ => unexpected!( | ||
| self, | ||
| p, | ||
| "an identifier, [ for an array pattern, { for an object patter or ... for a \ |
There was a problem hiding this comment.
Typo in the unexpected! message: "object patter" should be "object pattern".
| "an identifier, [ for an array pattern, { for an object patter or ... for a \ | |
| "an identifier, [ for an array pattern, { for an object pattern or ... for a \ |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39f65b5ffc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else if p.syntax().flow() | ||
| && cur == Token::At | ||
| && peek!(p).is_some_and(|peek| peek == Token::At) | ||
| { |
There was a problem hiding this comment.
Restrict @@ key parsing to declaration/type contexts
parse_prop_name is reused by runtime object/class member parsing as well as Flow declaration parsing, so this new flow && @@ fast-path now accepts value-level syntax that should still be rejected. In Flow mode, inputs like ({ @@iterator() {} }) or class C { @@iterator() {} } will be interpreted as string-key members instead of producing a syntax error, which changes parser correctness outside the intended declare/type-member cases. Please gate this branch to the specific Flow declaration/type contexts that actually support @@ident keys.
Useful? React with 👍 / 👎.
Summary
...AnimatedProps<Props>,...Props<any, T>, and...{ ... }component Foo(...rest) {}) by keeping named-rest parsing there:,?, or=markers are present@@...in Flow mode and parse@@identkeys as string keys ("@@ident")crates/swc_ecma_parser/tests/flow/issue-11729-phase2Testing
git submodule update --init --recursiveUPDATE=1 cargo test -p swc_ecma_parsercargo test -p swc_ecma_parsercargo fmt --allcargo clippy --all --all-targets -- -D warningscargo test -p swc_ecma_parser --features flow --test flow -- --ignoredCloses #11729