Ticket #5089: 5089_3.patch

File 5089_3.patch, 2.1 KB (added by Wiktor Walc, 13 years ago)
  • _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
    378375                                scope = new CKPACKAGER.scope( fn, scope );
    379376
     377                                // Named function expression affects only inner scope.
     378                                if ( name.length() )
     379                                {
     380                                        if ( fn.functionType == fn.FUNCTION_EXPRESSION )
     381                                                scope.declareName( name );
     382
     383                                        out( ' ', scope.getNewName( name, 1 ) );
     384                                }
     385
    380386                                out( '(' );
    381387
    382388                                for ( var i = 0, len = scope.args.length ; i < len ; i++ )
     
    394400                                        out( 'var ', scope.getNewName( 'this' ), '=this;' );
    395401
    396402                                tree = fn;
    397                                 writeNode( fn.getFirstChild(), { isFunction : true } );
    398403
     404                                var funcBody =  fn.getFirstChild();
     405
     406                                // Remove the "scope downcast" provided by Rhino.
     407                                if ( fn.functionType == fn.FUNCTION_EXPRESSION && name.length() )
     408                                        funcBody.removeChild( funcBody.getFirstChild() );
     409
     410                                writeNode( funcBody, { isFunction : true } );
     411
    399412                                scope = scope.parent;
    400413                                tree = currentTree;
    401414
    402415                                out( '}' );
    403416
    404                                 if ( name.length() )
     417                                // No trailing semicolon for function expression.
     418                                if ( fn.functionType != fn.FUNCTION_EXPRESSION && name.length() )
    405419                                        out( ';' );
    406420                                break;
    407421
  • 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 =
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy