add SymbolDef IDs to --output ast (#2772)
This commit is contained in:
28
bin/uglifyjs
28
bin/uglifyjs
@@ -11,7 +11,7 @@ var path = require("path");
|
|||||||
var program = require("commander");
|
var program = require("commander");
|
||||||
var UglifyJS = require("../tools/node");
|
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 files = {};
|
||||||
var options = {
|
var options = {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -223,7 +223,33 @@ function run() {
|
|||||||
}
|
}
|
||||||
fatal(ex);
|
fatal(ex);
|
||||||
} else if (program.output == "ast") {
|
} else if (program.output == "ast") {
|
||||||
|
if (!options.compress && !options.mangle) {
|
||||||
|
result.ast.figure_out_scope({});
|
||||||
|
}
|
||||||
print(JSON.stringify(result.ast, function(key, value) {
|
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 (skip_key(key)) return;
|
||||||
if (value instanceof UglifyJS.AST_Token) return;
|
if (value instanceof UglifyJS.AST_Token) return;
|
||||||
if (value instanceof UglifyJS.Dictionary) return;
|
if (value instanceof UglifyJS.Dictionary) return;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function SymbolDef(scope, orig, init) {
|
|||||||
this.id = SymbolDef.next_id++;
|
this.id = SymbolDef.next_id++;
|
||||||
};
|
};
|
||||||
|
|
||||||
SymbolDef.next_id = 1;
|
SymbolDef.next_id = 1e6;
|
||||||
|
|
||||||
SymbolDef.prototype = {
|
SymbolDef.prototype = {
|
||||||
unmangleable: function(options) {
|
unmangleable: function(options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user