diff options
author | kzc <kzc@users.noreply.github.com> | 2018-01-12 02:41:09 -0500 |
---|---|---|
committer | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-12 15:41:09 +0800 |
commit | d4d7d99b70da46303aff3152cec197c371596d0b (patch) | |
tree | 9fd10118b2e9a5a25cf9248663d1ea313919bc2d | |
parent | 6a696d0a7ba88483a31e243d27b006c8c9ae0ec2 (diff) | |
download | tracifyjs-d4d7d99b70da46303aff3152cec197c371596d0b.tar.gz tracifyjs-d4d7d99b70da46303aff3152cec197c371596d0b.zip |
add SymbolDef IDs to --output ast (#2772)
-rwxr-xr-x | bin/uglifyjs | 28 | ||||
-rw-r--r-- | lib/scope.js | 2 |
2 files changed, 28 insertions, 2 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs index 38917137..99248f1b 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -11,7 +11,7 @@ var path = require("path"); var program = require("commander"); var UglifyJS = require("../tools/node"); -var skip_keys = [ "cname", "enclosed", "inlined", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ]; +var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ]; var files = {}; var options = { compress: false, @@ -223,7 +223,33 @@ function run() { } fatal(ex); } else if (program.output == "ast") { + if (!options.compress && !options.mangle) { + result.ast.figure_out_scope({}); + } print(JSON.stringify(result.ast, function(key, value) { + switch (key) { + case "thedef": + if (typeof value == "object" && typeof value.id == "number") { + return value.id; + } + return; + case "enclosed": + return value.map(function(sym){ + return sym.id; + }); + case "variables": + case "functions": + case "globals": + if (value && value.size()) { + var ret = {}; + value.each(function(val, key) { + // key/val inverted for readability. + ret[val.id] = key; + }); + return ret; + } + return; + } if (skip_key(key)) return; if (value instanceof UglifyJS.AST_Token) return; if (value instanceof UglifyJS.Dictionary) return; diff --git a/lib/scope.js b/lib/scope.js index af852bb1..55b3ddbb 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -57,7 +57,7 @@ function SymbolDef(scope, orig, init) { this.id = SymbolDef.next_id++; }; -SymbolDef.next_id = 1; +SymbolDef.next_id = 1e6; SymbolDef.prototype = { unmangleable: function(options) { |