[dojo-contributors] [patch] Forward References Confuse the Compressor

Timothy Williamson tim at ninginc.com
Fri Jun 23 17:58:24 EDT 2006


Hello Dojo Folks,

In trying to get the wonders of custom_rhino compression to play nice  
with TrimPath's template.js, we hit upon a bug!  Specifically, the  
TrimPath people love to use forward references, e.g.:
function() {
	function foo() {
		bar();
	}
	var bar = function() {
		alert("Hi!");
	}
	foo();
}

Dojo's custom_rhino compressor mangles this into:
function(){
function foo(){
bar();
}
var _1=function(){
alert("Hi!");
};
foo();
}

Note that the reference to bar() in foo did not get converted to _1 
().  That is, the output should have been:
function(){
function foo(){
_1();
}
var _1=function(){
alert("Hi!");
};
foo();
}

The attached patch applies all the same changes as custom_rhino.diff  
as well as a few more changes to src/org/mozilla/javascript/ 
Decompiler.java which track the scope of undeclared variable uses and  
substitute the shortened version where appropriate when the variable  
is later defined.  As custom_rhino.diff fails against the current  
Rhino head, I applied my changes to ftp://ftp.mozilla.org/pub/ 
mozilla.org/js/rhino1_6R2.zip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: custom_rhino_forward_references.diff
Type: application/octet-stream
Size: 35717 bytes
Desc: not available
Url : http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20060623/20f6606a/attachment.dll 
-------------- next part --------------
Let me know if you run into any problems applying the diff or using  
the new code!

--Tim


More information about the dojo-contributors mailing list