Provide filename to isolation function.

pull/343/head
Chad Weider 2012-01-15 22:56:41 -08:00
parent 8bf0e7c2aa
commit 71dfced06d
1 changed files with 4 additions and 3 deletions

View File

@ -179,7 +179,8 @@ function _handle(req, res, jsFilename, jsFiles) {
if(type == "JS")
{
embeds[filename] = compressJS([isolateJS(data)]);
var shortFilename = filename.replace(/^..\/static\/js\//, '');
embeds[filename] = compressJS([isolateJS(data, shortFilename)]);
}
else
{
@ -297,14 +298,14 @@ 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(isolateJS(files[filename]));
write(isolateJS(files[filename], 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.
// exports is global and require is a function that returns global.
function isolateJS(code) {
function isolateJS(code, filename) {
return '(function (exports, require) {'
+ code + '\n'
+ '}(function () {return this}(), (function (path) {return (function () {return this}())})));\n';