Skip to content

Commit

Permalink
compilation input converts \r\n to \n
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHaedicke committed Jun 9, 2021
1 parent fdb84e5 commit 82058dd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Compiler/AST/Expressions/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal override bool TryEvaluate(Stack<Context> 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;
}
Expand Down
6 changes: 3 additions & 3 deletions Compiler/CodeGeneration/CompilationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatementSyntax>());
}


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)
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class HbsCompiler
public static Tuple<string, IEnumerable<HandlebarsException>> 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))
Expand Down
8 changes: 6 additions & 2 deletions Compiler/HandlebarsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}
Expand Down
11 changes: 8 additions & 3 deletions Compiler/Visitors/CodeGenerationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion CompilerVSIX/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="HandlebarsCompiler.Jakob Demler.71222594-41cc-4ba2-b691-ad7c2783a83b" Version="0.4.2" Language="en-US" Publisher="Jakob Demler" />
<Identity Id="HandlebarsCompiler.Jakob Demler.71222594-41cc-4ba2-b691-ad7c2783a83b" Version="0.4.3" Language="en-US" Publisher="Jakob Demler" />
<DisplayName>HandlebarsCompiler</DisplayName>
<Description xml:space="preserve">Compiles Handlebars Templates into performant and typechecked C# Code</Description>
<MoreInfo>https://github.com/Noxum/CompiledHandlebars</MoreInfo>
Expand Down

0 comments on commit 82058dd

Please sign in to comment.