aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2015-03-17 10:05:49 +0200
committerMihai Bazon <mihai.bazon@gmail.com>2015-03-17 10:05:49 +0200
commit80cfd063e20e6779fc03da20cd53e6d05df8a181 (patch)
tree701d89758f11c434295c658598cd763ab7e33217
parentaa45f6586ebf60643682c41aaf2b66c623bece43 (diff)
downloadtracifyjs-80cfd063e20e6779fc03da20cd53e6d05df8a181.tar.gz
tracifyjs-80cfd063e20e6779fc03da20cd53e6d05df8a181.zip
Export readNameCache / writeNameCache
-rwxr-xr-xbin/uglifyjs31
-rw-r--r--tools/node.js35
2 files changed, 37 insertions, 29 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index f2f8f0d9..e1deaf5e 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -171,38 +171,11 @@ if (ARGS.reserved_file) (function(){
})();
function readNameCache(key) {
- var cache = null;
- if (ARGS.name_cache) {
- try {
- var cache = fs.readFileSync(ARGS.name_cache, "utf8");
- cache = JSON.parse(cache)[key];
- if (!cache) throw "init";
- cache.props = UglifyJS.Dictionary.fromObject(cache.props);
- } catch(ex) {
- cache = {
- cname: -1,
- props: new UglifyJS.Dictionary()
- };
- }
- }
- return cache;
+ return UglifyJS.readNameCache(ARGS.name_cache, key);
}
function writeNameCache(key, cache) {
- if (ARGS.name_cache) {
- var data;
- try {
- data = fs.readFileSync(ARGS.name_cache, "utf8");
- data = JSON.parse(data);
- } catch(ex) {
- data = {};
- }
- data[key] = {
- cname: cache.cname,
- props: cache.props.toObject()
- };
- fs.writeFileSync(ARGS.name_cache, JSON.stringify(data, null, 2), "utf8");
- }
+ return UglifyJS.writeNameCache(ARGS.name_cache, key, cache);
}
if (ARGS.quotes === true) {
diff --git a/tools/node.js b/tools/node.js
index af540e0c..a8e734d9 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -193,3 +193,38 @@ exports.describe_ast = function() {
doitem(UglifyJS.AST_Node);
return out + "";
};
+
+exports.readNameCache = function(filename, key) {
+ var cache = null;
+ if (filename) {
+ try {
+ var cache = fs.readFileSync(filename, "utf8");
+ cache = JSON.parse(cache)[key];
+ if (!cache) throw "init";
+ cache.props = UglifyJS.Dictionary.fromObject(cache.props);
+ } catch(ex) {
+ cache = {
+ cname: -1,
+ props: new UglifyJS.Dictionary()
+ };
+ }
+ }
+ return cache;
+};
+
+exports.writeNameCache = function(filename, key, cache) {
+ if (filename) {
+ var data;
+ try {
+ data = fs.readFileSync(filename, "utf8");
+ data = JSON.parse(data);
+ } catch(ex) {
+ data = {};
+ }
+ data[key] = {
+ cname: cache.cname,
+ props: cache.props.toObject()
+ };
+ fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
+ }
+};