Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 363
dgolovin Avatar asked Sep 16 '13 23:09

dgolovin


People also ask

What is the ECMAScript specification?

The ECMAScript specification is a standardized specification of a scripting language developed by Brendan Eich of Netscape; initially named Mocha, then LiveScript, and finally JavaScript. In December 1995, Sun Microsystems and Netscape announced JavaScript in a press release.

Is JavaScript ECMAScript?

JavaScript is a general-purpose scripting language that conforms to the ECMAScript specification. The ECMAScript specification is a blueprint for creating a scripting language. JavaScript is an implementation of that blueprint. On the whole, JavaScript implements the ECMAScript specification as described in ECMA-262.


2 Answers

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

like image 105
pkuzhel Avatar answered Sep 20 '22 11:09

pkuzhel


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.

like image 39
kangax Avatar answered Sep 22 '22 11:09

kangax