Index: /CKPackager/trunk/_source/includes/scriptcompressor.js
===================================================================
--- /CKPackager/trunk/_source/includes/scriptcompressor.js	(revision 6329)
+++ /CKPackager/trunk/_source/includes/scriptcompressor.js	(revision 6330)
@@ -369,12 +369,19 @@
 				out( 'function' );
 
-				if ( name.length() )
-					out( ' ', scope.getNewName( name, true ) );
-
 				var currentTree = tree,
 					fnIndex = node.getExistingIntProp( Node.FUNCTION_PROP ),
 					fn = tree.getFunctionNode(fnIndex);
 
+				if ( fn.functionType != 2 && name.length() )
+					out( ' ', scope.getNewName( name, 1 ) );
+
 				scope = new CKPACKAGER.scope( fn, scope );
+
+				// Named function expression affects only inner scope.
+				if ( fn.functionType == 2 && name.length() )
+				{
+					scope.declareName( name );
+					out( ' ', scope.getNewName( name, 1 ) );
+				}
 
 				out( '(' );
@@ -395,5 +402,12 @@
 
 				tree = fn;
-				writeNode( fn.getFirstChild(), { isFunction : true } );
+
+				var funcBody =  fn.getFirstChild();
+
+				// Remove the "scope downcast" provided by Rhino.
+				if ( fn.functionType == 2 && name.length() )
+					funcBody.removeChild( funcBody.getFirstChild() );
+
+				writeNode( funcBody, { isFunction : true } );
 
 				scope = scope.parent;
@@ -402,5 +416,6 @@
 				out( '}' );
 
-				if ( name.length() )
+				// No trailing semicolon for function expression.
+				if ( fn.functionType != 2 && name.length() )
 					out( ';' );
 				break;
Index: /CKPackager/trunk/test/test.js
===================================================================
--- /CKPackager/trunk/test/test.js	(revision 6329)
+++ /CKPackager/trunk/test/test.js	(revision 6330)
@@ -310,5 +310,11 @@
 		[	"var a=(1,2,3,4);" ],
 
-		[	"a=(1,2,3,4);" ]
+		[	"a=(1,2,3,4);" ],
+
+		[	"var A=function B(){var C=1;B();};", "var a=function c(){var b=1;c();};" ],
+
+		[	"var A={foo:function C(){}};", "var a={foo:function b(){}};" ],
+
+		[	"call(function A(){});", "call(function a(){});" ]
 	];
 
