diff options
-rwxr-xr-x | bin/uglifyjs | 1 | ||||
-rw-r--r-- | lib/ast.js | 1 | ||||
-rw-r--r-- | tools/exports.js | 16 | ||||
-rw-r--r-- | tools/node.js | 40 |
4 files changed, 27 insertions, 31 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs index 4768f766..fbb053d8 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -254,7 +254,6 @@ if (ARGS.self) { } files = UglifyJS.FILES; if (!ARGS.wrap) ARGS.wrap = "UglifyJS"; - ARGS.export_all = true; } var ORIG_MAP = ARGS.in_source_map; @@ -81,6 +81,7 @@ function DEFNODE(type, props, methods, base) { ctor.DEFMETHOD = function(name, method) { this.prototype[name] = method; }; + exports["AST_" + type] = ctor; return ctor; }; 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, |