Closed Bug 450338 Opened 17 years ago Closed 15 years ago

Last parenthesis of conditional expression not stripped when it is in if statement

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
trivial

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: BijuMailList, Unassigned)

Details

Something nice to have.... http://groups.google.com/group/mozilla.dev.tech.js-engine/browse_thread/thread/46237fccd2df7b21# function a() { x = (a == b) && (c == d) ; if ((a == b) && (c == d) ) { p(); } } alert(a); // gives ==> function a() { x = a == b && c == d; if (a == b && (c == d)) { p(); } } Here all parenthesis of first expression in the function was striped off "x = (a == b) && (c == d) ;" ==> "x = a == b && c == d;" But for the next statement with similar conditional expression the last parenthesis is not removed. ie, "if ((a == b) && (c == d) ) {" ==> "if (a == b && (c == d)) {" now if we add an assignment operator in conditional expression, we will see the problem is gone. ie, " if(x=(a == b) && (c == d) ) {" ==> "if (x = a == b && c == d) {"
// other cases function a() { x = (a == b) && (c == d) && (e == f) && (g == h) ; if((a == b) && (c == d) && (e == f) && (g == h) ); if(x=(a == b) && (c == d) && (e == f) && (g == h) ) ; while((a == b) && (c == d) && (e == f) && (g == h) ) ; while(x=(a == b) && (c == d) && (e == f) && (g == h) ) ; for((a == b) && (c == d) && (e == f) && (g == h) ;;) ; for(;(a == b) && (c == d) && (e == f) && (g == h) ;) ; for(;x=(a == b) && (c == d) && (e == f) && (g == h) ;) ; for(;;(a == b) && (c == d) && (e == f) && (g == h) ) ; do{}while((a == b) && (c == d) && (e == f) && (g == h) ) ; do{}while(x=(a == b) && (c == d) && (e == f) && (g == h) ) ; } // gives ==> function a() { x = a == b && c == d && e == f && g == h; if (a == b && c == d && e == f && (g == h)) { } if (x = a == b && c == d && e == f && g == h) { } while (a == b && c == d && e == f && (g == h)) { } while (x = a == b && c == d && e == f && g == h) { } for (a == b && c == d && e == f && g == h;;) { } for (; a == b && c == d && e == f && (g == h);) { } for (; x = a == b && c == d && e == f && g == h;) { } for (;; a == b && c == d && e == f && g == h) { } do { } while (a == b && c == d && e == f && (g == h)); do { } while (x = a == b && c == d && e == f && g == h); }
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → WORKSFORME
Thanks this is cool function a() { y=(1==(3&4))?((a)+(b)):(a-c); x = ((a == b) && ((c|(c+2)) == (d*d))) && ((c == d) && (c == d)) ; if (((a == b) && ((c|(c+2)) == (d*d))) && ((c == d) && (c == d)) ) { p(); } } alert(a); // strips down all unnecessary parenthesis // and gives ==> function a() { y = 1 == (3 & 4) ? a + b : a - c; x = a == b && (c | c + 2) == d * d && c == d && c == d; if (a == b && (c | c + 2) == d * d && c == d && c == d) { p(); } }
Thanks to jorendorff for pn_parens. /be
You need to log in before you can comment on or make changes to this bug.