Is there some tool that can syntax-check my JavaScript files to see if they contain syntax errors that would bother the Javascript engine of Internet Explorer, especially excess trailing commas?
Example:
var some_object = {
valid : "property",
one : "comma too much ---> ",
};
This code works fine in FireFox, Chrome and Node.JS but fails in IE because of the trailing comma. The integrated debugger of IE is rarely a help since it doesn't produce useful errors/warnings for large web applications as we have (lots of JavaScript files combined together summing up to 50-100 k lines of code).
JSLint doesn't help as it reports a huge amount of other warnings or stops at some meaningless error.
One idea could be using eval()
directly within IE and catch SyntaxError exceptions but I can't do this in an automated way (ie. on a command line).
Unfortunately Node.JS doesn't bother about trailing commas.
No Linux / Windows tool around that can do basic JavaScript syntax checking for a file?
I tested the script with IE11 emulator. To find the IE11 emulator, right-click on the web browser click "Inspect element". At the bottom-left of the page, scroll down the navigation bar and click the desktop icon. The "User Agent String" dropdown box contains options to emulate IE6-11.
To detect whether the current browser is Internet Explorer, you can make use of the navigator. userAgent property. The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.
You can try also http://www.javascriptlint.com/. After installed, you may edit jsl.default.conf to set the warnings reported.
jsl -process file.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With