Skip to content

Default parameter Flow annotations cause parsing error #5191

@jonvuri

Description

@jonvuri

Annotating a function type in Flowtype with a default parameter (which looks like ?Type) seems to cause a parsing error in the current version of Babel, ^6.21. This could be a regression of #2493.

Input Code

const fn: ( Object, ?Object ) => void = ( o1, o2 ) => o1

https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=const%20fn%3A%20(%20Object%2C%20%3FObject%20)%20%3D%3E%20void%20%3D%20(%20o1%2C%20o2%20)%20%3D%3E%20o1

Babel Configuration (.babelrc, package.json, cli command)

NOTE: Fails on REPL too so probably irrelevant, see link above. Included anyway just in case:

{
  "presets": [
    "es2015",
    "react"
  ],
  "plugins": [
    "react-hot-loader/babel",
    "ramda",
    ["babel-root-slash-import", {
      "rootPathSuffix": "src"
    }],
    ["extensible-destructuring", {
      "mode": "optout",
      "impl": "immutable"
    }]
  ],
  "env": {
    "test": {
      "plugins": [
        "istanbul"
      ]
    }
  }
}

Expected Behavior

The code parses successfully.

Current Behavior

A parsing error occurs at the default parameter Flow annotation:

Unexpected token, expected ) (1:20)
> 1 | const fn: ( Object, ?Object ) => void = ( o1, o2 ) => o1

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions