Skip to content

Commit

Permalink
Allow @@ as a fallback (#10752)
Browse files Browse the repository at this point in the history
* Added new tests for the specific regressed scenario.

* Allow `@@` sequences. Fixes dotnet/sdk#42730 for now. When we move to the new lexer, these will once again be disallowed; attempting to use runtime compilation will necessitate using the native lexer.

* Fixup legacy test baselines
  • Loading branch information
333fred authored Aug 20, 2024
1 parent ff768a6 commit 68650a7
Show file tree
Hide file tree
Showing 34 changed files with 391 additions and 60 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Transition;[@];
CSharpStatementLiteral - [12..28)::16 - [@@@class.Foo() }] - Gen<Stmt> - SpanEditHandler;Accepts:Any
Transition;[@];
Identifier;[@];
Transition;[@];
Identifier;[@class];
Dot;[.];
Identifier;[Foo];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
Whitespace;[ ];
NullCoalesce;[??];
Whitespace;[ ];
Transition;[@];
Identifier;[photo];
Identifier;[@photo];
Dot;[.];
Identifier;[Description];
RazorMetaCode - [46..47)::1 - Gen<None> - SpanEditHandler;Accepts:None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
LessThan;[<];
Identifier;[h3];
GreaterThan;[>];
Transition;[@];
Identifier;[message];
Identifier;[@message];
LessThan;[<];
Slash;[/];
Identifier;[h3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10516,6 +10516,21 @@ public void AtTransitions()
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/sdk/issues/42730")]
public void AtAtHandled()
{
var generated = CompileToCSharp("""
@{ var validationMessage = @Html.ValidationMessage("test", "", new { @@class = "invalid-feedback" }, "div"); }
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated,
// x:\dir\subdir\Test\TestComponent.cshtml(1,28): error CS0103: The name 'Html' does not exist in the current context
// var validationMessage = @Html.ValidationMessage("test", "", new { @@class = "invalid-feedback" }, "div");
Diagnostic(ErrorCode.ERR_NameNotInContext, "@Html").WithArguments("Html").WithLocation(1, 28));
}

#endregion

#region LinePragmas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable disable

using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.AspNetCore.Razor.Language.Legacy;
Expand Down Expand Up @@ -880,6 +881,31 @@ public void EscapedIdentifiers_10()
""");
}

[Fact, WorkItem("https://github.com/dotnet/sdk/issues/42730")]
public void EscapedIdentifiers_11()
{
ParseDocumentTest("""
@{ var validationMessage = @Html.ValidationMessage(Model.Binding, "", new { @@class = "invalid-feedback" }, "div"); }
""");
}

[Fact, WorkItem("https://github.com/dotnet/sdk/issues/42730")]
public void EscapedIdentifiers_12()
{
ParseDocumentTest("""
@{
@@
""");
}

[Fact, WorkItem("https://github.com/dotnet/sdk/issues/42730")]
public void EscapedIdentifiers_13()
{
ParseDocumentTest("""
@{ var validationMessage = new { @@
""");
}

private void RunRazorCommentBetweenClausesTest(string preComment, string postComment, AcceptedCharactersInternal acceptedCharacters = AcceptedCharactersInternal.Any)
{
ParseDocumentTest(preComment + "@* Foo *@ @* Bar *@" + postComment);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 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)
{
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
var validationMessage = @Html.ValidationMessage("test", "", new {

#line default
#line hidden
#nullable disable
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
@class = "invalid-feedback" }, "div");

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
CSharpCode - (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - var validationMessage = @Html.ValidationMessage("test", "", new {
CSharpCode - (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - @class = "invalid-feedback" }, "div");
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source Location: (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml)
| var validationMessage = @Html.ValidationMessage("test", "", new { |
Generated Location: (987:28,2 [67] )
| var validationMessage = @Html.ValidationMessage("test", "", new { |

Source Location: (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml)
|@class = "invalid-feedback" }, "div"); |
Generated Location: (1246:35,70 [39] )
|@class = "invalid-feedback" }, "div"); |

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <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)
{
#nullable restore
#line (1,3)-(1,70) "x:\dir\subdir\Test\TestComponent.cshtml"
var validationMessage = @Html.ValidationMessage("test", "", new {

#line default
#line hidden
#nullable disable

#nullable restore
#line (1,71)-(1,110) "x:\dir\subdir\Test\TestComponent.cshtml"
@class = "invalid-feedback" }, "div");

#line default
#line hidden
#nullable disable

}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [22] ) - global::System
UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [27] ) - global::System.Linq
UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode - (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - var validationMessage = @Html.ValidationMessage("test", "", new {
CSharpCode - (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - @class = "invalid-feedback" }, "div");
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source Location: (2:0,2 [67] x:\dir\subdir\Test\TestComponent.cshtml)
| var validationMessage = @Html.ValidationMessage("test", "", new { |
Generated Location: (735:21,0 [67] )
| var validationMessage = @Html.ValidationMessage("test", "", new { |

Source Location: (70:0,70 [39] x:\dir\subdir\Test\TestComponent.cshtml)
|@class = "invalid-feedback" }, "div"); |
Generated Location: (939:29,0 [39] )
|@class = "invalid-feedback" }, "div"); |

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
LeftParenthesis;[(];
CSharpCodeBlock - [38..45)::7
CSharpExpressionLiteral - [38..45)::7 - [@string] - Gen<Expr>
Transition;[@];
Keyword;[string];
Identifier;[@string];
RazorMetaCode - [45..46)::1 - Gen<None>
RightParenthesis;[)];
MarkupTextLiteral - [46..46)::0 - [] - Gen<Markup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Whitespace;[ ];
Identifier;[var];
Whitespace;[ ];
Identifier;[@];
Transition;[@];
Identifier;[@class];
Whitespace;[ ];
Assign;[=];
Expand All @@ -30,7 +30,7 @@
Whitespace;[ ];
Assign;[=];
Whitespace;[ ];
Identifier;[@];
Transition;[@];
Identifier;[@class];
Semicolon;[;];
NewLine;[LF];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
LeftParenthesis;[(];
CSharpCodeBlock - [74..81)::7
CSharpExpressionLiteral - [74..81)::7 - [@string] - Gen<Expr>
Transition;[@];
Keyword;[string];
Identifier;[@string];
RazorMetaCode - [81..82)::1 - Gen<None>
RightParenthesis;[)];
MarkupTextLiteral - [82..82)::0 - [] - Gen<Markup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
LeftParenthesis;[(];
CSharpCodeBlock - [75..82)::7
CSharpExpressionLiteral - [75..82)::7 - [@string] - Gen<Expr>
Transition;[@];
Keyword;[string];
Identifier;[@string];
RazorMetaCode - [82..83)::1 - Gen<None>
RightParenthesis;[)];
MarkupTextLiteral - [83..83)::0 - [] - Gen<Markup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
LeftParenthesis;[(];
CSharpCodeBlock - [115..122)::7
CSharpExpressionLiteral - [115..122)::7 - [@string] - Gen<Expr>
Transition;[@];
Keyword;[string];
Identifier;[@string];
RazorMetaCode - [122..123)::1 - Gen<None>
RightParenthesis;[)];
MarkupTextLiteral - [123..123)::0 - [] - Gen<Markup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
LeftParenthesis;[(];
CSharpCodeBlock - [117..124)::7
CSharpExpressionLiteral - [117..124)::7 - [@string] - Gen<Expr>
Transition;[@];
Keyword;[string];
Identifier;[@string];
RazorMetaCode - [124..125)::1 - Gen<None>
RightParenthesis;[)];
MarkupTextLiteral - [125..125)::0 - [] - Gen<Markup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [118] )
Code span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [118] )
Transition span at (1:0,1 [1] ) - Parent: Statement block at (1:0,1 [117] )
MetaCode span at (2:0,2 [1] ) - Parent: Statement block at (1:0,1 [117] )
Code span at (3:0,3 [74] ) - Parent: Statement block at (1:0,1 [117] )
Code span at (77:0,77 [1] ) - Parent: Statement block at (1:0,1 [117] )
Code span at (78:0,78 [39] ) - Parent: Statement block at (1:0,1 [117] )
MetaCode span at (117:0,117 [1] ) - Parent: Statement block at (1:0,1 [117] )
Markup span at (118:0,118 [0] ) - Parent: Markup block at (0:0,0 [118] )
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
RazorDocument - [0..118)::118 - [ @{ var validationMessage = @Html.ValidationMessage(Model.Binding, "", new { @@class = "invalid-feedback" }, "div"); }]
MarkupBlock - [0..118)::118
MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup>
Marker;[];
CSharpCodeBlock - [0..118)::118
CSharpStatementLiteral - [0..1)::1 - [ ] - Gen<Stmt>
Whitespace;[ ];
CSharpStatement - [1..118)::117
CSharpTransition - [1..2)::1 - Gen<None>
Transition;[@];
CSharpStatementBody - [2..118)::116
RazorMetaCode - [2..3)::1 - Gen<None>
LeftBrace;[{];
CSharpCodeBlock - [3..117)::114
CSharpStatementLiteral - [3..77)::74 - [ var validationMessage = @Html.ValidationMessage(Model.Binding, "", new { ] - Gen<Stmt>
Whitespace;[ ];
Identifier;[var];
Whitespace;[ ];
Identifier;[validationMessage];
Whitespace;[ ];
Assign;[=];
Whitespace;[ ];
Identifier;[@Html];
Dot;[.];
Identifier;[ValidationMessage];
LeftParenthesis;[(];
Identifier;[Model];
Dot;[.];
Identifier;[Binding];
Comma;[,];
Whitespace;[ ];
StringLiteral;[""];
Comma;[,];
Whitespace;[ ];
Keyword;[new];
Whitespace;[ ];
LeftBrace;[{];
Whitespace;[ ];
CSharpEphemeralTextLiteral - [77..78)::1 - [@] - Gen<Stmt>
Transition;[@];
CSharpStatementLiteral - [78..117)::39 - [@class = "invalid-feedback" }, "div"); ] - Gen<Stmt>
Identifier;[@class];
Whitespace;[ ];
Assign;[=];
Whitespace;[ ];
StringLiteral;["invalid-feedback"];
Whitespace;[ ];
RightBrace;[}];
Comma;[,];
Whitespace;[ ];
StringLiteral;["div"];
RightParenthesis;[)];
Semicolon;[;];
Whitespace;[ ];
RazorMetaCode - [117..118)::1 - Gen<None>
RightBrace;[}];
MarkupTextLiteral - [118..118)::0 - [] - Gen<Markup>
Marker;[];
EndOfFile;[];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [10] )
Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [10] )
MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [10] )
Code span at (2:0,2 [6] ) - Parent: Statement block at (0:0,0 [10] )
Code span at (8:1,4 [1] ) - Parent: Statement block at (0:0,0 [10] )
Code span at (9:1,5 [1] ) - Parent: Statement block at (0:0,0 [10] )
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
Loading

0 comments on commit 68650a7

Please sign in to comment.