facebook / facebook/flow

Parser recovers badly when function declaration is missing identifier

Open
#3,300 0 comments 0 reactions 0 assignees View on GitHub
parsing
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

`function () {}` (a statement, not an expression) errors with an "unexpected token (" because it's missing the function name. but it recovers by making an `Identifier` with name `(`, which is also illegal.

```
{
"type": "Identifier",
"name": "(",
"typeAnnotation": null,
"optional": false
}
```

maybe instead it should use an Identifier with name `""`. or, we allow `FunctionDeclaration` to have a null id for `export default function() {}`, so maybe it's slightly less invalid to use null instead of an invalid identifier.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.