Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line tool for finding basic Javascript syntax errors?

Are there any command-line Linux tools that can catch basic syntax errors and compile time errors in my Javascript files, even if said Javascript files are written for use in a web browser?

I typically code my Javascript at the same time I'm coding my server side code in say Ruby or Perl. It would save me significant time if I could partially test my client side Javascript the same way I test my server side Ruby and Perl -- on the command line, typically from within emacs. I'm not expecting to catch run time JavaScript errors on the server, just basic things like a mistyped variable name or an extra bracket somewhere or a runaway string, things that could be found before actually attempting to execute the code.

What I do now to test/debug Javascript is the usual cycle of "visit web app in browser; check Firebug or other console; back to emacs to fix errors; repeat." Doing that is certainly unavoidable for more complex types of errors (e.g. involving user and network interaction) but a garden variety syntax error could be caught and dealt with more quickly on the command line without loading up the browser.

I've looked a bit into some server side platforms like node.js, but they all seemed geared toward writing and executing server side code (so all of the client side specific bits in my code would presumably make it barf). I also found an emacs mode for javascript REPL but it doesn't seemed designed to do just basic compile checks - it basically loads the whole page via an external graphical browser and lets you monkey with it, which is precisely what I'm trying to avoid.

like image 596
Ryan Tate Avatar asked Dec 04 '10 21:12

Ryan Tate


People also ask

How use JavaScript command line?

To run the REPL, just type node at the command line. You'll see a new prompt appear—this time, a > instead of a $ . As long as the prompt is > , you can type Javascript expressions and see what they evaluate to (sort of like a calculator). To exit the REPL, type .

How do I see JavaScript errors in Chrome?

In Chrome, navigate to Tools > Advanced > Error Console. The error console will open. Select JavaScript and Errors from the two drop downs. To find the error location, expand one of the errors.


1 Answers

Things like YUICompressor effectively do a syntax check too.

like image 73
Pointy Avatar answered Oct 02 '22 17:10

Pointy