如何转义 CoffeeScript 保留字?
我正在尝试使用用 CoffeeScript 编写的 QUnit 运行一些单元测试,但似乎有一些保留字导致了问题,最明显的是“not”。有没有办法转义 CoffeeScript 保留字?下面是一个演示该问题的简单测试:
module "Sad face test"
test "will not compile", ->
not false, "holy crap this creates a syntax error :-("
生成的错误是“Parse error on line 3: Unexpected ','”
I'm trying to run some unit tests using QUnit written in CoffeeScript but there seems to be some reserved words that are causing problems, most notably "not". Is there a way to escape a CoffeeScript reserved word? Here's a simple test that demonstrates the problem:
module "Sad face test"
test "will not compile", ->
not false, "holy crap this creates a syntax error :-("
The error this generates is "Parse error on line 3: Unexpected ','"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能找到的最佳答案是转义为 JavaScript 并给函数起别名:
虽然看起来
not
不是最新版本的 QUnit 中的函数,所以在这个特定的实例中,您可以不需要转义 CoffeeScript 保留字。The best answer I have been able to find is to escape into JavaScript and alias the function:
Although it looks like
not
isn't a function within the latest version of QUnit, so in this specific instance you may not need to to escape a CoffeeScript reserved word.not
函数是全局的,所以它实际上附加到window
,对吗?那么,您可以直接写而不是
not
; 来代替反引号转义。或者The
not
function is global, so it's actually attached towindow
, right? Instead of backtick escapes, then, you can just writeinstead of
not
; or