Community
Participate
Working Groups
Array initializers and object initializers in Javascript are perfectly valid if the last item is terminated by a comma. Currently Eclipse incorrectly signals a syntax error on these commas: x = [1, 2, ]; // same as x = [1, 2]; y = {a: 1, b: 2, }; // same as y = {a: 1, b: 2}; Javascript is more relaxed than Java here because it simplifies the generation of lists of items in indexed arrays or associative arrays/objects... -- Configuration Details -- Product: Eclipse Platform 3.6.0.v201006080911 (org.eclipse.platform.ide) Installed Features: org.eclipse.platform 3.6.0.v20100602-9gF78GpqFt6trOGhL60z0oEx3fz-JKNwxPY
*** This bug has been marked as a duplicate of bug 329716 ***
Reopening after more consideration. There's no error reported *now*.
This was clearly NOT a duplicate for bug 329716, which only addresses the formatting of comma-expressions, where the "comma operator", that exists in JavaScript/ECMAScript (like C and C++) in parenthesized subexpressions or in expression statements (all of them not tolerated in Java) still generates an incorrect parsing error wherever it is found in Javascript/ECMAScript sources. Here we are handling another context, where the comma is not used in comma-expressions, but in array/object initializers, where it is effectively recognized as such, except that this current bug is related to the presence of a "superfluous" comma at end of the list of expressions for the initializer: this is not accepted in Java, but perfectly valid in Javascript/ECMAScript (like also in most C and C++ compilers). This should NOT generate an error, but may only an optional warning for "code beautifiers" (such as the one integrated in the EDT environment when editing Javascript/ECMASCript files), only when working in paranoid mode (because a few bogous Javascript implementations may sometime shoke on the presence of extra commas at end of initializers list, i.e. in constructors of arrays between [], or objects between {}. A simple code reformatting should probably not even remove those extra final commas.
As Philippe points out, trailing commas in initializers are valid according to the ECMAScript standard. I prefer to use them because then all entries in the initializer have the same format so reordering them doesn't cause missing comma errors. Unfortunately, some poor implementations (most notably IE7) don't support them so they have to be avoided in portable code. I'd think this should be added to the list of validation problems whose severity is configurable in Preferences -> JavaScript -> Validator -> Errors/Warnings.
I think the authors of JSDT donot know Javascript Language. I suggest let us close the javascript validation. But eclipse jee 3.7.1 canot close JS validation.I close the Preference of javascript validation and make the level be Ignore ,but eclipse Problems still reports the problems (errors and warnings) of Javascript type . Guys , you all can import a js file ,like JQuery-1.x.min.js , so that you can find too many errors.
One way to ignore the annoying errors is that : 1.remove javascript -> validator -> errors/warning. 2.remove project -> .project file -> javascript command 3.It is important,too! delete js file and import again.
The suggestion to remove the validation is very poor. True ECMAScript syntax errors should still be detected as "errors" and not blindly disabled. trailing commas in initializers lists should only be a warning (only for compatibility with old Javascript implementations that are not conforming to the ECMAScript standard). This warning should be off by default, whilst true syntax errors should be on be default. Once again I request a change of classification by NOT parsing initializer lists as if they were comma expressions (they are not). This requires a very modest change in the syntax analyzer, so that they are parsed differently and the code colorizer works properly on code which is tehnically correct and standard (even if it would bug on old Javascripts for which most developers no longer work for as a primary goal). If needed the developers can enable this specific warning in Eclipse only for compatibility with old Javascript parsers, if their project need this compatibility, or specifically treat it as an error by an explicit preference setting for their specific project : this should require a separate setting.
3 years after reporting it, and still no progress... still marked for a "future milestone" when it is a request for very simple change to fix the JavaScript/ECMAscript parser that incorrectly confuses initializers with comma-expressions. Trailing commas in initializers is definitely not an error but in fact a recommended style, they are part of the language standard. OJ ou may drop them in a compresses javascript version, but these compresses version are built automatically by tools and not intended to be editable. The editable versions will include correct indentation, trailing commas and non obfuscated local variables. Eclipse still should not warn on these commas, and not on standard packages of jQuery
Closed as outdated