omarkhan/coffeedoc

reserved word "private"

Closed this issue · 4 comments

Error

$ coffeedoc --renderer gfm --stdout lib/
SyntaxError: reserved word "private" on line 16
    at SyntaxError (unknown source)
    at Lexer.error (/usr/local/lib/node_modules/coffeedoc/node_modules/coffee-script/lib/coffee-script/lexer.js:682:13)
    at Lexer.identifierToken (/usr/local/lib/node_modules/coffeedoc/node_modules/coffee-script/lib/coffee-script/lexer.js:86:16)
    at Lexer.tokenize (/usr/local/lib/node_modules/coffeedoc/node_modules/coffee-script/lib/coffee-script/lexer.js:33:19)
    at Object.nodes (/usr/local/lib/node_modules/coffeedoc/node_modules/coffee-script/lib/coffee-script/coffee-script.js:63:33)
    at CommonJSParser.getNodes (/usr/local/lib/node_modules/coffeedoc/src/parsers.coffee:37:31)
    at Object.documentModule (/usr/local/lib/node_modules/coffeedoc/src/coffeedoc.coffee:33:20)
    at Object.<anonymous> (/usr/local/lib/node_modules/coffeedoc/src/docgen.coffee:115:24)
    at Object.<anonymous> (/usr/local/lib/node_modules/coffeedoc/src/docgen.coffee:141:4)
    at Module._compile (module.js:432:26)

node:

$ node -v
v0.6.6

coffee:

$ coffee -v
CoffeeScript version 1.1.3

https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words

Check the end of lexer.coffee from the coffeescript source. It throws an error at compile time to avoid generating bad javascript.

Golden rule: make sure your code runs before passing it through coffeedoc.

You are correct, I've used local private variable and after change it documentation was generated.

On the other hand, your "Golder rule" is not relevant to this situation - code, that generate this error works fine even with private variable, and I don't give you reason for making so sure, that my code not works.

Resume:
Your documentation generator fails on valid code (at least coffee script lexer thinks so), that may mean, that
you using coffee script lexer on slightly different manner, that was assumed by design.

In this case I think you may add warnings to code, that used uncorrect, but valid syntax.

I could even add patch to your code, if you need it.

The code is not valid. If you run this, the coffeescript lexer will throw an error:

private = 'invalid'  # fails

Coffeedoc uses coffeescript to generate an AST from source files. If it's not valid coffeescript, it will fail. It's not trying to be a code quality tool - you can use something like coffeelint for that, or run your source through coffee --lint to check the compiled js.

Check the coffeescript source here for details: https://github.com/jashkenas/coffee-script/blob/master/src/lexer.coffee#L578

Thanks for coffee lint, I've check and found 'private' vars problems.

But when I lanched this code via coffescrit it was work as expected (I don't compile it to javascript),
that's strange...