Forum Bugs

unexpected token reserved("const")

kathar0s
I think this is about ES2015(ES6) problem.

Prince cannot recognize ES6 syntax maybe.

const state = {
activateDownload: false,
toastVisible: false,
toastMessage: '',
toastState: false,
useGNB: true
}

is there a plan to fix this problem?
mikeday
Correct, Prince does not support ES6 at this time. We may fix this in the future, but not in the short term.
jamespaden
Any updated plans to support ES6?

Try DocRaptor - PrinceXML web service and official PrinceXML partner

mikeday
Not yet, but it's something we should think about for 2021. Are there any particular scripts or language features that come up repeatedly?
theadventmaster
Hello Mike,

Alex from DocRaptor support here.

Figure I'll chime in as well since I encounter ES6 concerns in our support queues.

let, Set, Map, and const come up a lot in support inquiries - or at least, they're indicators someone is using ES6+ features and for us to suggest alternatives to them. Functional utilities such as map, reduce, Array.sort, Array.filter, etc. are also commonly used.

Would be great if ES6+ in PrinceXML "just worked". Could make everyone happy both now and in the future (when software vendors inevitably drop ES5 backwards compatibility, which has already occurred with some software libraries).
hallvord
The mentioned array methods are supported - sort, filter, map and reduce :)

Otherwise this looks like a good shortlist, think the only thing I'd add is arrow functions (=>) which I expect to start showing up about now, since IE11 is the only major thing without support at this point.

Announcement: repos for tests/utils

mikeday
Today we have released a new latest build with support for the JavaScript let/const keywords and ES6 lexical scopes! :D
dago
Well as today (Mon 20 Jun 2022 11:46:38 PM CDT) using Prince 14.2

Im getting this error :
prince: dist/index.html:1: error: unexpected token reserved("const")

on this precise html snippet
<script>const foo = ' ' //...</script>

by using this command
prince dist/index.html -o pdf/manual.pdf --pdf-author="Me" --javascript
mikeday
Please try the latest builds.
GetPsyched
Hello, I'm getting a similar error when using v15.1

The command:
prince dist/index.html -o dist/output.pdf --script=https://cdn.tailwindcss.com

The error:
prince: https://cdn.tailwindcss.com/:1: error: SyntaxError: unexpected token reserved("class")
mikeday
Sorry, classes are not yet supported.
GetPsyched
Ah, rip. Can you message in this thread once they're supported? (or link me to some place that I can track for updates on this)