2

I'm trying to get CoffeeKup to work with Mozilla's Rhino engine. Not much luck so far. I'm trying this simple template:

templates ?= {}
templates.first = ->
    doctype 5
    html ->
        head ->
            title "#{@title}"
        body ->
            h1 "#{@hello}"

Which I compile into Javascript and then try to render using

CoffeeKup.render(templates.first, {title: 'Say Hello', hello: 'Hello World!'});

But it fails with this:

org.mozilla.javascript.EcmaError: SyntaxError: invalid return (CoffeeKup#304(Function)#230)

In the Javascript version of coffeekup.coffee, line 304 is this one:

return new Function('data', code);

And code line 230 (last line) is this:

).call(data);return __ck.buffer.join('');

Does anything look out of the ordinary or is this perhaps a Rhino bug?

nilskp
  • 3,097
  • 1
  • 30
  • 34
  • Are you sure that very same code you linked works in Node? It gives me the "..." secondary prompt for me like it is waiting for more input, and it throws a SyntyxError in Spidermonkey as well. – Hannes Wallnöfer Jan 03 '12 at 16:44
  • I don't use Node, so no. But even though it looks fine to my eyes, doesn't mean there's not a subtle bug there. Are you able to get Node to consume it if you simplify it or otherwise make any modifications? – nilskp Jan 04 '12 at 15:02
  • I created [this HTML file](http://pastie.org/3125229) and when viewing it in Firefox, the alert has this content: ` Say Hello

    Hello World!

    `, so the code appears to be fine.
    – nilskp Jan 04 '12 at 15:08

1 Answers1

1

If it works on Node/V8 + browsers but not Rhino, you can be fairly certain it's something specific to Rhino (not necessarily wrong, though). In the longer comment at the top of coffeekup.coffee it says that it will run on Node or on browsers, so that's most likely the case.

To really know what's going wrong, you need a debugger where you can step through the code (I don't know how to do that on Rhino, possibly via Eclipse or maybe even jdb if you have all sources at hand and are very Java proficient). If you find something reasonable trivial, try to file an issue, but CoffeeKup doesn't seem to have seen much activity for the last months. If you're up for a challenge, fork, fix and pull request.

Jacob Oscarson
  • 6,363
  • 1
  • 36
  • 46