#12389·swc

Flow parser fails to parse leading `|` in match cases

Author: leegeunhyeokCreated Sep 17, 2026Updated Sep 17, 2026

Describe the bug

The Flow parser (Syntax::Flow) fails to parse the optional leading | before the first pattern in both match expressions and match statements when pattern_matching is enabled.

This is valid Flow syntax and is used by React Native 0.87.1 in ReactNativeResponder.js. Removing only the first | makes both snippets parse successfully; | between alternative patterns is already supported.

Input code

typescript
// @flow
function isRelevant(kind: string): boolean {
  return match (kind) {
    | 'start'
    | 'move' => true,
    _ => false,
  };
}

function handle(kind: string): void {
  match (kind) {
    | 'start'
    | 'move' => {
      console.log(kind);
    }
    _ => {}
  }
}

Config

rust
Syntax::Flow(FlowSyntax {
    pattern_matching: true,
    ..Default::default()
})

Link to the code that reproduces this issue

https://github.com/leegeunhyeok/match-leading-pipe-repro

SWC Info output

This reproduction uses the Rust parser crates directly:

toml
swc_common = "=26.0.0"
swc_ecma_ast = "=29.0.1"
swc_ecma_parser = { version = "=45.1.3", features = ["flow"] }

Run cargo run --locked in the reproduction repository.

Expected behavior

Both the match expression and match statement should parse successfully. Flow accepts an optional leading | before a match pattern.

Actual behavior

The command exits with status 1. The match expression reports TS1109 and then fails with Expected(";", "=>"). The match statement fails with Unexpected { got: "|", expected: "a pattern" }.

[failed] match expression
  recovered: Error { error: (..., TS1109) }
  fatal: Error { error: (..., Expected(";", "=>")) }
[failed] match statement
  fatal: Error { error: (..., Unexpected { got: "|", expected: "a pattern" }) }

Version

[email protected]

Additional context

The same failure is present on the latest swc main branch at the time of reporting (55ffd3e272be7798bf9c83acee7897110222d118).

The current pattern parser parses a primary first and only consumes pipes that follow it: https://github.com/swc-project/swc/blob/55ffd3e272be7798bf9c83acee7897110222d118/crates/swc_ecma_parser/src/parser/stmt.rs#L1582-L1594


This is message for readers, not the author of ths issue.

Please read no +1 before lefting a comment, or your comment will be deleted and you will be blocked.