<commit_before>var fs   = require('fs'),
burrito  = require('burrito'),
outcome  = require('outcome'),
uglify = require('uglify-js'),
parser   = uglify.parser;



/**
 * finds an expression based on the filter given
 */

function traverse(ast, filter, filtered) {
	if(!filtered) filtered = [];

	for(var i = ast.length; i--;) {

		var node = ast[i];
		if(!(node instanceof Array)) continue;


		if(filter(node)) {
			filtered.push(node);
		}

		traverse(node, filter, filtered);
	}

	return filtered;
}

/**
 */

function cloneArray(target) {
	return JSON.parse(JSON.stringify(target));
}

/**
 */

function parse(content) {
	return parser.parse(content);
}

/**
 */

function stringify(ast, b) {
	return uglify.uglify.gen_code(ast, { beautify : b });
}

/**
 * wraps the target JS around a shit-ton of try catch blocks. Oh god why >.>...
 */

function wrapWithShitLoadsOfTryCatchBlocks(content, ops) {

	//preprend the error handler if the option is set for it.
	if(ops.addHandler)
	content = "var catchall = catchall || { \
		error: function() {} \
	}" + content;


	var ast = parse(content);

	//first need to find ALL the functions in the given script
	var fns = traverse(ast, function(x) {
		return x[0] == 'defun' || x[0] == 'function';
	}),

	//next we need to parse a try-catch block. this wraps around the function body
	tryCatchAst = traverse(parse('try { } catch(e){ catchall.error(e); }'), function(x) {
		return x[0] == 'try';
	}).pop();


	//finally - need to loop through all the functions and wrap the 
	//bodies in try/catch blocks
	for(var i = fns.length; i--;) {
		var fn = fns[i],
		tryCatchAstClone = cloneArray(tryCatchAst);

		//set the body to the try catch tpl
		tryCatchAstClone[1] = fn[3];

		//set fn body to the try-catch block<commit_msg>cleanup<commit_after>var fs   = require('fs'),
burrito  = require('burrito'),
outcome  = require('outcome'),
uglify = require('uglify-js'),
parser   = uglify.parser;



/**
 * finds an expression based on the filter given
 */

function traverse(ast, filter, filtered) {

	var node;

	if(!filtered) filtered = [];

	for(var i = ast.length; i--;) {

		node = ast[i];

		if(!(node instanceof Array)) continue;


		if(filter(node)) {

			filtered.push(node);

		}

		traverse(node, filter, filtered);

	}

	return filtered;

}

/**
 */

function cloneArray(target) {

	return JSON.parse(JSON.stringify(target));

}

/**
 */

function parse(content) {

	return parser.parse(content);

}

/**
 */

function stringify(ast, b) {

	return uglify.uglify.gen_code(ast, { beautify : b });
	
}

/**
 * wraps the target JS around a shit-ton of try catch blocks. Oh god why >.>...
 */

function wrapWithShitLoadsOfTryCatchBlocks(content, ops) {

	var ast, fn, fns, tryCatchAst, tryCatchAstClone, cnt = content;

	//preprend the error handler if the option is set for it.
	if(ops.addHandler) {
		
		cnt = "var catchall = catchall || { \
			error: function() {} \
		}" + cnt;

	}


	ast = parse(cnt);

	//first need to find ALL the functions in the given script
	fns = traverse(ast, function(x) {

		return x[0] == 'defun' || x[0] == 'function';

	});

	//next we need to parse a try-catch block. this wraps around the function body
	tryCatchAst = traverse(parse('try { } catch(e){ catchall.error(e); }'), function(x) {

		return x[0] == 'try';

	}).pop();


	//finally - need to loop through all the functions and wrap the 
	//bodies in try/catch blocks
	for(var i = fns.length; i--;) {

		fn = fns[i];

		tryCatchAstClone = cloneArray(tryCatchAst);

		//set the body to the try catch tpl
		tryCatchAstClone[1] = fn[3];

		//set fn body to the try-catch block
{'fraction_non_alphanumeric': 0.15563555801716977, 'fraction_numerical': 0.0027693159789531985, 'mean_word_length': 3.3781818181818184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6456945', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1247, 'n_words': 367}