Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 329716 - JSDT can't seem to parse JavaScript's comma operator
Summary: JSDT can't seem to parse JavaScript's comma operator
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.2.4   Edit
Assignee: Chris Jaun CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard: WI39826
Keywords:
: 341937 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-08 17:56 EST by Peter Rybin CLA
Modified: 2011-06-30 18:36 EDT (History)
4 users (show)

See Also:
thatnitind: review+


Attachments
patch for the parser (368.43 KB, patch)
2011-03-23 16:36 EDT, Chris Jaun CLA
no flags Details | Diff
parser zip file (16.57 KB, application/x-zip-compressed)
2011-03-23 16:36 EDT, Chris Jaun CLA
no flags Details
Updated Scanner.java for regex handling (16.57 KB, text/plain)
2011-03-24 17:30 EDT, Nitin Dahyabhai CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Rybin CLA 2010-11-08 17:56:21 EST
Build Identifier: I20100608-0911 (3.6.0)

It seems that JSDT gramma does not really support comma operator

Reproducible: Always

Steps to Reproduce:
1. create a javascript file
2. open it in jsdt editor
3. enter a simple statement with comma expression:
    var z=(1, 2);
expected: non error is highlighted
actual: comma is highlighted as error, "Syntax error on tocken ",", in expected"

4. Try context menu -> Source -> Format
expected: source is changed according to format rules (e.g. more spaces added)
actual: source is not touched by format at all
Comment 1 Chris Jaun CLA 2011-03-23 16:36:09 EDT
Created attachment 191789 [details]
patch for the parser
Comment 2 Chris Jaun CLA 2011-03-23 16:36:54 EDT
Created attachment 191790 [details]
parser zip file
Comment 3 Nitin Dahyabhai CLA 2011-03-24 17:30:11 EDT
Created attachment 191873 [details]
Updated Scanner.java for regex handling
Comment 4 Nitin Dahyabhai CLA 2011-03-24 17:36:38 EDT
Tagged org.eclipse.wst.jsdt.core as v201103242129 before and v201103242136 after.
Comment 5 Chris Jaun CLA 2011-03-24 17:45:07 EDT
org.eclipse.wst.jsdt.compiler.tests tagged as v201103242142 (before) and v201103242144(after)
Comment 6 Chris Jaun CLA 2011-03-30 10:37:51 EDT
checked into 3.2.4 and HEAD.
Comment 7 Nitin Dahyabhai CLA 2011-04-05 16:32:24 EDT
*** Bug 341937 has been marked as a duplicate of this bug. ***
Comment 8 Nitin Dahyabhai CLA 2011-04-18 16:04:19 EDT
Tagging 3.3/HEAD as v201104182003 before.
Comment 9 Nitin Dahyabhai CLA 2011-04-18 17:00:11 EDT
Tagging 3.3/HEAD as v201104182100 after.
Comment 10 Nitin Dahyabhai CLA 2011-06-30 17:29:34 EDT
*** Bug 325280 has been marked as a duplicate of this bug. ***
Comment 11 Philippe Verdy CLA 2011-06-30 17:56:43 EDT
(In reply to comment #10)
> *** Bug 325280 has been marked as a duplicate of this bug. ***

NOT a duplicate, even if this is still a parsing error. See the bug description.

This is a separate issue of the parser related to the presence of optional final commas at end of expression lists in initializers, instead of here within the context of comma-expressions.
Comment 12 Philippe Verdy CLA 2011-06-30 18:36:08 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > *** Bug 325280 has been marked as a duplicate of this bug. ***
> 
> NOT a duplicate, even if this is still a parsing error. See the bug
> description.

Hoaver, the source code proposed for corrct this current bug seems to correctly include the handling of optional commas at end of initializer lists for {object-litterals, } and [new-array-literals, ].

It also seems to correctly accepts empty expressions in those initializers for array litterals (where the comma alone is used to mark an elision to skip an index). Something should be checked for the meaning of final elisions: how many elements are inserted in such [array-litterals, , , , ] ???

Elision makes no sense for object literals where elements can only be indexed by names. However I have not checked if they were invalid. If they are valid, they should just be ignored by the compiler as the indexing name is missing.

However, another interesting thing to check is if the following object litteral is valid or not in Javascript/ECMAScript, and how it is interpreted:

x = {a:, b:};

I.e. should it insert the properties named "a" and "b" in the new object, but assigning them an unassigned value? I need to reread the ECMAScript specification about this detail: can a ECMAScript object enumerate existing properties whose reading will return an unassigned value? (this case exists for example with variables that have been declared "globally" in a window object or in the text of a function body, but still not assigned, or that have been unset explicitly (instead of assigning them explicitly with a null value); the enumeration of properties in their container still finds those declared but unassigned/unbound variables for the purpose of masking local variables/properties that may be bound in an external but accessible caller context or in the context of a "with(object)..." statement).