uglify: Ensure prettified code inherits the current environment, instead of the default global environment default

Wed, 10 Feb 2016 12:33:42 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 10 Feb 2016 12:33:42 +0000
changeset 92
55e927a6c228
parent 91
4608c7c025e5
child 93
07c10f9ba77c

uglify: Ensure prettified code inherits the current environment, instead of the default global environment

uglify/squish.uglify.lua file | annotate | diff | comparison | revisions
--- a/uglify/squish.uglify.lua	Thu Dec 31 20:29:08 2015 +0000
+++ b/uglify/squish.uglify.lua	Wed Feb 10 12:33:42 2016 +0000
@@ -96,7 +96,7 @@
 	outfile:write[[}; function prettify(code) return code:gsub("["..string.char(base_char).."-"..string.char(base_char+#keywords).."]", 
 	function (c) return keywords[c:byte()-base_char]; end) end ]]
 	
-	outfile:write [[return assert(loadstring(prettify]]
+	outfile:write [[return setfenv(assert(loadstring(prettify]]
 	outfile:write("[", string.rep("=", maxequals+1), "[");
 	
 	-- Write code, substituting tokens as we go
@@ -115,7 +115,7 @@
 
 	-- Close string/functions	
 	outfile:write("]", string.rep("=", maxequals+1), "]");
-	outfile:write(", '@", outfile_fn,"'))()");
+	outfile:write(", '@", outfile_fn,"')), getfenv())()");
 	outfile:close();
 	os.rename(outfile_fn..".uglified", outfile_fn);
 end

mercurial