jashkenas / jashkenas/coffeescript
Nodes: `while` with empty block is inconsistent with empty-block `for`
Nobody has claimed this yet.
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
- `for` with single-expression block containing `undefined`:
```
$ coffee -be 'console.log (for a in [0, 1, 2, 3] then undefined)'
[ undefined, undefined, undefined, undefined ]
```
- `for` with empty block:
```
$ coffee -be 'console.log (for a in [0, 1, 2, 3] then)'
[]
```
- `while` with single-expression block containing `undefined`:
```
$ coffee -be 'i = 4; console.log (while i-- then undefined)'
[ undefined, undefined, undefined, undefined ]
```
- `while` with empty block:
```
$ coffee -be 'i = 4; console.log (while i-- then)'
undefined
```
The value of a `for` or `while` should _always_ be a list. The behaviour of `while` with an empty block should change to produce an empty list so that it is consistent with `for`.
**edit:** an alternative (which I would actually prefer) would be to change the behaviour of the empty-block forms to match the forms with an `undefined` expression.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CoffeeScript compiler entry points that handle `for` and `while` expressions, using the reported `coffee -be` examples as reproduction cases. Add regression coverage for empty-block loops and verify that their results consistently follow the chosen behavior for blocks containing `undefined`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100