我一直在尝试使用 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。
转到上述站点并将上面的代码片段粘贴到那里。
我也尝试过将其转换为不同的在线工具。
最佳答案
你是对的,问题出在版本上。
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/