update rename functionality
This commit is contained in:
parent
db76bb3c1f
commit
072e0c16e1
|
|
@ -119,6 +119,11 @@ function processFile(file) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (ARGS.print_ast){
|
||||
console.log(output);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ARGS.nice_formatting) {
|
||||
output = removeWhitespace(output);
|
||||
}
|
||||
|
|
@ -155,10 +160,16 @@ function processFile(file) {
|
|||
inferred_names[result[i].v] = result[i].inf.green;
|
||||
}
|
||||
}
|
||||
console.log(UglifyJS.replaceMangled(code, file, inferred_names));
|
||||
try {
|
||||
var renamed_js = UglifyJS.replaceMangled(code, file, inferred_names);
|
||||
console.log(renamed_js);
|
||||
} catch (ex){
|
||||
sys.error("ERROR: ".red + "failed rename '" + file + "': " + ex);
|
||||
}
|
||||
|
||||
},
|
||||
function(err) {
|
||||
console.log("ERROR: ".red + "connecting to server '" + HOST + ":" + PORT + "' " + err);
|
||||
sys.error("ERROR: ".red + "connecting to server '" + HOST + ":" + PORT + "' " + err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,14 +57,25 @@ function replaceMangled(code, file, infered_names) {
|
|||
//replace variables with inferred names
|
||||
stream = OutputStream({
|
||||
beautify: true, replace_mangled: function (node) {
|
||||
return node.definition() ? infered_names[feature_outputter.string_map.getId("$" + node.definition().id + "-" + node.name)] : node.name;
|
||||
var label = nodeToString(node);
|
||||
if (node.definition() && feature_outputter.string_map.hasId(label) && feature_outputter.string_map.getId(label) in infered_names){
|
||||
return infered_names[feature_outputter.string_map.getId(label)];
|
||||
} else {
|
||||
return node.name;
|
||||
}
|
||||
//return node.definition() ? infered_names[feature_outputter.string_map.getId("$" + node.definition().id + "-" + node.name)] : node.name;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//replace variables with placeholders. Using in the online demo for interactive renaming.
|
||||
stream = OutputStream({
|
||||
beautify: true, replace_mangled: function (node) {
|
||||
return node.definition() ? "local$$" + feature_outputter.string_map.getId("$" + node.definition().id + "-" + node.name) : node.name;
|
||||
if (node.definition() && feature_outputter.string_map.hasId(nodeToString(node))){
|
||||
return "local$$" + feature_outputter.string_map.getId(nodeToString(node));
|
||||
} else {
|
||||
return node.name;
|
||||
}
|
||||
//return node.definition() ? "local$$" + feature_outputter.string_map.getId("$" + node.definition().id + "-" + node.name) : node.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -213,13 +224,13 @@ function printAst(toplevel){
|
|||
var output = "";
|
||||
|
||||
var walker = new TreeWalker(function(node){
|
||||
output += string_template(" node{id} [label=\"{label}\"];\n", {
|
||||
output += string_template(' node{id} [label="{label}"];\n', {
|
||||
id: node.id,
|
||||
label: nodeType(node)
|
||||
});
|
||||
|
||||
if (walker.parent() != null) {
|
||||
output += string_template(" node{id1} -> node{id2} [weight=1];\n", {
|
||||
output += string_template(' node{id1} -> node{id2} [weight=1];\n', {
|
||||
id1: walker.parent().id,
|
||||
id2: node.id
|
||||
});
|
||||
|
|
@ -383,7 +394,7 @@ NodePathFinder.prototype.find = function(node) {
|
|||
/* ---[ JsonOutputter ]--- */
|
||||
|
||||
function FeatureJsonOutputter() {
|
||||
this.string_map = new StringMap(false);
|
||||
this.string_map = new StringMap();
|
||||
this.first_element = true;
|
||||
this.output = "";
|
||||
this.depth = 0;
|
||||
|
|
@ -540,18 +551,26 @@ FeatureJsonOutputter.prototype.endScope = function(){
|
|||
|
||||
/* -----[ StringMap ]----- */
|
||||
|
||||
function StringMap(nice_names) {
|
||||
function StringMap() {
|
||||
this.map = {};
|
||||
this.current_id = 0;
|
||||
this.nice_names = nice_names;
|
||||
this.keys = [];
|
||||
}
|
||||
|
||||
StringMap.prototype.hasId = function(input){
|
||||
if (input == null){
|
||||
throw new Error("error null");
|
||||
}
|
||||
|
||||
//we add a special character in from to allow for keys such as "toString"
|
||||
var escaped_input = "#" + input;
|
||||
return escaped_input in this.map;
|
||||
};
|
||||
|
||||
StringMap.prototype.getId = function(input){
|
||||
if (input == null){
|
||||
throw new Error("error null");
|
||||
}
|
||||
if (this.nice_names) return input;
|
||||
|
||||
//we add a special character in from to allow for keys such as "toString"
|
||||
var escaped_input = "#" + input;
|
||||
|
|
|
|||
|
|
@ -1101,7 +1101,7 @@ function OutputStream(options) {
|
|||
var def = self.definition();
|
||||
// output.print_name(def ? def.mangled_name || def.name : self.name);
|
||||
|
||||
if (output.replace_mangled == null || self instanceof AST_This || self.unmangleable())
|
||||
if (output.replace_mangled == null || !def || self instanceof AST_This || self.unmangleable())
|
||||
//retain original name for variables that cannot be mangled
|
||||
output.print_name(def ? def.mangled_name || def.name : self.name);
|
||||
else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user