Reputation: 2096
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?
Upvotes: 18
Views: 48339
Reputation: 3902
Try the Esprima parser. It comes with a syntax validator that will give you the line number of each error.
npm install --global esprima
esvalidate path/to/file.js
outputs
path/to/file.js:915: Unexpected token )
Upvotes: 0
Reputation: 61
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.
Upvotes: 6
Reputation: 20620
Minimize the nesting of functions. It reduces the quality of the code (maintainability-wise).
Upvotes: -1
Reputation: 160201
Re-format the file using something that indents well. Look for something that's too far to the left.
Upvotes: 2