google / google/closure-compiler

Need a better error message for `yield` outside a generator

Open
#2,612 0 comments 1 reaction 0 assignees View on GitHub
Parser
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

[Repro][1]

The following input

```js
yield;
```

produces a very cryptic error message:

```
input0:1: ERROR - Parse error. primary expression expected
yield;
^
```

It should probably be improved to something like "ERROR - yield only allowed inside a generator". Presumably this is as simple as just adding an additional case in Parser#parsePrimaryExpression right before the `default` to throw a different error for a `YIELD` token.

[1]: https://closure-compiler-debugger.appspot.com/#input0%3Dyield%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1

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.