CoffeeScript Source
return sprite: myFunc
width: 79
height: 66
throw:
from: {}
last: {}
Compiled With CoffeeScript 1.1.1
return {
sprite: myFunc({
width: 79,
height: 66
}),
"throw": {
from: {},
last: {}
}
};
Compiled With CoffeeScript 1.3.3
return {
sprite: myFunc({
width: 79,
height: 66
})
};
({
"throw": {
from: {},
last: {}
}
});
This breaks my code. I can see nothing in the changelog between versions. Is this a bug?
I’d call it a bug but the bug was in 1.1.1 and in your code for depending on a particular interpretation of ambiguous code. This:
may be a little ambiguous as to what block
throwis supposed to be in but the 1.3.3 interpretation is the only one that makes sense to me: your indentation doesn’t match your intent.If we add a function wrapper for clarity:
then what little ambiguity was there vanishes and the 1.3.3 interpretation:
makes perfect sense as your structure is just a variation on:
Just because braces and parentheses and what not are optional doesn’t mean that they are forbidden. If the intent of a piece of code structure isn’t obvious at a glance then you should force the structure with some braces and parentheses, something like this perhaps:
or better (IMO):
Unfortunately, you’re going to have to read all your CoffeeScript and add braces as needed. I hope you have a very good test suite.
Interestingly enough, if you drop the
return:then you get this interpretation in the latest:
That makes perfect sense to me as it looks like:
Your explicit
returnintroduces context that isn’t present when thereturnis implied.