Skip to content

Flow cannot parse conditional expression that includes assignment and arrow #8731

Open

Description

@sosukesuzuki

Flow version: 0.157.0

Expected behavior

Succeeds in parsing the following code

(a ? (b = c) : d => e);

Actual behavior

Failed to parse the above code

Additional Info

@babel/parser can parse the above code since 7.15.3 (ref: babel/babel#13655 )

Activity

  1. SamChou19815 commented on Aug 20, 2021

    @SamChou19815
    Contributor

    I think Flow is interpreting the sequence (b = c) : d => e to be an arrow function with parameter b of default value c, with return type d and return value e.
    It considers the entire sequence as the first branch of the ternary expression, so it expects a : to start the second branch.
    Actually TypeScript seems to have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions