Ticket #4692: 4692_3.patch

File 4692_3.patch, 2.5 KB (added by Frederico Caldeira Knabben, 14 years ago)
  • _source/includes/scriptcompressor.js

     
    7676        precedence[ Token.COMMA ] = 17;
    7777
    7878        // Tokens having right-to-left associativity.
    79         // From http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Operator_Precedence
     79        // From https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Operator_Precedence
    8080        var associativityRTL = {};
    8181        associativityRTL[ Token.SETNAME ] =
    8282        associativityRTL[ Token.SETPROP ] =
     
    241241                                        if ( child.getFirstChild() )
    242242                                        {
    243243                                                out( '=' );
     244
     245                                                if ( child.getFirstChild().getType() == Token.COMMA )
     246                                                        out( '(' );
     247
    244248                                                writeChildren( child );
     249
     250                                                if ( child.getFirstChild().getType() == Token.COMMA )
     251                                                        out( ')' );
    245252                                        }
    246253
    247254                                        scope.declareName( name );
     
    289296
    290297                                        default :
    291298                                                out( '=' );
     299
     300                                                if ( value.getType() == Token.COMMA )
     301                                                        out( '(' );
     302
    292303                                                writeNode( value );
     304
     305                                                if ( value.getType() == Token.COMMA )
     306                                                        out( ')' );
     307
    293308                                                break;
    294309                                }
    295310
     
    429444                                var param = child.getNext();
    430445                                while( param )
    431446                                {
     447                                        if ( param.getType() == Token.COMMA )
     448                                                out( '(' );
     449
    432450                                        if ( !writeNode( param ) )
    433451                                                break;
    434452
     453                                        if ( param.getType() == Token.COMMA )
     454                                                out( ')' );
     455
    435456                                        param = param.getNext();
    436457
    437458                                        if ( param )
     
    11151136                                out( lang[ type ] );
    11161137
    11171138                                // The right side.
    1118                                 if ( !parenthesis )
    1119                                         parenthesis = ( precedence[ type ] < ( precedence[ right.getType() ] || 0 ) );
     1139                                parenthesis = ( precedence[ type ] < ( precedence[ right.getType() ] || 0 ) );
    11201140
    11211141                                if ( !parenthesis && !associativityRTL[ type ] && !noAssociativity[ type ] )
    11221142                                        parenthesis = ( precedence[ type ] == ( precedence[ right.getType() ] || 0 ) );
  • test/test.js

     
    289289                        "var a=b?c:d;" ],
    290290
    291291                [       "var a=(b=c)?d:e;" ],
    292                                
     292
    293293                [       "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);" ]
    296307        ];
    297308
    298309        var tests =
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy