jashkenas/coffee-script — Issue #1830: parsing error (?) with nested dictionaries
Author: loveencounterflow
Created: 2011-11-05 19:25:25+00:00
State: open

i just experienced an unexpected parsing behavior that kept me 2hrs thinking and searching; it happens when you nest dictionaries without using curly braces. to reproduce, you can use the coffee → js tab on http://js2coffee.org; the sample script there (excerpt)

days =
monday: 1
tuesday: 2

and so on compiles as expected to

var days, today;
days = {
monday: 1,
tuesday: 2
};

however, if you change the input to

days =
monday: foo: 'bar'
tuesday: 2

and believed you would get the analogous interpretation

days = {
monday: {
foo: 'bar'
},
tuesday: 2
};

for your efforts, you were wrong. instead you'll get

days = {
monday: {
foo: 'bar',
tuesday: 2
}
};

which subsumes all of the following entry under the first entry that has a 'naked' dictionary literal. for me this behavior seems to violate the internal logic of coffeescript grammar. anyone with me?