Forum How do I...?

Error when generating a PDF with the --javascript flag

brad
Generating my PDF with the --javascript flag, I'm getting this error:

prince: /path/to/application.js:38034: error: unexpected token keyword("delete")

Which is just a call to delete an Angular resource (ExampleResource.delete()), and I believe is valid JavaScript.

Does anyone have any idea why this is throwing an error or how to work around it?
mikeday
"delete" is a JavaScript keyword, and there are a number of places where it cannot be used as a valid identifier. For example, "function delete() { ... }" will not work. However, it seems that web browsers accept it as an object property name, while Prince does not. A quick workaround would be to refer to it as ExampleResource["delete"]() which will avoid the problem. We will investigate the compatibility issue.
mikeday
I think we can fix this issue shortly. Which platform are you running Prince on? We can create an updated alpha build for you to try.
brad
Thanks for the speedy response! When I used that workaround for all the keywords (I've listed all the ones I ran into at the bottom of this response in case you're interested), I ran into a new issue:

prince: /path/to/application.js:9237: error: TypeError: undefined value is not an object

Unfortunately, that line is minified Angular, so it's impossible to debug. The new plan is to generate the HTML with Node, then pass the static HTML to Prince.

As I mentioned, other keyword errors I ran into are "finally" (as a method on an object), "int" (in a function's scope), "class" (as a method on an object), and "new" (as a key in an object).
mikeday
For the record, the JavaScript keyword issue has been fixed in the latest Prince alpha version. Thanks for letting us know about it! :)