是否可以保留单行注释? (用CoffeeScript编写greasemonkey/userscripts)
我注意到编译 CoffeeScript 时,没有保留任何单行注释。
这是有问题的,因为我正在尝试在 CoffeeScript 中编写 Greasemonkey/用户脚本,并且它们依赖于元数据块的注释。
我尝试过使用反引号,但注释周围的反引号似乎存在问题:
`// ==UserScript==
// @version 1.0
// ==/UserScript==`
alert "hello world"
成为
// ==UserScript==
// @version 1.0
// ==/UserScript==;alert("hello world");
如果我在结束反引号之前添加额外的行,我会得到:
// ==UserScript==
// @version 1.0
// ==/UserScript==
;alert("hello world");
拥有自动换行的便利也将是很好的..但我假设没有 -bare
元数据块也会被包装。
我有更好的方法可以解决这个问题吗?
I've noticed that when compiling CoffeeScript, none of the single-line comments are retained.
This is problematic as I'm trying to write a greasemonkey/userscript in CoffeeScript, and they rely on comments for the metadata block.
I've tried using backticks, but there seems to be a problem with backticks around comments:
`// ==UserScript==
// @version 1.0
// ==/UserScript==`
alert "hello world"
Becomes
// ==UserScript==
// @version 1.0
// ==/UserScript==;alert("hello world");
And if I add an extra line before the closing backtick I get:
// ==UserScript==
// @version 1.0
// ==/UserScript==
;alert("hello world");
It would also be nice to have the convenience of automatic wrapping.. but I suppose without -bare
the metadata block would be wrapped as well.
Is there a better way I could be going about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不使用 CoffeeScript,但从文档看来您可以使用:
这将产生:
它作为 GM 脚本解析得非常好。元数据读取正确。
I don't use CoffeeScript, but from the docs it looks like you could use:
Which would yield:
which parses perfectly fine as a GM script. The metadata reads correctly.