[Pkg-javascript-commits] [uglifyjs] 63/77: Support multiple --reserved-file args
Jonas Smedegaard
dr at jones.dk
Tue May 19 00:02:33 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v2.4.18
in repository uglifyjs.
commit 3ef092332b1e7c9bf1d17038601a33bd742dd753
Author: Mihai Bazon <mihai.bazon at gmail.com>
Date: Wed Mar 18 11:53:17 2015 +0200
Support multiple --reserved-file args
---
bin/uglifyjs | 25 ++++++++++++-------------
tools/node.js | 19 +++++++++++++++++++
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/bin/uglifyjs b/bin/uglifyjs
index e1deaf5..281ac17 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -94,8 +94,8 @@ You need to pass an argument to this option to specify the name that your module
.string("comments")
.string("wrap")
.string("p")
- .string("reserved-file")
.string("name-cache")
+ .array("reserved-file")
.boolean("expr")
.boolean("source-map-include-sources")
@@ -150,6 +150,11 @@ if (ARGS.acorn) {
var COMPRESS = getOptions("c", true);
var MANGLE = getOptions("m", true);
var BEAUTIFY = getOptions("b", true);
+var RESERVED = null;
+
+if (ARGS.reserved_file) ARGS.reserved_file.forEach(function(filename){
+ RESERVED = UglifyJS.readReservedFile(filename, RESERVED);
+});
if (ARGS.d) {
if (COMPRESS) COMPRESS.global_defs = getOptions("d");
@@ -159,16 +164,10 @@ if (ARGS.r) {
if (MANGLE) MANGLE.except = ARGS.r.replace(/^\s+|\s+$/g).split(/\s*,+\s*/);
}
-var RESERVED = null;
-if (ARGS.reserved_file) (function(){
- var data = fs.readFileSync(ARGS.reserved_file, "utf8");
- RESERVED = data = JSON.parse(data);
- if (data.vars) {
- MANGLE.except = MANGLE.except
- ? MANGLE.except.concat(data.vars)
- : data.vars;
- }
-})();
+if (RESERVED && MANGLE) {
+ if (!MANGLE.except) MANGLE.except = RESERVED.vars;
+ else MANGLE.except = MANGLE.except.concat(RESERVED.vars);
+}
function readNameCache(key) {
return UglifyJS.readNameCache(ARGS.name_cache, key);
@@ -457,9 +456,9 @@ function normalize(o) {
function getOptions(x, constants) {
x = ARGS[x];
- if (!x) return null;
+ if (x == null) return null;
var ret = {};
- if (x !== true) {
+ if (x !== "") {
var ast;
try {
ast = UglifyJS.parse(x, { expression: true });
diff --git a/tools/node.js b/tools/node.js
index a8e734d..048630d 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -194,6 +194,25 @@ exports.describe_ast = function() {
return out + "";
};
+exports.readReservedFile = function(filename, reserved) {
+ if (!reserved) {
+ reserved = { vars: [], props: [] };
+ }
+ var data = fs.readFileSync(filename, "utf8");
+ data = JSON.parse(data);
+ if (data.vars) {
+ data.vars.forEach(function(name){
+ UglifyJS.push_uniq(reserved.vars, name);
+ });
+ }
+ if (data.props) {
+ data.props.forEach(function(name){
+ UglifyJS.push_uniq(reserved.props, name);
+ });
+ }
+ return reserved;
+};
+
exports.readNameCache = function(filename, key) {
var cache = null;
if (filename) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list