option to exclude certain names from mangling
This commit is contained in:
@@ -19,6 +19,7 @@ For example -p 3 will drop 3 directories from file names and ensure they are rel
|
|||||||
.describe("o", "Output file (default STDOUT).")
|
.describe("o", "Output file (default STDOUT).")
|
||||||
.describe("b", "Beautify output/specify output options.")
|
.describe("b", "Beautify output/specify output options.")
|
||||||
.describe("m", "Mangle names/pass mangler options.")
|
.describe("m", "Mangle names/pass mangler options.")
|
||||||
|
.describe("r", "Reserved names to exclude from mangling.")
|
||||||
.describe("c", "Enable compressor/pass compressor options. \
|
.describe("c", "Enable compressor/pass compressor options. \
|
||||||
Pass options like -c hoist_vars=false,if_return=false. \
|
Pass options like -c hoist_vars=false,if_return=false. \
|
||||||
Use -c with no argument if you want to disable the squeezer entirely.")
|
Use -c with no argument if you want to disable the squeezer entirely.")
|
||||||
@@ -34,6 +35,7 @@ Use -c with no argument if you want to disable the squeezer entirely.")
|
|||||||
.alias("m", "mangle")
|
.alias("m", "mangle")
|
||||||
.alias("c", "compress")
|
.alias("c", "compress")
|
||||||
.alias("d", "define")
|
.alias("d", "define")
|
||||||
|
.alias("r", "reserved-names")
|
||||||
|
|
||||||
.string("b")
|
.string("b")
|
||||||
.string("m")
|
.string("m")
|
||||||
@@ -83,6 +85,10 @@ if (COMPRESS && ARGS.d) {
|
|||||||
COMPRESS.global_defs = getOptions("d");
|
COMPRESS.global_defs = getOptions("d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MANGLE && ARGS.r) {
|
||||||
|
MANGLE.except = ARGS.r.replace(/^\s+|\s+$/g).split(/\s*,+\s*/);
|
||||||
|
}
|
||||||
|
|
||||||
var OUTPUT_OPTIONS = {
|
var OUTPUT_OPTIONS = {
|
||||||
beautify: BEAUTIFY ? true : false
|
beautify: BEAUTIFY ? true : false
|
||||||
};
|
};
|
||||||
|
|||||||
10
lib/scope.js
10
lib/scope.js
@@ -354,7 +354,8 @@ AST_LoopControl.DEFMETHOD("target", function(){
|
|||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
sort: false
|
sort : false,
|
||||||
|
except : []
|
||||||
});
|
});
|
||||||
// We only need to mangle declaration nodes. Special logic wired
|
// We only need to mangle declaration nodes. Special logic wired
|
||||||
// into the code generator will display the mangled name if it's
|
// into the code generator will display the mangled name if it's
|
||||||
@@ -376,16 +377,19 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
var a = node.variables;
|
var a = node.variables;
|
||||||
for (var i in a) if (HOP(a, i)) {
|
for (var i in a) if (HOP(a, i)) {
|
||||||
var symbol = a[i];
|
var symbol = a[i];
|
||||||
if (!(is_setget && symbol instanceof AST_SymbolLambda))
|
if (!(is_setget && symbol instanceof AST_SymbolLambda)) {
|
||||||
|
if (options.except.indexOf(symbol.name) < 0) {
|
||||||
to_mangle.push(symbol);
|
to_mangle.push(symbol);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
var name;
|
var name;
|
||||||
do name = base54(++lname); while (!is_identifier(name));
|
do name = base54(++lname); while (!is_identifier(name));
|
||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
|
|||||||
Reference in New Issue
Block a user