Coffeescript 1.7.1意外的换行怪异

Mik*_*idt 7 coffeescript

我有以下代码(大约一年),我用它来处理应用程序中的zipcodes.今天我不得不改变一个值,现在突然间我再也无法编译它了.我在"hilleroed"的"h"处得到一个意外的换行符.

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]
Run Code Online (Sandbox Code Playgroud)

我不能为我的生活弄清楚什么是错的.这是一个错误还是我错过了什么?如果我将代码粘贴到coffeescript.org上的在线编译器中,我会得到同样的错误.怎么修?

编辑:

我正在使用咖啡脚本1.7.1.它适用于1.6.3.

更新:

这是一个意想不到的错误,请参阅https://github.com/jashkenas/coffee-script/issues/3408

jco*_*lum 3

问题出在 Office 对象中。此代码失败:

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

当这一切过去时:

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

如果您确实想保留换行符,请添加一些括号:

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

编译器似乎对对象定义的结束位置感到困惑。如果省略括号,您将得到以下 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))
});
Run Code Online (Sandbox Code Playgroud)

当在节点 repl 中运行时,返回:

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

基于js,这是有道理的,但基于咖啡,这是没有意义的。这可能值得作为一个问题提交

TLDR:当您希望将函数返回值分配给对象的字段时,请使用括号。