jashkenas/coffee-script — Issue #1957: Seriously inconsistent whitespace handling in objects
Author: nicolaskruchten
Created: 2011-12-21 16:00:28+00:00
State: open

If you declare objects which contain values which are arrays declared on multiple lines, the way whitespace is interpreted is very inconsistent and leads to subtle bugs.

I'm trying to represent the following object in Javascript:

```
var myObject = {
foo: {
bar: {
baz: ["hey"]
},
quux: "yo"
}
};
```

The following code in CoffeeScript compiles as expected:

```
myObject =
foo:
bar:
baz: [
"hey"
] #try indenting me!
quux: "yo"
```

But depending on how far over you indent the final square-bracket (there are 9 possible legal positions in this case) you get one of three different compilation outputs: the correct one, one where 'quux' is at the same level as 'foo', and one where 'quux' is not included in the object at all!

Here's the most pathological one:

```
myObject =
foo:
bar:
baz: [
"hey"
] #indent me!
quux: "yo"
```

compiles to

```
var myObject;

myObject = {
foo: {
bar: {
baz: ["hey"]
}
}
};

({
quux: "yo"
});
```

I would say that the expected behaviour should be that all 9 valid positions of the final square bracket should result in the same, correct compile :)

Thanks!