aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkzc <kzc@users.noreply.github.com>2018-01-13 12:40:51 -0500
committerAlex Lam S.L <alexlamsl@gmail.com>2018-01-14 01:40:51 +0800
commit2cab34834191ea4fb48059e5725b631ff2752aa4 (patch)
treec8e71b73ee1c506fcd38df781739d6f4115c68c1
parent460218a3f878fff658ca6c8e238f203866320b98 (diff)
downloadtracifyjs-2cab34834191ea4fb48059e5725b631ff2752aa4.tar.gz
tracifyjs-2cab34834191ea4fb48059e5725b631ff2752aa4.zip
improve SymbolDef info in `--output ast` (#2778)
* SymbolDef info (a.k.a. `thedef`) is now represented as a string containing `"ID name [mangled_name]"`. * Enhance display of `globals`, `variables`, `functions` and `enclosed`. * `SymbolDef.next_id` starts at `1` and the `id` is adjusted for `-o ast` display.
-rwxr-xr-xbin/uglifyjs27
-rw-r--r--lib/scope.js2
2 files changed, 11 insertions, 18 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 99248f1b..9a3257e7 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -227,28 +227,15 @@ function run() {
result.ast.figure_out_scope({});
}
print(JSON.stringify(result.ast, function(key, value) {
- switch (key) {
+ if (value) switch (key) {
case "thedef":
- if (typeof value == "object" && typeof value.id == "number") {
- return value.id;
- }
- return;
+ return symdef(value);
case "enclosed":
- return value.map(function(sym){
- return sym.id;
- });
+ return value.length ? value.map(symdef) : undefined;
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;
+ return value.size() ? value.map(symdef) : undefined;
}
if (skip_key(key)) return;
if (value instanceof UglifyJS.AST_Token) return;
@@ -403,6 +390,12 @@ function skip_key(key) {
return skip_keys.indexOf(key) >= 0;
}
+function symdef(def) {
+ var ret = (1e6 + def.id) + " " + def.name;
+ if (def.mangled_name) ret += " " + def.mangled_name;
+ return ret;
+}
+
function format_object(obj) {
var lines = [];
var padding = "";
diff --git a/lib/scope.js b/lib/scope.js
index 55b3ddbb..af852bb1 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 = 1e6;
+SymbolDef.next_id = 1;
SymbolDef.prototype = {
unmangleable: function(options) {