The unexpected token is something that the browser is burping on. Sometimes is is simply a typo, a } instead of ). But you will encounter situation in which your code is squeaky clean and you know there's nothing extra. You even log the raw html to the console log so you can eyeball the actual stream of characters being sent to the browser.
After a great many trails and errors and false paths, the only thing that has fixed this error in my environment -- Google Apps Script webapp on Chrome on the latest Windows platform -- is to break up my script into a whole bunch of little ones. Probably will also work if I follow the best practices and move most the the script into other html files and include them between separate script pairs..
html...
<script>
code function
</script>
<script>
code some lines; declarations, assignments
</script>
<script>
code another function
</script>
html...
My tentative conclusion is that there is something seriously wrong with the way the apps script editor handles the <script> tag. Adding a bunch of unnecessary ones made the error go away when there wasn't one visible in the raw data.
Since Google recently hit me up with a survey about how to improve the apps script editor, my hopes are up that they are in fact working on it. . They didn't ask much in the quick survey and about all I wrote there was to make the syntax checking and hint stuff more like brackets and to use a live preview like brackets does.
I don't mind working in an IDE that lives in browser windows. My first IDE was Borland's Delphi, and I've worked in the Oracle, IBM and Microsoft versions. Google is a lot less restrictive but sometimes harder to find out what you need. The one thing about IDE that make them work best is their central organizing tool; usually an interactive outline that has links to everything you need.
I do hope that space on the left in the Apps Script editor is brought up to modern IDE standards.
Just curious: bunch of these lines are showing up in my console window when I'm loading my webapp into Chrome. Should I be concerned? is there something in my code causing this?
content-ads.js:1 INS: content-ads.js loaded: about:blank
content-tss.js:50 TSS: Excluding content tss (trigger: send-message)