I've had the following coffeescript in production for a few months:
yearSource = (yearsBack) ->
endYear = new Date().getFullYear()+1
label: year, value: year for year in [endYear - yearsBack .. endYear]
That compiled to this script:
yearSource = function(yearsBack) {
var endYear, year, _i, _ref, _results;
endYear = new Date().getFullYear() + 1;
_results = [];
for (year = _i = _ref = endYear - yearsBack; _ref <= endYear ? _i <= endYear : _i >= endYear; year = _ref <= endYear ? ++_i : --_i) {
_results.push({
label: year,
value: year
});
}
return _results;
};
This returns a list of years from the given year forward.
After deploying an update where the scripts were recompiled and suddenly the script looks like this:
yearSource = function(yearsBack) {
var endYear, year;
endYear = new Date().getFullYear() + 1;
return {
label: year,
value: (function() {
var _i, _ref, _results;
_results = [];
for (year = _i = _ref = endYear - yearsBack; _ref <= endYear ? _i <= endYear : _i >= endYear; year = _ref <= endYear ? ++_i : --_i) {
_results.push(year);
}
return _results;
})()
};
};
Since the list is supposed to be the source for a jQuery UI Autocomplete widget this broke things pretty thoroughly.
I can fix it by moving the loop work to a new indented line:
yearSource = (yearsBack) ->
endYear = new Date().getFullYear()+1
for year in [endYear - yearsBack .. endYear]
label: year, value: year
What was I doing wrong that caused things to break between coffeescript versions?
{ label: year, value: year } for year in [endYear - yearsBack .. endYear]. Sounds like a "fix" to CoffeeScript broke your code. Pitfall of using a brand new language.