jashkenas / jashkenas/coffeescript

Nodes: `while` with empty block is inconsistent with empty-block `for`

Open
#2,446 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

change
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.