Coffeescript 1.7.1 unexpected newline weirdness

I have the following code (about a year) that I use to work with zipcodes in an application. Today I had to change the value, and now I suddenly can not compile it. I get an unexpected new line at "h" in "hilleroed".

class Application postal_codes: regions: sjaelland:[0..4999] fyn: [5000..5999] soenderjylland: [6000..6200] .concat [6261..6280] .concat [6600..6899] .concat [6041..6064] .concat [6960] .concat [7000..7079] .concat [7200] .concat [7250] nordmidtjylland: [6900..6999] .concat [7080..7199] .concat [7182..7184] .concat [7190..7190] .concat [7260..9999] office_postal: ringsted: 4100 hilleroed: 3400 kgslyngby: 2800 odense: 5220 haderslev: 6100 esbjerg: 6715 herning: 7400 aalborg: 9200 aarhus: 8210 horsens: 8700 offices: ringsted: [0..2690] .concat [2770,2791] .concat [4000..4030] .concat [4050..4990] hilleroed: [2700..2765] .concat [2980..3670] .concat [4040] kgslyngby: [2800..2970] odense: [5000..5985] haderslev: [6000..6240] .concat [6300..6622] .concat [6630..6640] .concat [7000..7080] .concat [7182..7184] esbjerg: [6261..6280] .concat [6623] .concat [6650..6879] # 6880 is herning.. meh .concat [6881..6893] .concat [6960] .concat [7200..7260] herning: [6880] .concat [6900..6950] .concat [6971..6990] .concat [7270..7280] .concat [7330..7680] .concat [7800..7884] .concat [8800] .concat [8831] aalborg: [7700..7790] .concat [7900..7990] .concat [8832] .concat [8970] .concat [9000..9999] aarhus: [8000..8270] .concat [8305..8340] .concat [8355..8643] .concat [8660..8670] .concat [8830] .concat [8840..8963] .concat [8981..8990] horsens: [7100..7173] .concat [7190] .concat [7300..7323] .concat [8300,8350] .concat [8653..8659] .concat [8680..8783] 

I can’t understand in my life what happened. Is this a mistake, or am I missing something? If I paste the code into an online compiler at coffeescript.org, I get the same error. How to fix?

EDIT:

I am using coffee script 1.7.1. It works in 1.6.3.

UPDATE:

This is an unexpected error, see https://github.com/jashkenas/coffee-script/issues/3408

+6
source share
1 answer

The problem is the office facility. This code does not work:

 offices: ringsted: [0..2690] .concat [2770, 2791] .concat [4000..4030] .concat [4050..4990] hilleroed: [2700..2765] .concat [2980..3670] .concat [4040] kgslyngby: [2800..2970] 

While this goes:

 offices: ringsted: [0..2690].concat [2770, 2791].concat [4000..4030].concat [4050..4990] hilleroed: [2700..2765].concat [2980..3670].concat [4040] kgslyngby: [2800..2970] 

If you really want to keep line breaks, add a few characters:

 offices: ringsted: ([0..2690] .concat [2770..2791] .concat [4000..4030] .concat [4050..4990]) hilleroed: ([2700..2765] .concat [2980..3670] .concat [4040]) kgslyngby: [2800..2970] 

It seems like the compiler is confused about where your object definitions end up. If you leave without a password, you will get this js:

 // without parens var _i, _j, _k, _l, _results, _results1, _results2, _results3; ({ offices: { ringsted: (function() { _results3 = []; for (_l = 0; _l <= 233; _l++){ _results3.push(_l); } return _results3; }).apply(this) }.concat((function() { _results2 = []; for (_k = 2770; _k <= 2791; _k++){ _results2.push(_k); } return _results2; }).apply(this)).concat((function() { _results1 = []; for (_j = 4000; _j <= 4030; _j++){ _results1.push(_j); } return _results1; }).apply(this)).concat((function() { _results = []; for (_i = 4050; _i <= 4990; _i++){ _results.push(_i); } return _results; }).apply(this)) }); 

What when launched in node repl returns:

TypeError: Object #<Object> has no method 'concat'

Which makes sense based on js but doesn't make sense based on coffee. This may be worth the problem .

TL; DR : use parens when you want function return values ​​to be assigned to an object field.

+2
source

All Articles