<commit_before>var U = require('../../utils'),
	colors = require('colors'),
	path = require('path'),
	fs = require('fs'),
	wrench = require('wrench'),
	logger = require('../../common/logger'),
	jsp = require("../../uglify-js/uglify-js").parser,
	pro = require("../../uglify-js/uglify-js").uglify,
	_ = require('../../lib/alloy/underscore')._,
	optimizer = require('./optimizer'),
	CONST = require('../../common/constants');

///////////////////////////////////////
////////// private variables //////////
///////////////////////////////////////
var alloyRoot = path.join(__dirname,'..','..'),
	alloyUniqueIdPrefix = '__alloyId',
	alloyUniqueIdCounter = 0,
	JSON_NULL = JSON.parse('null'),
	compilerConfig;

///////////////////////////////
////////// constants //////////
///////////////////////////////
var STYLE_ALLOY_TYPE = '__ALLOY_TYPE__',
	STYLE_EXPR_PREFIX = '__ALLOY_EXPR__--',
	PLATFORMS = ['ios', 'android', 'mobileweb'],
	NS_ALLOY = 'Alloy',
	NS_TI_MAP = 'Ti.Map',
	NS_TI_MEDIA = 'Ti.Media',
	NS_TI_UI_IOS = 'Ti.UI.iOS',
	NS_TI_UI_IPAD = 'Ti.UI.iPad',
	NS_TI_UI_IPHONE = 'Ti.UI.iPhone',
	NS_TI_UI_MOBILEWEB = 'Ti.UI.MobileWeb',
	IMPLICIT_NAMESPACES = {
		// Alloy
		Require: NS_ALLOY,
		Include: NS_ALLOY,

		// Ti.Map
		Annotation: NS_TI_MAP,

		// Ti.Media
		VideoPlayer: NS_TI_MEDIA,
		MusicPlayer: NS_TI_MEDIA,

		// Ti.UI.iOS
		AdView: NS_TI_UI_IOS,
		CoverFlowView: NS_TI_UI_IOS,
		TabbedBar: NS_TI_UI_IOS,
		Toolbar: NS_TI_UI_IOS,

		// Ti.UI.iPad
		DocumentViewer: NS_TI_UI_IPAD,
		Popover: NS_TI_UI_IPAD,
		SplitWindow: NS_TI_UI_IPAD,

		// Ti.UI.iPhone
		NavigationGroup: NS_TI_UI_IPHONE, // I know MobileWeb has one, but 99% will be this one
		StatusBar: NS_TI_UI_IPHONE,
	},
	CONDITION_MAP = {
		android: {
			compile: 'OS_ANDROID',
			runtime: "Ti.Platform.osname === 'android'"
		},
		ios: {
			compile: 'OS_IOS',
			runtime: "Ti.Platform.osname === 'ipad' || Ti.Platform.osname === 'iphone'"
		},
		mobileweb: {
			compile: 'OS_MOBILEWEB',
			runtime: "Ti.Platform.osname === 'mobileweb'"
		}
	},
	RESERVED_ATTRIBUTES = ['id', 'class', 'platform'],
	RESERVED_EVENT_REGEX =  /^on([A-Z].+)/;

//////////////////////////////////////
////////// public interface //////////
//////////////////////////////////////
exports.generateVarName = function(id) {
	return '$.' + id;
}

exports.generateUniqueId = function() {
	return alloyUniqueIdPrefix + alloyUniqueIdCounter++;
}

