Hi all. I was creating a javascript component and when done, noticed that service studio showed "Invalid Script - Script 'xyz' has syntax errors.[...]" in the warnings tab. However, when opening the script, no syntax error whatsoever was indicated and the script works fine (no errors or warnings in the browser console).
What seems to cause the issue, is my usage of field declarations in a class. I've reproduced the same behavior in a tiny test script:
Note the "Invalid Script" warning while no warning is shown in the script window itself. Again, the script runs totally fine. Now, I could omit the field declaration and instead assign the default value in a constructor but I don't believe that's a good coding practice; declaring fields explicitly makes things more readable in my opinion.
Now, my question is: Anyone here with similar experiences? Any suggestions how to get rid of the warning other than brute-force hiding it? If I hide it, I won't see a warning if I (or someone else) actually introduce a syntax error in that script in the future...
Hi @Thomas Milde
Put that assignment in constructor, that warning will leave.
Regards
Murali
Thanks Murali but as I already mentioned in my original post, I don't think this is good coding style. Explicitly declaring fields makes the code more readable in my opinion.
Hello,
I've seen other instances of incorrect warnings about javascript syntax "errors", and what I do in those cases is to just hide the warning. However, as you have correctly pointed out, this could lead to real syntax errors going unnoticed in the future. You could just leave the warning there, and add a comment to your JS code explaining that it's not really a syntax issue, and why the warning is being ignored.
I think your best option here is to open a support ticket to OS pointing out this issue. With a bit of luck, this will result in them adding it to their backlog and eventually fixing it. 🙂
Thanks, I will probably raise it as a support ticket indeed.