Reputation: 4855
I have this function on an object that I need to trace REALLY BADLY, along with the parent caller of the invocation and arguments passed to the caller.
This well works until minified:
var foo = {
FunctionToBeLogged: function GiveMeAName() {
console.log('> %s called from %s - args: %o',
arguments.callee.name,
arguments.callee.caller.name,
arguments.callee.caller.arguments);
}
}
var bar = {
A: function A(something) {
foo.FunctionToBeLogged('nothing', 12, true);
},
B: function B(whatever, doesntMatter) {
foo.FunctionToBeLogged('nothing', 12, true);
}
}
bar.A(1.2, 'Fred', { }); // > GiveMeAName called from A - args: [1.2, "Fred", Object]
bar.B('Barney', 42, false); // > GiveMeAName called from B - args: ["Barney", 42, false]
Minification gets rid of the these names and my output becomes:
bar.A(1.2, 'Fred', { }); // > called from - args: [1.2, "Fred", Object]
bar.B('Barney', 42, false); // > called from - args: ["Barney", 42, false]
I really don't want to go and create function declarations and assignments because I have TONS of them (I inherited this code with 7,564... and I can easily run some regex sub to name the function expressions.)
What can I do to prevent the minifier to get rid of my these function names?
Upvotes: 2
Views: 4167
Reputation: 13896
To achieve this you can pass specific names to not be mangled, for example in UglifyJS:
To avoid that, you can use --reserved-file to pass a filename that should contain the names to be excluded from mangling
In that file you would have a list of names you do not want to be changed like so:
{
"vars": [ "define", "require", ... ],
"props": [ "length", "prototype", ... ]
}
Upvotes: 2