jashkenas / jashkenas/coffeescript

Bug: multiline object literal requires braces in post-loops

Open
#5,299 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

Choose one: is this a bug report or feature request?

A bit of both.

### Input Code

[#try](http://coffeescript.org/#try:use%20k%2C%20v%20for%20k%2C%20v%20of%0A%20%20k%3A%20v%0A)
```coffee
use k, v for k, v of
k: v
```
While this also applies to
```coffee
use k, v for x in # or `from`
k: v

# and

use k, v while # or `until`
k: v
```
i don't see any point in supporting that.

### Expected Behavior
```js
# (shortened)
for (k in {k: v}) {
use(k, v);
}
```
### Current Behavior
```js
[stdin]:2:1: error: unexpected indentation
k: v
^^
```

### Workaround
```coffee
use k, v for k, v of \
k: v \
a: b \
x: y

# or

use k, v for k, v of {
k: v
a: b
x: y
}
```
### Possible Solution

Add implicit line continuation support for objects in *eof* for-of loop *headers*.
The logic used in function calls might be reusable.

### Context

Ran into this a couple of times expecting the compiler to accept it.

### Environment

* CoffeeScript version: v2.5.1
* Node.js version: any



Btw, do you call this an implicit object? What's the term generally used for omitting object braces?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the multiline object examples in the issue with the CoffeeScript compiler and compare the current error with the expected JavaScript. Read the parser logic for end-of-file `for`, `of`, `in`, `while`, and `until` loop headers, especially the implicit line-continuation logic used in function calls. Done means the examples compile without explicit braces or continuation escapes.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.