Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to keep single-line comments? (Writing greasemonkey/userscripts in CoffeeScript)

Tags:

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?

like image 311
Acorn Avatar asked Jun 28 '11 00:06

Acorn


1 Answers

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.

like image 195
Brock Adams Avatar answered Sep 22 '22 02:09

Brock Adams