Skip to main content

Bug Tracker

Side navigation

#7032 closed bug (fixed)

Opened September 14, 2010 06:02PM UTC

Closed October 01, 2010 06:35AM UTC

Last modified March 13, 2012 11:11PM UTC

Syntax error on comma expressions between parentheses, fails in Eclipse

Reported by: verdy_p Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: syntax error, Eclipse Cc:
Blocked by: Blocking:
Description

This line in jQuery 1.4.2, within Sizzle() function chokes some javascript interprets (for example in Javascript projects open in Eclipse, due to a parser bug):

Reset the position of the chunker regexp (start from head)

while ( (chunker.exec(''), m = chunker.exec(soFar)) !== null ) {

...

}

The parser does not accept comma expressions in while() conditions tested against identity with null (even if we try to add extra parentheses); a simple equivalent fix is:

while (chunker.exec(''), (m = chunker.exec(soFar)) !== null) {

...

}

In fact only the second expression is really tested, the first one in the comma expression is discarded. and replaced by the second to get the result of the comma expression tested against null identity.

This should normally be also equivalent to:

while ((chunker.exec(''), (m = chunker.exec(soFar)) !== null)) {

...

}

... but here again the surrounding parentheses are causing the same bug on the comma (Eclipse claims that it expects a dot instead of the comma, as if we were about to get properties from the returned String object.

Apparently, Eclipse's Javascript engine attempts to optimize tests against null identities (assuming we are testing object references), and chokes on such expression, or failing to correctly infer types for the comma expression.

If you really want to discard the result of the first Regexp.exec() call, you could do that more explicitly like this:

while (true) {

chunker.exec('');

if (m = chunker.exec(soFar)) === null)) break;

...

}

But shouldn't the first call to chunker.exec() have its result tested, even if we discard it ? If so this could be:

Reset the position of the chunker regexp (start from head)

while ( chunker.exec('') != null &&

(m = chunker.exec(soFar)) !== null ) {

Note: I also filed the Javascript parsing bug bug to Eclipse.

Bug seen in Eclipse version Version: 3.6.0 (Helios). See Eclipse bug 325279.

PLEASE DON'T use comma expressions, except in very few places to assign multiple variables (e.g. in a for loop), and without surrounding parentheses.

Attachments (0)
Change History (1)

Changed October 01, 2010 06:35AM UTC by snover comment:1

priority: → undecided
resolution: → fixed
status: newclosed

Looks like this has been replaced with a do… while in 1.4.3 already.