Is there a tool to validate ECMAScript and confirm it is compatible with ECMAScript Language Specification 3rd edition?

StackOverflow https://stackoverflow.com/questions/18839149

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?

有帮助吗?

解决方案 2

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top