aboutsummaryrefslogtreecommitdiff
path: root/tools
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 /tools
parentaa45f6586ebf60643682c41aaf2b66c623bece43 (diff)
downloadtracifyjs-80cfd063e20e6779fc03da20cd53e6d05df8a181.tar.gz
tracifyjs-80cfd063e20e6779fc03da20cd53e6d05df8a181.zip
Export readNameCache / writeNameCache
Diffstat (limited to 'tools')
-rw-r--r--tools/node.js35
1 files changed, 35 insertions, 0 deletions
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");
+ }
+};