exports.getParserArgs = function(node, state) {
	state = state || {};
	var name = node.nodeName,
		ns = node.getAttribute('ns') || IMPLICIT_NAMESPACES[name] || CONST.NAMESPACE_DEFAULT,
		req = node.getAttribute('require'),
		id = node.getAttribute('id') || state.defaultId || exports.generateUniqueId(),
		platform = node.getAttribute('platform'),
		platformObj = {};

	// cleanup namespaces and nodes
	ns = ns.replace(/^Titanium\./, 'Ti');
	node.setAttribute('id', id);
	if (state.defaultId) { delete state.defaultId; }

	// process the platform attribute
	if (platform) {
		_.each((platform).split(','), function(p) {
			var matches = U.trim(p).match(/^(\!{0,1})(.+)/);
			if (matches !== null) {
				var negate = matches[1];
				var name = matches[2];
				if (_.contains(PLATFORMS, name)) {
					if (negate === '!') {
						_.each(_.without(PLATFORMS, name), function(n) {
							platformObj[n] = true;
						});
					} else {
						platformObj[name] = true;
					}
					return;
				}
			}
			U.die('Invalid platform type found: ' + p);
		});
	}

	// get create arguments and events from attributes
	var createArgs = {}, events = [];
	_.each(node.attributes, function(attr) {
		var attrName = attr.nodeName;
		if (_.contains(RESERVED_ATTRIBUTES, attrName)) { return; }
		var matches = attrName.match(RESERVED_EVENT_REGEX);
		if (matches !== null) {
			events.push({name:U.lcfirst(matches[1]),value:node.getAttribute(attrName)});
		} else {
			createArgs[attrName] = node.getAttribute(attrName);
		}
	});
	
	return {
		ns: ns,
		name: name,
		id: id, <commit_msg>added reserved attributes for requires and includes<commit_after>var U = require('../../utils'),
	colors = require('colors'),
	path = require('path'),
	fs = require('fs'),
	wrench = require('wrench'),
	logger = require('../../common/logger'),
	jsp = require("../../uglify-js/uglify-js").parser,
	pro = require("../../uglify-js/uglify-js").uglify,
	_ = require('../../lib/alloy/underscore')._,
	optimizer = require('./optimizer'),
	CONST = require('../../common/constants');

///////////////////////////////////////
////////// private variables //////////
///////////////////////////////////////
var alloyRoot = path.join(__dirname,'..','..'),
	alloyUniqueIdPrefix = '__alloyId',
	alloyUniqueIdCounter = 0,
	JSON_NULL = JSON.parse('null'),
	compilerConfig;

///////////////////////////////
////////// constants //////////
///////////////////////////////
var STYLE_ALLOY_TYPE = '__ALLOY_TYPE__',
	STYLE_EXPR_PREFIX = '__ALLOY_EXPR__--',
	PLATFORMS = ['ios', 'android', 'mobileweb'],
	NS_ALLOY = 'Alloy',
	NS_TI_MAP = 'Ti.Map',
	NS_TI_MEDIA = 'Ti.Media',
	NS_TI_UI_IOS = 'Ti.UI.iOS',
	NS_TI_UI_IPAD = 'Ti.UI.iPad',
	NS_TI_UI_IPHONE = 'Ti.UI.iPhone',
	NS_TI_UI_MOBILEWEB = 'Ti.UI.MobileWeb',
	IMPLICIT_NAMESPACES = {
		// Alloy
		Require: NS_ALLOY,
		Include: NS_ALLOY,

		// Ti.Map
		Annotation: NS_TI_MAP,

		// Ti.Media
		VideoPlayer: NS_TI_MEDIA,
		MusicPlayer: NS_TI_MEDIA,

		// Ti.UI.iOS
		AdView: NS_TI_UI_IOS,
		CoverFlowView: NS_TI_UI_IOS,
		TabbedBar: NS_TI_UI_IOS,
		Toolbar: NS_TI_UI_IOS,

		// Ti.UI.iPad
		DocumentViewer: NS_TI_UI_IPAD,
		Popover: NS_TI_UI_IPAD,
		SplitWindow: NS_TI_UI_IPAD,

		// Ti.UI.iPhone
		NavigationGroup: NS_TI_UI_IPHONE, // I know MobileWeb has one, but 99% will be this one
		StatusBar: NS_TI_UI_IPHONE,
	},
	CONDITION_MAP = {
		android: {
			compile: 'OS_ANDROID',
			runtime: "Ti.Platform.osname === 'android'"
		},
		ios: {
			compile: 'OS_IOS',
			runtime: "Ti.Platform.osname === 'ipad' || Ti.Platform.osname === 'iphone'"
		},
		mobileweb: {
			compile: 'OS_MOBILEWEB',
			runtime: "Ti.Platform.osname === 'mobileweb'"
		}
	},
	RESERVED_ATTRIBUTES = ['id', 'class', 'platform'],
	RESERVED_ATTRIBUTES_REQ_INC = ['id', 'class', 'platform', 'type', 'src'],
	RESERVED_EVENT_REGEX =  /^on([A-Z].+)/;

//////////////////////////////////////
////////// public interface //////////
//////////////////////////////////////
exports.generateVarName = function(id) {
	return '$.' + id;
}

exports.generateUniqueId = function() {
	return alloyUniqueIdPrefix + alloyUniqueIdCounter++;
}

exports.getParserArgs = function(node, state) {
	state = state || {};
	var name = node.nodeName,
		ns = node.getAttribute('ns') || IMPLICIT_NAMESPACES[name] || CONST.NAMESPACE_DEFAULT,
		req = node.getAttribute('require'),
		id = node.getAttribute('id') || state.defaultId || exports.generateUniqueId(),
		platform = node.getAttribute('platform'),
		platformObj = {};

	// cleanup namespaces and nodes
	ns = ns.replace(/^Titanium\./, 'Ti');
	node.setAttribute('id', id);
	if (state.defaultId) { delete state.defaultId; }

	// process the platform attribute
	if (platform) {
		_.each((platform).split(','), function(p) {
			var matches = U.trim(p).match(/^(\!{0,1})(.+)/);
			if (matches !== null) {
				var negate = matches[1];
				var name = matches[2];
				if (_.contains(PLATFORMS, name)) {
					if (negate === '!') {
						_.each(_.without(PLATFORMS, name), function(n) {
							platformObj[n] = true;
						});
					} else {
						platformObj[name] = true;
					}
					return;
				}
			}
			U.die('Invalid platform type found: ' + p);
		});
	}

	// get create arguments and events from attributes
	var createArgs = {}, events = [];
	var attrs = _.contains([], fullname) ? RESERVED_ATTRIBUTES_REQ_INC : RESERVED_ATTRIBUTES;
	_.each(node.attributes, function(attr) {
		var attrName = attr.nodeName;
		if (_.contains(attrs, attrName)) { return; }
		var matches = attrName.match(RESERVED_EVENT_REGEX);
		if (matches !== null) {
			events.push({name:U.lcfirst(matches[1]),value:node.getAttribute(attrName)});
		} else {
			createArgs[attrName] = node.getAttribute(attrName);
		}
	});
	
	return {
		ns: ns,
		name: name,
		id: id, 
{'fraction_non_alphanumeric': 0.23316062176165803, 'fraction_numerical': 0.0019738465334320256, 'mean_word_length': 2.7954119850187267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4877675', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2884, 'n_words': 520}