<commit_before>var U = require('../../../utils'),
	babylon = require('babylon'),
	types = require('babel-types'),
	generate = require('babel-generator').default,
	traverse = require('babel-traverse').default;

var isBaseControllerExportExpression = types.buildMatchMemberExpression('exports.baseController');

exports.processController = function(code, file) {
	var baseController = '',
		moduleCodes = '',
		newCode = '',
		exportSpecifiers = [];

	try {
		var ast = babylon.parse(code, { sourceFilename: file, sourceType: 'module' });
		traverse(ast, {
			enter: function(path) {
				if (types.isAssignmentExpression(path.node) && isBaseControllerExportExpression(path.node.left)) {
					// what's equivalent of print_to_string()? I replaced with simple value property assuming it's a string literal
					baseController = '\'' + path.node.right.value + '\'';
				}
			},

			ImportDeclaration: function(path) {
				moduleCodes += generate(path.node, {}).code;
				path.remove();
			},

			ExportNamedDeclaration: function(path) {
				var node = path.node;
				var specifiers = node.specifiers;
				if (specifiers && specifiers.length !== 0) {
					specifiers.forEach(function (specifier) {
						if (specifier.local && specifier.local.name) {
							exportSpecifiers.push(specifier.local.name);
						}
					});
				}
				moduleCodes += generate(node, {}).code;
				path.remove();
			}
		});

		if (exportSpecifiers.length > 0) {
			traverse(ast, {
				enter: function(path) {
					var node = path.node,
						name;
					if (node.type === 'VariableDeclaration') {
						name = node.declarations[0].id.name;
					} else if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') {
						name = node.id.name;
					}

					if (exportSpecifiers.indexOf(name) !== -1) {
						moduleCodes += generate(node, {}).code;
						path.remove();
					}
				}
			});
		}

		newCode = generate(ast, {}).code;
	} catch (e) {
		U.dieWithCodeFrame('Error generating AST for "' + file + '". Unexpected token at line ' + e.loc.line + ' column ' + e.loc.column, e.loc, code);
	}

	return {
		es6mods: moduleCodes,
		base: baseController,
		code: newCode
	};
};<commit_msg>[ALOY-1627] Breakpoints not working on Alloy apps<commit_after>var U = require('../../../utils'),
	babylon = require('babylon'),
	types = require('babel-types'),
	generate = require('babel-generator').default,
	traverse = require('babel-traverse').default;

var isBaseControllerExportExpression = types.buildMatchMemberExpression('exports.baseController');

const GENCODE_OPTIONS = {
	retainLines: true
};

exports.processController = function(code, file) {
	var baseController = '',
		moduleCodes = '',
		newCode = '',
		exportSpecifiers = [];

	try {
		var ast = babylon.parse(code, { sourceFilename: file, sourceType: 'module' });
		traverse(ast, {
			enter: function(path) {
				if (types.isAssignmentExpression(path.node) && isBaseControllerExportExpression(path.node.left)) {
					// what's equivalent of print_to_string()? I replaced with simple value property assuming it's a string literal
					baseController = '\'' + path.node.right.value + '\'';
				}
			},

			ImportDeclaration: function(path) {
				moduleCodes += generate(path.node, GENCODE_OPTIONS).code;
				path.remove();
			},

			ExportNamedDeclaration: function(path) {
				var node = path.node;
				var specifiers = node.specifiers;
				if (specifiers && specifiers.length !== 0) {
					specifiers.forEach(function (specifier) {
						if (specifier.local && specifier.local.name) {
							exportSpecifiers.push(specifier.local.name);
						}
					});
				}
				moduleCodes += generate(node, GENCODE_OPTIONS).code;
				path.remove();
			}
		});

		if (exportSpecifiers.length > 0) {
			traverse(ast, {
				enter: function(path) {
					var node = path.node,
						name;
					if (node.type === 'VariableDeclaration') {
						name = node.declarations[0].id.name;
					} else if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration') {
						name = node.id.name;
					}

					if (exportSpecifiers.indexOf(name) !== -1) {
						moduleCodes += generate(node, GENCODE_OPTIONS).code;
						path.remove();
					}
				}
			});
		}

		newCode = generate(ast, GENCODE_OPTIONS).code;
	} catch (e) {
		U.dieWithCodeFrame('Error generating AST for "' + file + '". Unexpected token at line ' + e.loc.line + ' column ' + e.loc.column, e.loc, code);
	}

	return {
		es6mods: moduleCodes,
		base: baseController,
		code: newCode
	};
};
{'fraction_non_alphanumeric': 0.15546124637033729, 'fraction_numerical': 0.003127094036184945, 'mean_word_length': 3.343355965082444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3299082', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1400, 'n_words': 284}