-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove calls to console.* #293
base: master
Are you sure you want to change the base?
Conversation
Do you know when it will be committed in the master ? |
Looks good so far.. How about to make it external to uglify? So I can remove anything or can modify it.. Maybe add hooks to default uglifier? Right now I can replace default squeezer by hijacking require(..) e.g uglify-console.js:
|
@iliakan I'm not convinced by that method of monkey-patching the ast_squeeze function. If you're going to be using it from within some node script you have control over, you might as well include the
For command-line usage via |
I believe you can simply use sed -E 's/(console\.)/\/\/\1/g' script.js | uglifyjs |
This change removes calls to console.* statements as requested in #124 (I couldn't get this code to attach to that issue...)
It does so by replacing statements that call
console
methods with an empty block to be removed later by the squeeze function.The caveat is that it only fully removes console function calls if they are executed as statements. If the calls are made elsewhere in the tree then they will just be replaced with 0. For example, the following boolean expression:
will be compressed to:
Also, the function arguments will be removed so users should be aware that if an argument is a function call, it won't be executed. For example, the
foo
function call will be totally removed in the following example:This can be executed from the commandline by adding the
--no-console
flag