te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>debugging - Command line tool for finding basic Javascript syntax errors? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debugging - Command line tool for finding basic Javascript syntax errors? - Stack Overflow

programmeradmin3浏览0评论

Are there any mand-line Linux tools that can catch basic syntax errors and pile 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 mand 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 plex 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 mand 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 pile 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.

Are there any mand-line Linux tools that can catch basic syntax errors and pile 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 mand 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 plex 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 mand 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 pile 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.

Share Improve this question edited Oct 24, 2013 at 18:50 Eric Leschinski 154k96 gold badges422 silver badges337 bronze badges asked Dec 4, 2010 at 21:40 Ryan TateRyan Tate 1,6032 gold badges16 silver badges21 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 1

Things like YUICompressor effectively do a syntax check too.

This isn't a direct answer to your question as it is a GUI tool, but I'm a big fan of Aptana. It uses SpiderMonkey to pile your code in the background and give you red squigglies for syntax errors as you type. (It also does the same for HTML.) It also tries to give you intellisense for JS, but it is hit-or-miss. It is nice when it works.

Since I probably haven't convinced you to change your development environment, let's answer your question directly. Why not use the SpiderMonkey engine to throw together a mand-line app that does what you're looking for? It looks easy enough to plug in. You won't even have to worry about the fact that you're guaranteed to get runtime exceptions (there will be no DOM objects in your environment) — you don't have to actually execute the script. Just call JS_CompileScript and check for success. (And then destroy the JSScript object, of course.)

Or, if you're lazy, you could try Rhino Shell, which is a mand-line Java tool which executes JavaScript.

I find JSHint, + its vim plugin are very useful. Light weight of vim and still be able to track the syntax errors of the javascript. JSHint can also be used as a mand line tool.

https://github./walm/jshint.vim

I wrote quick-lint-js for this purpose. It points out syntax errors, among other things.

quick-lint-js integrates with several code editors, such as Vim and Visual Studio Code. It also has a UNIX-style mand-line utility if you prefer.

Javascript debugger with a console in chrome:

The Chrome browser has a javascript debugger can find JavaScript errors:

In Chrome click Tools -> JavaScript Console:

This is examining a JavaScript page with the following code:

var error(){

}

And it tells me what is wrong with it, unexpected '('.

Telling me I can't define a function like that on line 14 of my javascript file.

If you click on the link next to the error, it will take you to and highlight the line that has the error/warning.

发布评论

评论列表(0)

  1. 暂无评论