Emit and map empty csharp tokens (#10969)

* Emit and map empty csharp tokens
- Add test and update baselines
* Unskip test
This commit is contained in:
Chris Sienkiewicz 2024-10-08 11:26:23 -07:00 коммит произвёл GitHub
Родитель ef8467d7c2
Коммит 7f81d931d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
13 изменённых файлов: 222 добавлений и 7 удалений

Просмотреть файл

@ -2103,6 +2103,34 @@ namespace Test
CompileToAssembly(generated);
}
[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10965")]
public void InvalidCode_EmptyTransition()
{
// Act
var generated = CompileToCSharp("""
<TestComponent Value="Hello" />
@
@code {
[Parameter] public int Param { get; set; }
}
""");
// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated, DesignTime?[
// x:\dir\subdir\Test\TestComponent.cshtml(3,7): error CS1525: Invalid expression term ';'
// __o = ;
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ";").WithArguments(";").WithLocation(3, 7)
] : [
// (24,36): error CS1525: Invalid expression term ')'
// __builder.AddContent(3,
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments(")").WithLocation(24, 36)
]);
}
#endregion
#region Bind

Просмотреть файл

@ -0,0 +1,57 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o = "";
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.TestComponent);
#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = ;
#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
#nullable restore
#line 5 "x:\dir\subdir\Test\TestComponent.cshtml"
[Parameter] public int Param { get; set; }
#line default
#line hidden
#nullable disable
}
}
#pragma warning restore 1591

Просмотреть файл

@ -0,0 +1 @@
x:\dir\subdir\Test\TestComponent.cshtml(3,2): Error RZ1003: A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.

Просмотреть файл

@ -0,0 +1,28 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - TestComponent
ComponentAttribute - - Value - - AttributeStructure.DoubleQuotes
HtmlContent - (22:0,22 [5] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (22:0,22 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlContent - (31:0,31 [4] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (31:0,31 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpExpression - (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp -
HtmlContent - (36:2,1 [4] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (36:2,1 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpCode - (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n [Parameter] public int Param { get; set; }\n

Просмотреть файл

@ -0,0 +1,14 @@
Source Location: (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml)
||
Generated Location: (1340:39,6 [0] )
||
Source Location: (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
[Parameter] public int Param { get; set; }
|
Generated Location: (1519:48,7 [50] )
|
[Parameter] public int Param { get; set; }
|

Просмотреть файл

@ -34,7 +34,15 @@ using Microsoft.AspNetCore.Components.Web
#line hidden
#nullable disable
));
string __formName = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<string>();
string __formName = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<string>(
#nullable restore
#line (2,56)-(2,57) "x:\dir\subdir\Test\TestComponent.cshtml"
#line default
#line hidden
#nullable disable
);
__builder.AddNamedEvent("onsubmit", __formName);
__builder.CloseElement();
}

Просмотреть файл

@ -8,3 +8,8 @@ Source Location: (75:1,31 [9] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (1138:30,0 [9] )
|() => { }|
Source Location: (99:1,55 [1] x:\dir\subdir\Test\TestComponent.cshtml)
| |
Generated Location: (1422:39,0 [1] )
| |

Просмотреть файл

@ -0,0 +1,45 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.OpenComponent<global::Test.TestComponent>(0);
__builder.AddComponentParameter(1, "Value", "Hello");
__builder.CloseComponent();
__builder.AddMarkupContent(2, "\r\n\r\n");
__builder.AddContent(3,
#nullable restore
#line (3,2)-(3,2) "x:\dir\subdir\Test\TestComponent.cshtml"
#line default
#line hidden
#nullable disable
);
}
#pragma warning restore 1998
#nullable restore
#line (5,8)-(7,1) "x:\dir\subdir\Test\TestComponent.cshtml"
[Parameter] public int Param { get; set; }
#line default
#line hidden
#nullable disable
}
}
#pragma warning restore 1591

Просмотреть файл

@ -0,0 +1 @@
x:\dir\subdir\Test\TestComponent.cshtml(3,2): Error RZ1003: A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.

Просмотреть файл

@ -0,0 +1,19 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - TestComponent
ComponentAttribute - - Value - - AttributeStructure.DoubleQuotes
HtmlContent - (22:0,22 [5] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (22:0,22 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlContent - (31:0,31 [4] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (31:0,31 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpExpression - (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp -
CSharpCode - (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n [Parameter] public int Param { get; set; }\n

Просмотреть файл

@ -0,0 +1,14 @@
Source Location: (36:2,1 [0] x:\dir\subdir\Test\TestComponent.cshtml)
||
Generated Location: (1005:26,0 [0] )
||
Source Location: (47:4,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
[Parameter] public int Param { get; set; }
|
Generated Location: (1200:35,0 [50] )
|
[Parameter] public int Param { get; set; }
|

Просмотреть файл

@ -1188,11 +1188,6 @@ internal class ComponentRuntimeNodeWriter : ComponentNodeWriter
private static void WriteCSharpToken(CodeRenderingContext context, IntermediateToken token)
{
if (string.IsNullOrWhiteSpace(token.Content))
{
return;
}
if (token.Source?.FilePath == null)
{
context.CodeWriter.Write(token.Content);

Просмотреть файл

@ -35,7 +35,7 @@ public class NonRazorSdkTests(ITestOutputHelper testOutputHelper) : AbstractRazo
base.PrepareProjectForFirstOpen(projectFileName);
}
[IdeFact(Skip = "https://github.com/dotnet/razor/issues/10965")] // Completion is broken in FUSE for sole `@` characters
[IdeFact]
public async Task Completion_DateTime()
{
// We open the Index.razor file, and wait for 3 RazorComponentElement's to be classified, as that