var CU = require('../compilerUtils'),
	_ = require('../../../lib/alloy/underscore')._;

exports.parse = function(node, state) {
	return require('./base').parse(node, state, parse);
};

function parse(node, state, args) {
	var createFunc = 'create' + node.nodeName,
		code = '';

	// Generate runtime code
	code += args.symbol + " = A$(" + args.ns + "." + createFunc + "(\n";
	code += CU.generateStyleParams(
		state.styles, 
		args.classes, 
		args.id, 
		node.nodeName, 
		_.defaults(state.extraStyle || {}, args.createArgs || {}) 
	) + '\n';
	code += "),'" + node.nodeName + "', " + (args.parent.symbol || 'null') + ");\n";
	if (args.parent.symbol) {
		code += args.parent.symbol + ".add(" + args.symbol + ");\n";
	} 

	// Update the parsing state
	return {
		parent: {
			node: node,
			symbol: args.symbol
		},
		styles: state.styles,
		code: code
	}
};
@@ -280,38 +280,178 @@
 %09// 
-Generate runtime code%0A%09code +=
+make symbol a local variable if necessary%0A%09if (state.local) %7B%0A%09%09args.symbol = CU.generateUniqueId(); %0A%09%7D%0A%0A%09// Generate runtime code%0A%09code += (state.local ? 'var ' : '') +
  arg
@@ -948,16 +948,47 @@
 ol%0A%09%09%7D,%0A
+%09%09local: state.local %7C%7C false,%0A
 %09%09styles

allow local variables to be used when generating UI components