diff --git a/Compiler/AST/Expressions/Identifier.cs b/Compiler/AST/Expressions/Identifier.cs index 07b01fe..528065b 100644 --- a/Compiler/AST/Expressions/Identifier.cs +++ b/Compiler/AST/Expressions/Identifier.cs @@ -75,7 +75,7 @@ internal override bool TryEvaluate(Stack contextStack, CompilationState } else { - state.AddTypeError($"Could not find Member '{_value}' in Type '{contextStack.Peek().Symbol.ToDisplayString()}'!", HandlebarsTypeErrorKind.UnknownMember); + state.AddTypeError($"Could not find Member '{_value}' in Type '{contextStack.Peek().Symbol.ToDisplayString()}'!", HandlebarsTypeErrorKind.UnknownMember, $"{state.Template.Namespace}.{state.Template.Name}|{_value}"); context = null; return false; } diff --git a/Compiler/CodeGeneration/CompilationState.cs b/Compiler/CodeGeneration/CompilationState.cs index 6d9e72e..6c2a9c3 100644 --- a/Compiler/CodeGeneration/CompilationState.cs +++ b/Compiler/CodeGeneration/CompilationState.cs @@ -37,16 +37,16 @@ internal CompilationState(RoslynIntrospector introspector, HandlebarsTemplate te { INamedTypeSymbol modelSymbol = Template.ModelFullyQualifiedName.Evaluate(Introspector); if (modelSymbol == null) - Errors.Add(new HandlebarsTypeError($"Could not find Type in ModelToken '{Template.ModelFullyQualifiedName}'!", HandlebarsTypeErrorKind.UnknownViewModel, 1, 1)); + Errors.Add(new HandlebarsTypeError($"Could not find Type in ModelToken '{Template.ModelFullyQualifiedName}'!", HandlebarsTypeErrorKind.UnknownViewModel, 1, 1, null)); ContextStack.Push(new Context("viewModel", modelSymbol)); } resultStack.Push(new List()); } - internal void AddTypeError(string message, HandlebarsTypeErrorKind kind) + internal void AddTypeError(string message, HandlebarsTypeErrorKind kind, string memberName = null) { - Errors.Add(new HandlebarsTypeError(message, kind, line, column)); + Errors.Add(new HandlebarsTypeError(message, kind, line, column, memberName)); } internal void AddTypeError(HandlebarsTypeError error) diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index efbfe84..bf44452 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -13,7 +13,7 @@ public static class HbsCompiler public static Tuple> Compile(string content, string @namespace, string name, Project containingProject) { var parser = new HbsParser(); - var template = parser.Parse(content); + var template = parser.Parse(content != null ? content.Replace("\r\n", "\n") : content); template.Namespace = @namespace; template.Name = name; if (!(template.ParseErrors?.Any() ?? false)) diff --git a/Compiler/HandlebarsException.cs b/Compiler/HandlebarsException.cs index b7420fc..e18b863 100644 --- a/Compiler/HandlebarsException.cs +++ b/Compiler/HandlebarsException.cs @@ -10,10 +10,14 @@ namespace CompiledHandlebars.Compiler public class HandlebarsTypeError : HandlebarsException { public HandlebarsTypeErrorKind Kind { get; set; } - public HandlebarsTypeError(string message, HandlebarsTypeErrorKind kind, int line, int column) : base(message, line, column) + + public string MemberName { get; set; } + + public HandlebarsTypeError(string message, HandlebarsTypeErrorKind kind, int line, int column, string memberName) : base(message, line, column) { Kind = kind; - } + MemberName = memberName; + } } diff --git a/Compiler/Visitors/CodeGenerationVisitor.cs b/Compiler/Visitors/CodeGenerationVisitor.cs index b9c94f2..fb3ecfe 100644 --- a/Compiler/Visitors/CodeGenerationVisitor.cs +++ b/Compiler/Visitors/CodeGenerationVisitor.cs @@ -73,9 +73,14 @@ public void Visit(YieldStatement astLeaf) } else { - //Unknown Member could also be a HelperCall with implied this as Parameter - if (astLeaf.Expr is MemberExpression) - astLeaf.TransformToHelperCall().Accept(this); + //Unknown Member could also be a HelperCall with implied this as Parameter + if (astLeaf.Expr is MemberExpression) + { + var lastError = state.Errors?.LastOrDefault(e => e is HandlebarsTypeError typeError && typeError.MemberName != null && typeError.MemberName.Equals($"{state.Template.Namespace}.{state.Template.Name}|{astLeaf.Expr}", StringComparison.Ordinal)); + if (lastError != null) + state.Errors.Remove(lastError); + astLeaf.TransformToHelperCall().Accept(this); + } } } diff --git a/CompilerVSIX/source.extension.vsixmanifest b/CompilerVSIX/source.extension.vsixmanifest index 4263254..a7e6ab4 100644 --- a/CompilerVSIX/source.extension.vsixmanifest +++ b/CompilerVSIX/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + HandlebarsCompiler Compiles Handlebars Templates into performant and typechecked C# Code https://github.com/Noxum/CompiledHandlebars