javascript - CoffeeScript 中的意外缩进

标签 javascript coffeescript

我一直在尝试使用 webpack 将我所有的 CoffeeScript 转换成一个包。

但我卡在了一部分。

出现以下错误

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

最佳答案

你是对的,问题出在版本上。

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

Coffeescript 2 编译为 Node 7.6+ 支持的现代 JS 这意味着 Coffeescript 类现在可以编译为 ES6 样式类而不是原型(prototype)。这带来了一些限制,导致 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...

关于javascript - CoffeeScript 中的意外缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49858400/

相关文章:

javascript - style.background 与 grb

javascript - 如果单击选项“否”,则删除输入值

javascript - 获取Controller的返回值给javascript

javascript - 当 Google Script 检测到后台发生变化(例如 cron)时,它如何发送电子邮件?

coffeescript - 使用脚本运行 Coffeescript Interactive (REPL)

ajax - 脊柱.js: "Uncaught Unknown record"

javascript - 如何配置 ColdFusion Model Glue 3 使其不会在 AJAX 请求上重定向?

javascript - 如果存在 2 个或更多相同的结果,则将 select2 建议限制为 1

javascript - EaselJS、Canvas、位图图像质量低且注册点不起作用

javascript - Transpiller 和 Internet Explorer 8