不匹配的括号:快速找到它们的方法?
我刚刚重新排列了一个非常大的 JavaScript 文件。我现在收到“输入意外结束”。在这数百个函数中的某个地方,有一个函数丢失了(或增加了)一个括号。找到它最快的方法是什么?
I just rearranged a very large JavaScript file. I now get "Unexpected end of input." Somewhere in those hundred of functions, one has lost (or gained) a bracket. What's the quickest way to find it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Eclipse 中缺少大括号时,一个好技巧是转到源模块中的最后一个大括号并双击它。这将一直突出显示它所认为的匹配的左大括号。它突出显示的位置始终是问题所在的开始位置,因此请跳过该左大括号并转到下一个,然后开始双击左大括号,您通常会很快找到大括号缺失的位置。我通过一个包含 20,000 多行代码的源代码文件艰难地了解到这一点,并收到数百个错误,而没有丝毫迹象表明真正的问题在哪里,因为错误开始出现在代码中的数千行中。
A good trick when missing a brace in eclipse is to go to the final brace in the source module and double-click it. That will highlight all the way back to what it THINKS is the matching open brace. Where it highlights back to is invariably the START of where the problem is, so skip that open brace and go to the next one and start double-clicking open braces and you will usually find where the brace is missing pretty quickly. I learnt that the hard way with a source code file of 20,000+ lines of code and getting hundreds of errors without the slightest indication as where the real problem was as the errors started appearing thousands of lines earlier in the code.
使用缩进良好的内容重新格式化文件。寻找离左侧太远的东西。
Re-format the file using something that indents well. Look for something that's too far to the left.
尝试 Esprima 解析器。它带有一个语法验证器,可以为您提供每个错误的行号。
输出
Try the Esprima parser. It comes with a syntax validator that will give you the line number of each error.
outputs
尽量减少函数的嵌套。它降低了代码的质量(可维护性)。
Minimize the nesting of functions. It reduces the quality of the code (maintainability-wise).