diff options
Diffstat (limited to 'tools/node.js')
-rw-r--r-- | tools/node.js | 35 |
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"); + } +}; |