<commit_before>using System;
using System.Reflection;
using Boo.Lang.Compiler.Ast;
using Boo.Lang.Compiler.Steps;
using Boo.Lang.Compiler.TypeSystem;

namespace Rhino.Commons.Binsor
{
	internal class TransformComponentReferences : ProcessMethodBodiesWithDuckTyping
	{
		private readonly ConstructorInfo _componentReferenceConstructor =
			typeof (ComponentReference).GetConstructor(new Type[] {typeof (string)});

		public override void OnReferenceExpression(ReferenceExpression node)
		{
			IEntity entity = NameResolutionService.Resolve(node.Name);
			if (entity != null)
			{
				base.OnReferenceExpression(node);
				return;
			}
			if(node.Name.StartsWith("@"))
			{
				string refComponentName = node.Name.Substring(1);
				StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(refComponentName);
				ExternalConstructor constructor = new ExternalConstructor(TypeSystemServices, _componentReferenceConstructor);
				MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, literal);
				node.ParentNode.Replace(node, invocation);
				return;
			}
			else if(node.ParentNode is MethodInvocationExpression)
			{
				MethodInvocationExpression mie = (MethodInvocationExpression) node.ParentNode;
				//Transform the first parameter of Component ctor to string.
				if(mie.Target.ToString() == "Component")
				{
					StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name);
					mie.Replace(node, literal);
					return;
				}
			}
			base.OnReferenceExpression(node);<commit_msg>Changing Binsor to only turn unknown references to strings when it is the FIRST element on Component().<commit_after>using System;
using System.Reflection;
using Boo.Lang.Compiler.Ast;
using Boo.Lang.Compiler.Steps;
using Boo.Lang.Compiler.TypeSystem;

namespace Rhino.Commons.Binsor
{
	internal class TransformComponentReferences : ProcessMethodBodiesWithDuckTyping
	{
		private readonly ConstructorInfo _componentReferenceConstructor =
			typeof (ComponentReference).GetConstructor(new Type[] {typeof (string)});

		public override void OnReferenceExpression(ReferenceExpression node)
		{
			IEntity entity = NameResolutionService.Resolve(node.Name);
			if (entity != null)
			{
				base.OnReferenceExpression(node);
				return;
			}
			if(node.Name.StartsWith("@"))
			{
				string refComponentName = node.Name.Substring(1);
				StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(refComponentName);
				ExternalConstructor constructor = new ExternalConstructor(TypeSystemServices, _componentReferenceConstructor);
				MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, literal);
				node.ParentNode.Replace(node, invocation);
				return;
			}
			else if(node.ParentNode is MethodInvocationExpression)
			{
				MethodInvocationExpression mie = (MethodInvocationExpression) node.ParentNode;
				//Transform the first parameter of Component ctor to string.
				if(mie.Target.ToString() == "Component" && mie.Arguments[0] == node)
				{
					StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name);
					mie.Replace(node, literal);
					return;
				}
			}
			base.OnReferenceExpression(node);
{'fraction_non_alphanumeric': 0.08819875776397515, 'fraction_numerical': 0.0009316770186335404, 'mean_word_length': 5.111954459203036, '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': '4264375', 'n_tokens_mistral': 1015, 'n_tokens_neox': 843, 'n_words': 183}