Ticket #4692: 4692_3.patch
File 4692_3.patch, 2.5 KB (added by , 14 years ago) |
---|
-
_source/includes/scriptcompressor.js
76 76 precedence[ Token.COMMA ] = 17; 77 77 78 78 // Tokens having right-to-left associativity. 79 // From http ://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Operator_Precedence79 // From https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Operator_Precedence 80 80 var associativityRTL = {}; 81 81 associativityRTL[ Token.SETNAME ] = 82 82 associativityRTL[ Token.SETPROP ] = … … 241 241 if ( child.getFirstChild() ) 242 242 { 243 243 out( '=' ); 244 245 if ( child.getFirstChild().getType() == Token.COMMA ) 246 out( '(' ); 247 244 248 writeChildren( child ); 249 250 if ( child.getFirstChild().getType() == Token.COMMA ) 251 out( ')' ); 245 252 } 246 253 247 254 scope.declareName( name ); … … 289 296 290 297 default : 291 298 out( '=' ); 299 300 if ( value.getType() == Token.COMMA ) 301 out( '(' ); 302 292 303 writeNode( value ); 304 305 if ( value.getType() == Token.COMMA ) 306 out( ')' ); 307 293 308 break; 294 309 } 295 310 … … 429 444 var param = child.getNext(); 430 445 while( param ) 431 446 { 447 if ( param.getType() == Token.COMMA ) 448 out( '(' ); 449 432 450 if ( !writeNode( param ) ) 433 451 break; 434 452 453 if ( param.getType() == Token.COMMA ) 454 out( ')' ); 455 435 456 param = param.getNext(); 436 457 437 458 if ( param ) … … 1115 1136 out( lang[ type ] ); 1116 1137 1117 1138 // The right side. 1118 if ( !parenthesis ) 1119 parenthesis = ( precedence[ type ] < ( precedence[ right.getType() ] || 0 ) ); 1139 parenthesis = ( precedence[ type ] < ( precedence[ right.getType() ] || 0 ) ); 1120 1140 1121 1141 if ( !parenthesis && !associativityRTL[ type ] && !noAssociativity[ type ] ) 1122 1142 parenthesis = ( precedence[ type ] == ( precedence[ right.getType() ] || 0 ) ); -
test/test.js
289 289 "var a=b?c:d;" ], 290 290 291 291 [ "var a=(b=c)?d:e;" ], 292 292 293 293 [ "if(a){for(;;){if(B){doB();}}}else{doC();}", 294 "if(a)for(;;){if(B)doB();}else doC();" 295 ] 294 "if(a)for(;;){if(B)doB();}else doC();" ], 295 296 [ "a((1,2),3);" ], 297 298 [ "(1,2)+3;" ], 299 300 [ "3+(1,2);" ], 301 302 [ "(1,2);", "1,2;" ], 303 304 [ "var a=(1,2,3,4);" ], 305 306 [ "a=(1,2,3,4);" ] 296 307 ]; 297 308 298 309 var tests =