咖啡脚本中的意外缩进

unexpected indentation in coffee-script

我一直在尝试使用 webpack 将我所有的咖啡脚本转换成一个包。

但是我卡在了一部分。

出现以下错误

error: unexpected indentation

super

我有一小段代码。

class p
  check: (x,y,z) ->
    if x and y
        super
    else
        if y
            x = y
        else
            super

当我在 http://coffeescript.org/

中检查时,我能够重现此错误

但是,http://js2.coffee/ 能够将其转换为 javascript。

转到上述站点并将上面的代码片段粘贴到那里。

我也尝试过将其转换为不同的在线工具。

Tool 1

这是由于咖啡脚本的版本。

http://coffeescript.org/中有最新版本,

而在 http://js2.coffee/ 中,它有 version 1.9.2

当我降级版本时,我能够解决我的问题。

根据目前的要求,我已经将其降级,它是我问题的解决方案。

如果有人有不同的答案,请post你的答案。

谢谢

你说得对,是版本问题

coffeescript.org/try 使用 coffeescript 2.X.X(当前为 2.2.4)

Coffeescript 2 编译为 Node 7.6+ 支持的现代 JS 这意味着 Coffeescript 类 现在可以编译为 ES6 风格 类 而不是原型。这带来了一些限制,导致 Coffeescript 2 发生变化。

来自coffeescript 2 announcement :

In CoffeeScript 2, “bare” super (calling super without arguments) is now no longer allowed, and one must use super() or super arguments... instead.

您需要更改 super 以将所有参数显式传递给被覆盖的方法:super arguments...

class p
  check: (x,y,z) ->
    if x and y
      super arguments...
    else
      if y
        x = y
      else
        super arguments...