Ticket #5089: 5089_3.patch
File 5089_3.patch, 2.1 KB (added by , 13 years ago) |
---|
-
_source/includes/scriptcompressor.js
368 368 369 369 out( 'function' ); 370 370 371 if ( name.length() )372 out( ' ', scope.getNewName( name, true ) );373 374 371 var currentTree = tree, 375 372 fnIndex = node.getExistingIntProp( Node.FUNCTION_PROP ), 376 373 fn = tree.getFunctionNode(fnIndex); 377 374 378 375 scope = new CKPACKAGER.scope( fn, scope ); 379 376 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 380 386 out( '(' ); 381 387 382 388 for ( var i = 0, len = scope.args.length ; i < len ; i++ ) … … 394 400 out( 'var ', scope.getNewName( 'this' ), '=this;' ); 395 401 396 402 tree = fn; 397 writeNode( fn.getFirstChild(), { isFunction : true } );398 403 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 399 412 scope = scope.parent; 400 413 tree = currentTree; 401 414 402 415 out( '}' ); 403 416 404 if ( name.length() ) 417 // No trailing semicolon for function expression. 418 if ( fn.functionType != fn.FUNCTION_EXPRESSION && name.length() ) 405 419 out( ';' ); 406 420 break; 407 421 -
test/test.js
309 309 310 310 [ "var a=(1,2,3,4);" ], 311 311 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(){});" ] 313 319 ]; 314 320 315 321 var tests =