<commit_before>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4 */
/*global self, importScripts, postMessage, estraverse, esprima */
importScripts("esprima.js");
importScripts("estraverse.js");
/* jslint ignore:start */
console = {};
console.log = function () {
	postMessage({
		type : 'log',
		value : arguments
	});
};
/* jslint ignore:end */

var ast,
	scopeTree = {
		name : 'root',
		varDefs : [],
		childs : [],
	},
	scopeStack = [scopeTree];

self.addEventListener('message', function (e) {
	scopeTree = {
		name : 'root',
		varDefs : [],
		childs : [],
		dataNode : {
			type : 'root',
			childs : [],
			name : 'root'
		}
	};
	scopeStack = [scopeTree];

	ast = esprima.parse(e.data, {
		comment : true,
		loc : true,
		tolerant : true
	});


	estraverse.traverse(ast, {
		enter: enter,
		leave: leave
	});
	console.log(scopeTree);
	var dataTree = createOutlineDataTree(scopeTree);
	dataTree.type = 'data';
	postMessage(dataTree);
});

/**
 *	@params {array} name
 *	@params {scopeTree} scope
 */
function resolveNameForScope(name, scope){
	var i;

	//search 4 name in varDefs
	for (i in scope.varDefs) {
		if (scope.varDefs[i].name[0] === name[0]) {
			//@todo check for the rest of the name


			//if found
			return {
				scope : scope,
				'var' : scope.varDefs[i],
			};
		}
	}
	if ('parent' in scope && scope.parent) {
		return resolveNameForScope(name, scope.parent);
	}
	return false;
}
function createOutlineDataTree(scopeTree) {
	var dataTree = {childs : []},
		dataStack = [dataTree],
		i,
		recursive = function(scope) {
			var owner,
				k;
			//name über den scope auflösen und dann zu scope.dataNode.childs oder var.value.childs hinzufügen
			if (!('callee' in scope) && !('expressionChain' in scope)) {

			} else {
				if ('callee' in scope && scope.callee.length > 0) {
					//anonym function in function attribute
					//use scope.callee[0] as name
					scope.name = scope.callee[scope.callee.length - 1];
					scope.dataNode.type = 'call';
				}
				if ('expressionChain' in scope && scope.expressionChain.length > 0) {
					//check for prototype
					if (scope.expressionChain[scope.expressionChain.length - 1] === 'prototype') {
						var copy = scope.expressionChain.slice();
						copy.pop();
						owner = resolveNameForScope(copy, scope);
						scope.dataNode.type = 'proto';
						if (owner) {
							owner.var.value.type = 'class';
							owner.var.value.childs.push(scope.dataNode);
							scope.skip = true;
						}
					} else {
						//check
						owner = resolveNameForScope(scope.expressionChain, scope);
						if (owner) {
							if (!owner.var.value) {
								var name = scope.expressionChain.join('.');
								owner.var.value = {
									type : 'expression',
									startline : '',
									childs : [scope.dataNode],
									name : name, //@todo better search naming ... its just the first object name
									line : '<span class="type"></span> ' +
										   '<span class="name">' + name + '</span>',
								};
								//owner.scope.dataNode.type = 'expression';
								owner.scope.dataNode.childs.push(owner.var.value);
								scope.dataNode.type ='member';
							} else {
								scope.dataNode.type ='member';
								owner.var.value.childs.push(scope.dataNode);
							}
							scope.skip = true;
						}<commit_msg>add linenumber to parent object <li><commit_after>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4 */
/*global self, importScripts, postMessage, estraverse, esprima */
importScripts("esprima.js");
importScripts("estraverse.js");
/* jslint ignore:start */
console = {};
console.log = function () {
	postMessage({
		type : 'log',
		value : arguments
	});
};
/* jslint ignore:end */

var ast,
	scopeTree = {
		name : 'root',
		varDefs : [],
		childs : [],
	},
	scopeStack = [scopeTree];

self.addEventListener('message', function (e) {
	scopeTree = {
		name : 'root',
		varDefs : [],
		childs : [],
		dataNode : {
			type : 'root',
			childs : [],
			name : 'root'
		}
	};
	scopeStack = [scopeTree];

	ast = esprima.parse(e.data, {
		comment : true,
		loc : true,
		tolerant : true
	});


	estraverse.traverse(ast, {
		enter: enter,
		leave: leave
	});
	var dataTree = createOutlineDataTree(scopeTree);
	dataTree.type = 'data';
	postMessage(dataTree);
});

/**
 *	@params {array} name
 *	@params {scopeTree} scope
 */
function resolveNameForScope(name, scope){
	var i;

	//search 4 name in varDefs
	for (i in scope.varDefs) {
		if (scope.varDefs[i].name[0] === name[0]) {
			//@todo check for the rest of the name


			//if found
			return {
				scope : scope,
				'var' : scope.varDefs[i],
			};
		}
	}
	if ('parent' in scope && scope.parent) {
		return resolveNameForScope(name, scope.parent);
	}
	return false;
}
function createOutlineDataTree(scopeTree) {
	var dataTree = {childs : []},
		dataStack = [dataTree],
		i,
		recursive = function(scope) {
			var owner,
				k;
			//name über den scope auflösen und dann zu scope.dataNode.childs oder var.value.childs hinzufügen
			if (!('callee' in scope) && !('expressionChain' in scope)) {

			} else {
				if ('callee' in scope && scope.callee.length > 0) {
					//anonym function in function attribute
					//use scope.callee[0] as name
					scope.name = scope.callee[scope.callee.length - 1];
					scope.dataNode.type = 'call';
				}
				if ('expressionChain' in scope && scope.expressionChain.length > 0) {
					//check for prototype
					if (scope.expressionChain[scope.expressionChain.length - 1] === 'prototype') {
						var copy = scope.expressionChain.slice();
						copy.pop();
						owner = resolveNameForScope(copy, scope);
						scope.dataNode.type = 'proto';
						if (owner) {
							owner.var.value.type = 'class';
							owner.var.value.childs.push(scope.dataNode);
							scope.skip = true;
						}
					} else {
						//check
						owner = resolveNameForScope(scope.expressionChain, scope);
						if (owner) {
							if (!owner.var.value) {
								var name = scope.expressionChain.join('.');
								owner.var.value = {
									type : 'expression',
									startline : scope.dataNode.startline,
									childs : [scope.dataNode],
									name : name,
									line : '<span class="type"></span> ' +
										   '<span class="name">' + name + '</span>',
								};
								//owner.scope.dataNode.type = 'expression';
								owner.scope.dataNode.childs.push(owner.var.value);
								scope.dataNode.type ='member';
							} else {
								scope.dataNode.type ='member';
								owner.var.value.childs.push(scope.dataNode);
							}
							scope.skip = true;
						}
{'fraction_non_alphanumeric': 0.15691651432053627, 'fraction_numerical': 0.002742230347349177, 'mean_word_length': 2.6985915492957746, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, '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': '2096541', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2206, 'n_words': 503}