最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a tool to validate ECMAScript and confirm it is compatible with ECMAScript Language Specification 3rd edit

programmeradmin3浏览0评论

I am currently trying to figure out why JSDT posts errors like 'JavaScript error on valid regex'.

While I was testing I realized that it works fine for simple files like this:

var a = {
    urlParseRE: /^\s*(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
    test: b.replace(/^\/|(\/[^\/]*|[^\/]+)$/g, "")
};

and reports errors on complex files like jQuery.mobile-1.3.1.min.js.

I used online tool to format mimified jQuery script and then deleted almost all content out of it to make a simple example which would help to replicate the problem. When size of file was reduced from around 3000 to 300 lines some new validation errors were posted before original one above. I ended up my experiment with completely different problem. Validation error was posted on ',' in example below:

!function(){
    window.alert("passed 1");
}(),
function(){
    window.alert("passed 2");
}();
window.alert("passed 3");

I understand that JSDT project was dormant for a while and supports only ECMAScript v3 so before I create new issue I'd like to be sure this last simple js example is correct for ECMAScript Language Specification 3rd edition. Is there any online or offline tool to verify that?

I am currently trying to figure out why JSDT posts errors like 'JavaScript error on valid regex'.

While I was testing I realized that it works fine for simple files like this:

var a = {
    urlParseRE: /^\s*(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
    test: b.replace(/^\/|(\/[^\/]*|[^\/]+)$/g, "")
};

and reports errors on complex files like jQuery.mobile-1.3.1.min.js.

I used online tool to format mimified jQuery script and then deleted almost all content out of it to make a simple example which would help to replicate the problem. When size of file was reduced from around 3000 to 300 lines some new validation errors were posted before original one above. I ended up my experiment with completely different problem. Validation error was posted on ',' in example below:

!function(){
    window.alert("passed 1");
}(),
function(){
    window.alert("passed 2");
}();
window.alert("passed 3");

I understand that JSDT project was dormant for a while and supports only ECMAScript v3 so before I create new issue I'd like to be sure this last simple js example is correct for ECMAScript Language Specification 3rd edition. Is there any online or offline tool to verify that?

Share Improve this question edited Jan 26, 2015 at 1:45 Bergi 665k161 gold badges1k silver badges1.5k bronze badges asked Sep 16, 2013 at 23:45 dgolovindgolovin 1,4421 gold badge11 silver badges23 bronze badges 4
  • 1 I don't know any such tool; in any case, the comma operator did exist in ES3. Ref: ecma-international.org/publications/files/ECMA-ST-ARCH/… – bfavaretto Commented Sep 17, 2013 at 0:23
  • Thanks, I installed Konqueror, because its layout engine KHTML supports scripts up to ECMAScript v3 and use it as my validation tool for now. So far my snippet of code works in it and that confirms the syntax I use is valid for v3. – dgolovin Commented Sep 19, 2013 at 22:09
  • not that I know of, but you can always JSLint the code (jslint.com, both online and offline) with settings that match the requirements of ES3. – Mike 'Pomax' Kamermans Commented Sep 19, 2013 at 22:38
  • I've used online version and it seems with configuration /*jslint browser: true, couch: false, es5: false, sloppy: true, white: true */ it doesn't understand that ! operator is equivalent of () and complains "Wrap an immediate function invocation in parentheses to assist the reader in understanding that the expression is the result of a function, and not the function itself". – dgolovin Commented Sep 19, 2013 at 23:03
Add a comment  | 

3 Answers 3

Reset to default 10

A little dated, but https://jshint.com/ points out ES3 and ES5 issues

You can use Esprima for this.

"ECMAScript parsing infrastructure for multipurpose analysis"

If you feed your last chunk to Esprima's validator, it says that "Code is syntatically valid."

Esprima follows ES5, so technically it could pass ES5-related syntax which ES3-only-compliant parser will not understand.

But in this case I don't see anything related to ES5, so it must be a bug in JSDT.

If you are open to using a command line tool, then I would recommend es-check (NPM link). You can test if your JS code conforms to the standard you specify. For example to check if index.js conforms to ES5 you can run:

es-check es5 index.js

Or if you want to check all scripts within a directory you could run:

es-check es5 './scripts/**/*.js'

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论