CoffeeScript 示例代码中出现意外的“INDENT" [英] Unexpected 'INDENT' in CoffeeScript Example Code

查看:23
本文介绍了CoffeeScript 示例代码中出现意外的“INDENT"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我第一次使用 CoffeeScript 时,我遇到了一个问题.为了调试我的问题,我尝试用咖啡脚本站点中的示例代码之一替换我的整个文件:

As I was playing around for the first time with CoffeeScript, I ran in to a problem. In order to debug my problem, I tried replacing my whole file with one of the example bits of code from the coffee script site:

kids =
  brother:
    name: "Max"
    age:  11
  sister:
    name: "Ida"
    age:  9

但是,当我尝试编译该代码时,我得到:

However, when I try to compile that code, I get:

Error: In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'
    at Object.parseError (/usr/lib/coffeescript/parser.js:501:11)
    at Object.parse (/usr/lib/coffeescript/parser.js:573:32)
    at Object.compile (/usr/lib/coffeescript/coffee-script.js:23:22)
    at /usr/lib/coffeescript/command.js:99:27
    at /usr/lib/coffeescript/command.js:72:28
    at fs:84:13
    at node.js:773:9
In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'

由于这是来自 CoffeeScript 站点的代码,我认为代码本身不是问题.但是,编译器似乎也可以正常工作;如果我编译:

Since this is code from the CoffeeScript site, I assume the code itself isn't the problem. However, the compiler also seems to be working properly; if I compile:

a = 2

它会生成一个文件:

(function(){
  var a;
  a = 2;
})();

正如预期的那样.所以换句话说,代码很好,编译器很好,但不知何故我得到了这个 Unexpected 'IDENT' 错误......谁能帮我理解发生了什么?

as expected. So in other words, the code is good, the compiler is good, and yet somehow I'm getting this Unexpected 'IDENT' error ... can anyone help me understand what is going on?

推荐答案

我很确定这是一个 tabs-vs-spaces 问题.如果这样做,请告诉您的编辑器不要将空格转换为制表符.此外,请使用光标浏览您的代码,并确保它不会跳过空白区域.

I am pretty sure this is a tabs-vs-spaces issue. Tell your editor not to convert spaces to tabs if it does that. Also, go through your code with the cursor and make sure it doesn't jump over blank areas.

问题在于,虽然普通编辑器将制表符视为两个或四个空格,但coffeescript 将其视为一个空格,因此缩进会混乱.

The issue is that while normal editors see a tab as equivalent to two or four spaces, coffeescript sees it as one space, so the indentation gets messed up.

如果这一切都没有帮助,请确保您拥有最新的咖啡脚本版本,例如1.1.0 或更高版本.

If this all doesn't help, make sure you have a recent coffeescript version, e.g. 1.1.0 or newer.

这篇关于CoffeeScript 示例代码中出现意外的“INDENT"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