Skip to content

Instantly share code, notes, and snippets.

@mishoo
Created November 11, 2011 07:45
Show Gist options
  • Save mishoo/1357462 to your computer and use it in GitHub Desktop.
Save mishoo/1357462 to your computer and use it in GitHub Desktop.
Drop debug(...) calls using PatternJS
var U = require("uglify-js");
var fs = require("fs");
var sys = require("sys");
var code = fs.readFileSync("/tmp/test.js", "utf8");
// 1. parse
var ast = U.parser.parse(code);
// 2. UglifyJS compress
ast = U.uglify.ast_mangle(ast);
ast = U.uglify.ast_squeeze(ast);
// drop debug(...) calls using PatternJS
// https://github.com/mishoo/PatternJS
var P = require("pattern");
var pattern = P.compile([ "call", [ "name", "debug" ]]);
P.search(ast, pattern, function(m){
m.$match().replace([]);
});
// regenerate code
code = U.uglify.gen_code(ast);
sys.puts(code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment