diff options
author | Mihai Bazon <mihai.bazon@gmail.com> | 2015-09-24 17:57:47 +0300 |
---|---|---|
committer | Mihai Bazon <mihai.bazon@gmail.com> | 2015-09-24 17:58:51 +0300 |
commit | 99233c44cc125fa1a96a47b863dbfb3ec0c3fadc (patch) | |
tree | 1cb038e841953084f910fd73411bf2dc89730160 /tools | |
parent | 33528002b496728457cccd9ddf54d2e50bc7e3f2 (diff) | |
download | tracifyjs-99233c44cc125fa1a96a47b863dbfb3ec0c3fadc.tar.gz tracifyjs-99233c44cc125fa1a96a47b863dbfb3ec0c3fadc.zip |
No longer use `vm` to load code.
Improves performance 2x on node > 0.10.
Ref #636
Diffstat (limited to 'tools')
-rw-r--r-- | tools/exports.js | 16 | ||||
-rw-r--r-- | tools/node.js | 40 |
2 files changed, 26 insertions, 30 deletions
diff --git a/tools/exports.js b/tools/exports.js new file mode 100644 index 00000000..a27cef90 --- /dev/null +++ b/tools/exports.js @@ -0,0 +1,16 @@ +exports["Compressor"] = Compressor; +exports["DefaultsError"] = DefaultsError; +exports["Dictionary"] = Dictionary; +exports["JS_Parse_Error"] = JS_Parse_Error; +exports["MAP"] = MAP; +exports["OutputStream"] = OutputStream; +exports["SourceMap"] = SourceMap; +exports["TreeTransformer"] = TreeTransformer; +exports["TreeWalker"] = TreeWalker; +exports["base54"] = base54; +exports["defaults"] = defaults; +exports["mangle_properties"] = mangle_properties; +exports["merge"] = merge; +exports["parse"] = parse; +exports["push_uniq"] = push_uniq; +exports["string_template"] = string_template; diff --git a/tools/node.js b/tools/node.js index eba2bc1d..f6048661 100644 --- a/tools/node.js +++ b/tools/node.js @@ -1,26 +1,5 @@ var path = require("path"); var fs = require("fs"); -var vm = require("vm"); - -var UglifyJS = vm.createContext({ - console : console, - process : process, - Buffer : Buffer, - MOZ_SourceMap : require("source-map") -}); - -function load_global(file) { - file = path.resolve(path.dirname(module.filename), file); - try { - var code = fs.readFileSync(file, "utf8"); - return vm.runInContext(code, UglifyJS, file); - } catch(ex) { - // XXX: in case of a syntax error, the message is kinda - // useless. (no location information). - console.log("ERROR in file: " + file + " / " + ex); - process.exit(1); - } -}; var FILES = exports.FILES = [ "../lib/utils.js", @@ -32,24 +11,25 @@ var FILES = exports.FILES = [ "../lib/compress.js", "../lib/sourcemap.js", "../lib/mozilla-ast.js", - "../lib/propmangle.js" + "../lib/propmangle.js", + "./exports.js", ].map(function(file){ return fs.realpathSync(path.join(path.dirname(__filename), file)); }); -FILES.forEach(load_global); +var UglifyJS = exports; + +new Function("MOZ_SourceMap", "exports", FILES.map(function(file){ + return fs.readFileSync(file, "utf8"); +}).join("\n\n"))( + require("source-map"), + UglifyJS +); UglifyJS.AST_Node.warn_function = function(txt) { console.error("WARN: %s", txt); }; -// XXX: perhaps we shouldn't export everything but heck, I'm lazy. -for (var i in UglifyJS) { - if (UglifyJS.hasOwnProperty(i)) { - exports[i] = UglifyJS[i]; - } -} - exports.minify = function(files, options) { options = UglifyJS.defaults(options, { spidermonkey : false, |