最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to keep single-line comments? (Writing greasemonkeyuserscripts in CoffeeScript) - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked Jun 28, 2011 at 0:52 AcornAcorn 50.5k30 gold badges140 silver badges178 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

I don't use CoffeeScript, but from the docs it looks like you could use:

###
// ==UserScript==
// @version       1.0
// ==/UserScript==
###
alert "hello world"


Which would yield:

/*
// ==UserScript==
// @version       1.0
// ==/UserScript==
*/
alert("hello world");

which parses perfectly fine as a GM script. The metadata reads correctly.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论