Ticket #5089: 5089_2.patch

File 5089_2.patch, 2.1 KB (added by Garry Yao, 13 years ago)
  • trunk/test/test.js

     
    309309
    310310                [       "var a=(1,2,3,4);" ],
    311311
    312                 [       "a=(1,2,3,4);" ]
     312                [       "a=(1,2,3,4);" ],
     313
     314                [       "var A=function B(){var C=1;B();};", "var a=function c(){var b=1;c();};" ],
     315
     316                [       "var A={foo:function C(){}};", "var a={foo:function b(){}};" ],
     317
     318                [       "call(function A(){});", "call(function a(){});" ]
    313319        ];
    314320
    315321        var tests =
  • trunk/_source/includes/scriptcompressor.js

     
    368368
    369369                                out( 'function' );
    370370
    371                                 if ( name.length() )
    372                                         out( ' ', scope.getNewName( name, true ) );
    373 
    374371                                var currentTree = tree,
    375372                                        fnIndex = node.getExistingIntProp( Node.FUNCTION_PROP ),
    376373                                        fn = tree.getFunctionNode(fnIndex);
    377374
     375                                if ( fn.functionType != 2 && name.length() )
     376                                        out( ' ', scope.getNewName( name, 1 ) );
     377
    378378                                scope = new CKPACKAGER.scope( fn, scope );
    379379
     380                                // Named function expression affects only inner scope.
     381                                if ( fn.functionType == 2 && name.length() )
     382                                {
     383                                        scope.declareName( name );
     384                                        out( ' ', scope.getNewName( name, 1 ) );
     385                                }
     386
    380387                                out( '(' );
    381388
    382389                                for ( var i = 0, len = scope.args.length ; i < len ; i++ )
     
    394401                                        out( 'var ', scope.getNewName( 'this' ), '=this;' );
    395402
    396403                                tree = fn;
    397                                 writeNode( fn.getFirstChild(), { isFunction : true } );
    398404
     405                                var funcBody =  fn.getFirstChild();
     406
     407                                // Remove the "scope downcast" provided by Rhino.
     408                                if ( fn.functionType == 2 && name.length() )
     409                                        funcBody.removeChild( funcBody.getFirstChild() );
     410
     411                                writeNode( funcBody, { isFunction : true } );
     412
    399413                                scope = scope.parent;
    400414                                tree = currentTree;
    401415
    402416                                out( '}' );
    403417
    404                                 if ( name.length() )
     418                                // No trailing semicolon for function expression.
     419                                if ( fn.functionType != 2 && name.length() )
    405420                                        out( ';' );
    406421                                break;
    407422
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy