Flow parser errors over to the CSharpDocument

This commit is contained in:
Ajay Bhargav Baaskaran 2017-01-26 13:11:15 -08:00
parent 0bf9abbedf
commit 98d5d1c70e
3 changed files with 51 additions and 2 deletions

View File

@ -36,11 +36,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution
};
var visitor = new CSharpRenderer(renderingContext);
visitor.VisitDocument(irDocument);
var combinedErrors = syntaxTree.Diagnostics.Concat(renderingContext.ErrorSink.Errors).ToList();
var csharpDocument = new RazorCSharpDocument()
{
GeneratedCode = renderingContext.Writer.GenerateCode(),
LineMappings = renderingContext.LineMappings,
Diagnostics = renderingContext.ErrorSink.Errors
Diagnostics = combinedErrors
};
codeDocument.SetCSharpDocument(csharpDocument);

View File

@ -37,11 +37,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var visitor = new CSharpRenderer(renderingContext);
visitor.VisitDocument(irDocument);
var combinedErrors = syntaxTree.Diagnostics.Concat(renderingContext.ErrorSink.Errors).ToList();
var csharpDocument = new RazorCSharpDocument()
{
GeneratedCode = renderingContext.Writer.GenerateCode(),
LineMappings = renderingContext.LineMappings,
Diagnostics = renderingContext.ErrorSink.Errors
Diagnostics = combinedErrors
};
codeDocument.SetCSharpDocument(csharpDocument);

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
@ -70,5 +71,49 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
Assert.NotNull(document.GetSyntaxTree());
Assert.NotNull(document.GetIRDocument());
}
[Fact]
public void CSharpDocument_Runtime_PreservesParserErrors()
{
// Arrange
var engine = RazorEngine.Create();
var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@!!!"));
// Act
engine.Process(document);
// Assert
var csharpDocument = document.GetCSharpDocument();
var error = Assert.Single(csharpDocument.Diagnostics);
Assert.Equal(
new RazorError(
LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"),
new SourceLocation(1, 0, 1),
length: 1),
error);
}
[Fact]
public void CSharpDocument_DesignTime_PreservesParserErrors()
{
// Arrange
var engine = RazorEngine.CreateDesignTime();
var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@{"));
// Act
engine.Process(document);
// Assert
var csharpDocument = document.GetCSharpDocument();
var error = Assert.Single(csharpDocument.Diagnostics);
Assert.Equal(
new RazorError(
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(LegacyResources.BlockName_Code, "}", "{"),
new SourceLocation(1, 0, 1),
length: 1),
error);
}
}
}