Skip to content

Instantly share code, notes, and snippets.

@mkozhukh
Created November 26, 2014 12:58
Show Gist options
  • Save mkozhukh/a5c8876acd9121a463c2 to your computer and use it in GitHub Desktop.
Save mkozhukh/a5c8876acd9121a463c2 to your computer and use it in GitHub Desktop.
UglifyJS config to remove asserts and debug code from webix_debug.js
var is_debug_name = function(name){
var test = name.toString();
if ((test.indexOf("debug") === 0) || (test.indexOf("log") === 0) || (test.indexOf("assert") === 0))
return true;
};
var is_private_name = function(name){
if (name.toString().charAt(0) == "_") return true;
};
var empty_code = function(orig){
var temp = new UglifyJS.AST_False();
if (orig){
temp.start = orig.start;
temp.end = orig.end;
}
return temp;
};
var remove_debug_code = new UglifyJS.TreeTransformer(function(node, descend){
//some.debug();
if (node instanceof UglifyJS.AST_Call && node.expression instanceof UglifyJS.AST_Dot){
if (is_debug_name(node.expression.property))
return empty_code();
} else
//if (some.debug)
if (node instanceof UglifyJS.AST_If && node.condition instanceof UglifyJS.AST_Dot){
if (is_debug_name(node.condition.property)){
node.condition = empty_code(node.condition);
return node;
}
} else
//some.debug = value;
if (node instanceof UglifyJS.AST_Assign && node.left instanceof UglifyJS.AST_Dot){
if (is_debug_name(node.left.property))
return empty_code();
} else
if (node instanceof UglifyJS.AST_Object){
for (i=node.properties.length-1; i>=0; i--)
if (is_debug_name(node.properties[i].key))
node.properties.splice(i,1);
}
descend(node, this);
return node;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment