Isolate all files in a closure.

pull/343/head
Chad Weider 2012-01-15 17:23:48 -08:00
parent ab02135643
commit fc68a25b21
1 changed files with 8 additions and 2 deletions

View File

@ -179,7 +179,7 @@ function _handle(req, res, jsFilename, jsFiles) {
if(type == "JS")
{
embeds[filename] = compressJS([data]);
embeds[filename] = compressJS([isolateJS(data)]);
}
else
{
@ -297,10 +297,16 @@ function tarCode(filesInOrder, files, write) {
for(var i = 0, ii = filesInOrder.length; i < filesInOrder.length; i++) {
var filename = filesInOrder[i];
write("\n\n\n/*** File: static/js/" + filename + " ***/\n\n\n");
write(files[filename]);
write(isolateJS(files[filename]));
}
}
// Wrap the following code in a self executing function and assign exports to
// global. This is a first step towards removing symbols from the global scope.
function isolateJS(code) {
return '(function (exports) {'+code+'\n}(function () {return this}()));\n';
}
function compressJS(values)
{
var complete = values.join("\n");