From fc68a25b21a2ceb4f7737dd05e1e7433076e929d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 17:23:48 -0800 Subject: [PATCH] Isolate all files in a closure. --- node/utils/Minify.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 03f511f41..4a22a81fa 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -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");