Flow parser errors over to the CSharpDocument
This commit is contained in:
parent
0bf9abbedf
commit
98d5d1c70e
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue