用于 Internet Explorer 的 JavaScript 语法检查

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6524413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 20:56:46  来源:igfitidea点击:

javascript syntax check for Internet Explorer

javascriptinternet-explorersyntax-checking

提问by Udo G

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?

是否有一些工具可以对我的 JavaScript 文件进行语法检查,以查看它们是否包含会干扰Internet Explorer的 Javascript 引擎的语法错误,尤其是多余的尾随逗号?

Example:

例子:

var some_object = {
  valid : "property",
  one : "comma too much ---> ",
};

This code works fine in FireFox, Chrome and Node.JSbut 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).

这段代码在 FireFox、Chrome和 Node.JS 中运行良好但在 IE 中由于尾随逗号而失败。IE 的集成调试器很少有帮助,因为它不会像我们那样为大型 Web 应用程序产生有用的错误/警告(大量 JavaScript 文件组合在一起,总计 50-100 k 行代码)。

JSLintdoesn't helpas it reports a huge amount of other warnings or stops at some meaningless error.

JSLint没有帮助,因为它报告了大量其他警告或在一些无意义的错误处停止。

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).

一个想法可能是eval()直接在 IE 中使用并捕获 SyntaxError 异常,但我无法以自动方式(即在命令行上)执行此操作。

Unfortunately Node.JSdoesn't bother about trailing commas.

不幸的是,Node.JS并不关心尾随逗号。

No Linux / Windows tool around that can do basic JavaScript syntax checking for a file?

没有 Linux / Windows 工具可以对文件进行基本的 JavaScript 语法检查吗?

采纳答案by Prusse

You can try also http://www.javascriptlint.com/. After installed, you may edit jsl.default.conf to set the warnings reported.

您也可以尝试http://www.javascriptlint.com/。安装后,您可以编辑 jsl.default.conf 来设置报告的警告。

jsl -process file.js

jsl -process file.js

回答by Ira Baxter

Our JavaScript Formatterwill prettyprint your JavaScript code. It uses a full JavaScript parser to do so. It reports syntax errors as it parses. Windows.

我们的JavaScript Formatter将漂亮地打印您的 JavaScript 代码。它使用一个完整的 JavaScript 解析器来做到这一点。它在解析时报告语法错误。视窗。