Follow-ups from PR 23385 (#24834)
* Make preservewhitespace use FileScopedSinglyOccurring * Design-time experience for boolean directive tokens * Update baselines
This commit is contained in:
parent
04ca38bcfb
commit
faf1d80af1
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
builder =>
|
||||
{
|
||||
builder.AddBooleanToken(ComponentResources.PreserveWhitespaceDirective_BooleanToken_Name, ComponentResources.PreserveWhitespaceDirective_BooleanToken_Description);
|
||||
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring;
|
||||
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
|
||||
builder.Description = ComponentResources.PreserveWhitespaceDirective_Description;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,22 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
context.CodeWriter.WriteLine(";");
|
||||
}
|
||||
break;
|
||||
|
||||
case DirectiveTokenKind.Boolean:
|
||||
// global::System.Boolean __typeHelper = {node.Content};
|
||||
using (context.CodeWriter.BuildLinePragma(node.Source, context))
|
||||
{
|
||||
context.CodeWriter
|
||||
.Write("global::")
|
||||
.Write(typeof(bool).FullName)
|
||||
.Write(" ")
|
||||
.WriteStartAssignment(TypeHelper);
|
||||
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter.Write(node.Content);
|
||||
context.CodeWriter.WriteLine(";");
|
||||
}
|
||||
break;
|
||||
}
|
||||
context.CodeWriter.CurrentIndent = originalIndent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,6 +202,47 @@ global::System.Object __typeHelper = ""Value"";
|
|||
#line 1 ""test.cshtml""
|
||||
global::System.Object __typeHelper = ""Value"";
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
))();
|
||||
}
|
||||
#pragma warning restore 219
|
||||
",
|
||||
csharp,
|
||||
ignoreLineEndingDifferences: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteDesignTimeDirective_WithBooleanToken_WritesLambda()
|
||||
{
|
||||
// Arrange
|
||||
var extension = new DesignTimeDirectiveTargetExtension();
|
||||
var context = TestCodeRenderingContext.CreateDesignTime();
|
||||
|
||||
var node = new DesignTimeDirectiveIntermediateNode();
|
||||
var token = new DirectiveTokenIntermediateNode()
|
||||
{
|
||||
Source = new SourceSpan("test.cshtml", 0, 0, 0, 5),
|
||||
Content = "true",
|
||||
DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Boolean),
|
||||
};
|
||||
node.Children.Add(token);
|
||||
|
||||
// Act
|
||||
extension.WriteDesignTimeDirective(context, node);
|
||||
|
||||
// Assert
|
||||
var csharp = context.CodeWriter.GenerateCode();
|
||||
Assert.Equal(
|
||||
@"#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
#nullable restore
|
||||
#line 1 ""test.cshtml""
|
||||
global::System.Boolean __typeHelper = true;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ namespace Test
|
|||
#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
#nullable restore
|
||||
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
global::System.Boolean __typeHelper = false;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
))();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ Document -
|
|||
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
|
||||
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
|
||||
DesignTimeDirective -
|
||||
DirectiveToken - (20:0,20 [4] x:\dir\subdir\Test\_Imports.razor) - true
|
||||
DirectiveToken - (20:0,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - false
|
||||
CSharpCode -
|
||||
IntermediateToken - - CSharp - #pragma warning disable 0414
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
Source Location: (20:0,20 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|false|
|
||||
Generated Location: (581:17,38 [5] )
|
||||
|false|
|
||||
|
||||
Source Location: (52:3,13 [12] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|DateTime.Now|
|
||||
Generated Location: (925:27,13 [12] )
|
||||
Generated Location: (1091:34,13 [12] )
|
||||
|DateTime.Now|
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ namespace Test
|
|||
#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
#nullable restore
|
||||
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
global::System.Boolean __typeHelper = false;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
))();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
Source Location: (20:0,20 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|false|
|
||||
Generated Location: (581:17,38 [5] )
|
||||
|false|
|
||||
|
||||
Source Location: (40:3,5 [63] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|foreach (var item in Enumerable.Range(1, 100))
|
||||
{
|
||||
|
|
||||
Generated Location: (917:27,5 [63] )
|
||||
Generated Location: (1083:34,5 [63] )
|
||||
|foreach (var item in Enumerable.Range(1, 100))
|
||||
{
|
||||
|
|
||||
|
||||
Source Location: (122:6,13 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|item|
|
||||
Generated Location: (1115:36,13 [4] )
|
||||
Generated Location: (1281:43,13 [4] )
|
||||
|item|
|
||||
|
||||
Source Location: (141:7,13 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|
|
||||
}|
|
||||
Generated Location: (1255:43,13 [7] )
|
||||
Generated Location: (1421:50,13 [7] )
|
||||
|
|
||||
}|
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ namespace Test
|
|||
#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
#nullable restore
|
||||
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
global::System.Boolean __typeHelper = true;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
))();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
Source Location: (20:0,20 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|true|
|
||||
Generated Location: (581:17,38 [4] )
|
||||
|true|
|
||||
|
||||
Source Location: (39:3,5 [63] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|foreach (var item in Enumerable.Range(1, 100))
|
||||
{
|
||||
|
|
||||
Generated Location: (917:27,5 [63] )
|
||||
Generated Location: (1082:34,5 [63] )
|
||||
|foreach (var item in Enumerable.Range(1, 100))
|
||||
{
|
||||
|
|
||||
|
||||
Source Location: (121:6,13 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|item|
|
||||
Generated Location: (1115:36,13 [4] )
|
||||
Generated Location: (1280:43,13 [4] )
|
||||
|item|
|
||||
|
||||
Source Location: (140:7,13 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|
|
||||
}|
|
||||
Generated Location: (1255:43,13 [7] )
|
||||
Generated Location: (1420:50,13 [7] )
|
||||
|
|
||||
}|
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ namespace Test
|
|||
#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
#nullable restore
|
||||
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
global::System.Boolean __typeHelper = true;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
))();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
Source Location: (20:0,20 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|true|
|
||||
Generated Location: (581:17,38 [4] )
|
||||
|true|
|
||||
|
||||
Source Location: (44:2,16 [3] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|Foo|
|
||||
Generated Location: (948:28,16 [3] )
|
||||
Generated Location: (1113:35,16 [3] )
|
||||
|Foo|
|
||||
|
||||
Source Location: (95:6,11 [29] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|
|
||||
int Foo = 18;
|
||||
|
|
||||
Generated Location: (1148:38,11 [29] )
|
||||
Generated Location: (1313:45,11 [29] )
|
||||
|
|
||||
int Foo = 18;
|
||||
|
|
||||
|
|
|
|||
Loading…
Reference in New Issue