Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify handling of the @ character in razor code blocks #10232

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode");

public CodeGenerationIntegrationTest()
: base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X")
: base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X")
{
Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode");

public CodeGenerationIntegrationTest()
: base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X")
: base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X")
{
Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InstrumentationPassIntegrationTest : IntegrationTestBase
private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode");

public InstrumentationPassIntegrationTest()
: base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X")
: base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X")
{
Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode");

public CodeGenerationIntegrationTest()
: base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions")
: base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions")
{
Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System;
using Xunit;

namespace Microsoft.AspNetCore.Razor.Language.Legacy;
Expand Down Expand Up @@ -40,7 +39,7 @@ public void CSharpBlock_SingleLineControlFlowStatement()
}

[Fact]
public void LocalFunctionsWithRazor()
public void LocalFunctionsWithRazor_MissingSemicolon()
{
ParseDocumentTest(
@"@{
Expand All @@ -52,6 +51,19 @@ void Foo()
}");
}

[Fact]
public void LocalFunctionsWithRazor()
{
ParseDocumentTest(
@"@{
void Foo()
{
var time = DateTime.Now;
<strong>Hello the time is @time</strong>
}
}");
}

[Fact]
public void LocalFunctionsWithGenerics()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] )
Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
Code span at (2:0,2 [66] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] )
Markup span at (68:4,8 [8] ) (Accepts:None) - Parent: Tag block at (68:4,8 [8] )
Markup span at (76:4,16 [18] ) (Accepts:Any) - Parent: Markup block at (68:4,8 [42] )
Transition span at (94:4,34 [1] ) (Accepts:None) - Parent: Expression block at (94:4,34 [5] )
Code span at (95:4,35 [4] ) (Accepts:NonWhitespace) - Parent: Expression block at (94:4,34 [5] )
Markup span at (99:4,39 [9] ) (Accepts:None) - Parent: Tag block at (99:4,39 [9] )
Markup span at (108:4,48 [2] ) (Accepts:None) - Parent: Markup block at (68:4,8 [42] )
Code span at (110:5,0 [7] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] )
MetaCode span at (117:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
Markup span at (118:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] )
Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [119] )
Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] )
MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] )
Code span at (2:0,2 [59] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [119] )
Markup span at (61:4,0 [8] ) (Accepts:Any) - Parent: Markup block at (61:4,0 [50] )
Markup span at (69:4,8 [8] ) (Accepts:None) - Parent: Tag block at (69:4,8 [8] )
Markup span at (77:4,16 [18] ) (Accepts:Any) - Parent: Markup block at (61:4,0 [50] )
Transition span at (95:4,34 [1] ) (Accepts:None) - Parent: Expression block at (95:4,34 [5] )
Code span at (96:4,35 [4] ) (Accepts:NonWhitespace) - Parent: Expression block at (95:4,34 [5] )
Markup span at (100:4,39 [9] ) (Accepts:None) - Parent: Tag block at (100:4,39 [9] )
Markup span at (109:4,48 [2] ) (Accepts:None) - Parent: Markup block at (61:4,0 [50] )
Code span at (111:5,0 [7] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [119] )
MetaCode span at (118:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] )
Markup span at (119:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [119] )
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
RazorDocument - [0..118)::118 - [@{LF void Foo()LF {LF var time = DateTime.NowLF <strong>Hello the time is @time</strong>LF }LF}]
MarkupBlock - [0..118)::118
RazorDocument - [0..119)::119 - [@{LF void Foo()LF {LF var time = DateTime.Now;LF <strong>Hello the time is @time</strong>LF }LF}]
MarkupBlock - [0..119)::119
MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup> - SpanEditHandler;Accepts:Any
Marker;[];
CSharpCodeBlock - [0..118)::118
CSharpStatement - [0..118)::118
CSharpCodeBlock - [0..119)::119
CSharpStatement - [0..119)::119
CSharpTransition - [0..1)::1 - Gen<None> - SpanEditHandler;Accepts:None
Transition;[@];
CSharpStatementBody - [1..118)::117
CSharpStatementBody - [1..119)::118
RazorMetaCode - [1..2)::1 - Gen<None> - SpanEditHandler;Accepts:None
LeftBrace;[{];
CSharpCodeBlock - [2..117)::115
CSharpStatementLiteral - [2..68)::66 - [LF void Foo()LF {LF var time = DateTime.NowLF ] - Gen<Stmt> - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[<null>];AtEOL
CSharpCodeBlock - [2..118)::116
CSharpStatementLiteral - [2..61)::59 - [LF void Foo()LF {LF var time = DateTime.Now;LF] - Gen<Stmt> - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[<null>];AtEOL
NewLine;[LF];
Whitespace;[ ];
Keyword;[void];
Expand All @@ -32,15 +32,17 @@
Identifier;[DateTime];
Dot;[.];
Identifier;[Now];
Semicolon;[;];
NewLine;[LF];
Whitespace;[ ];
MarkupBlock - [68..110)::42
MarkupElement - [68..108)::40
MarkupStartTag - [68..76)::8 - [<strong>] - Gen<Markup> - SpanEditHandler;Accepts:None
MarkupBlock - [61..111)::50
MarkupTextLiteral - [61..69)::8 - [ ] - Gen<Markup> - SpanEditHandler;Accepts:Any
Whitespace;[ ];
MarkupElement - [69..109)::40
MarkupStartTag - [69..77)::8 - [<strong>] - Gen<Markup> - SpanEditHandler;Accepts:None
OpenAngle;[<];
Text;[strong];
CloseAngle;[>];
MarkupTextLiteral - [76..94)::18 - [Hello the time is ] - Gen<Markup> - SpanEditHandler;Accepts:Any
MarkupTextLiteral - [77..95)::18 - [Hello the time is ] - Gen<Markup> - SpanEditHandler;Accepts:Any
Text;[Hello];
Whitespace;[ ];
Text;[the];
Expand All @@ -49,27 +51,27 @@
Whitespace;[ ];
Text;[is];
Whitespace;[ ];
CSharpCodeBlock - [94..99)::5
CSharpImplicitExpression - [94..99)::5
CSharpTransition - [94..95)::1 - Gen<None> - SpanEditHandler;Accepts:None
CSharpCodeBlock - [95..100)::5
CSharpImplicitExpression - [95..100)::5
CSharpTransition - [95..96)::1 - Gen<None> - SpanEditHandler;Accepts:None
Transition;[@];
CSharpImplicitExpressionBody - [95..99)::4
CSharpCodeBlock - [95..99)::4
CSharpExpressionLiteral - [95..99)::4 - [time] - Gen<Expr> - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K14
CSharpImplicitExpressionBody - [96..100)::4
CSharpCodeBlock - [96..100)::4
CSharpExpressionLiteral - [96..100)::4 - [time] - Gen<Expr> - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K14
Identifier;[time];
MarkupEndTag - [99..108)::9 - [</strong>] - Gen<Markup> - SpanEditHandler;Accepts:None
MarkupEndTag - [100..109)::9 - [</strong>] - Gen<Markup> - SpanEditHandler;Accepts:None
OpenAngle;[<];
ForwardSlash;[/];
Text;[strong];
CloseAngle;[>];
MarkupTextLiteral - [108..110)::2 - [LF] - Gen<Markup> - SpanEditHandler;Accepts:None
MarkupTextLiteral - [109..111)::2 - [LF] - Gen<Markup> - SpanEditHandler;Accepts:None
NewLine;[LF];
CSharpStatementLiteral - [110..117)::7 - [ }LF] - Gen<Stmt> - SpanEditHandler;Accepts:Any
CSharpStatementLiteral - [111..118)::7 - [ }LF] - Gen<Stmt> - SpanEditHandler;Accepts:Any
Whitespace;[ ];
RightBrace;[}];
NewLine;[LF];
RazorMetaCode - [117..118)::1 - Gen<None> - SpanEditHandler;Accepts:None
RazorMetaCode - [118..119)::1 - Gen<None> - SpanEditHandler;Accepts:None
RightBrace;[}];
MarkupTextLiteral - [118..118)::0 - [] - Gen<Markup> - SpanEditHandler;Accepts:Any
MarkupTextLiteral - [119..119)::0 - [] - Gen<Markup> - SpanEditHandler;Accepts:Any
Marker;[];
EndOfFile;[];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] )
Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
Code span at (2:0,2 [115] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] )
MetaCode span at (117:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] )
Markup span at (118:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] )
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
RazorDocument - [0..118)::118 - [@{LF void Foo()LF {LF var time = DateTime.NowLF <strong>Hello the time is @time</strong>LF }LF}]
MarkupBlock - [0..118)::118
MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup> - SpanEditHandler;Accepts:Any
Marker;[];
CSharpCodeBlock - [0..118)::118
CSharpStatement - [0..118)::118
CSharpTransition - [0..1)::1 - Gen<None> - SpanEditHandler;Accepts:None
Transition;[@];
CSharpStatementBody - [1..118)::117
RazorMetaCode - [1..2)::1 - Gen<None> - SpanEditHandler;Accepts:None
LeftBrace;[{];
CSharpCodeBlock - [2..117)::115
CSharpStatementLiteral - [2..117)::115 - [LF void Foo()LF {LF var time = DateTime.NowLF <strong>Hello the time is @time</strong>LF }LF] - Gen<Stmt> - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[<null>];AtEOL
NewLine;[LF];
Whitespace;[ ];
Keyword;[void];
Whitespace;[ ];
Identifier;[Foo];
LeftParenthesis;[(];
RightParenthesis;[)];
NewLine;[LF];
Whitespace;[ ];
LeftBrace;[{];
NewLine;[LF];
Whitespace;[ ];
Identifier;[var];
Whitespace;[ ];
Identifier;[time];
Whitespace;[ ];
Assign;[=];
Whitespace;[ ];
Identifier;[DateTime];
Dot;[.];
Identifier;[Now];
NewLine;[LF];
Whitespace;[ ];
LessThan;[<];
Identifier;[strong];
GreaterThan;[>];
Identifier;[Hello];
Whitespace;[ ];
Identifier;[the];
Whitespace;[ ];
Identifier;[time];
Whitespace;[ ];
Keyword;[is];
Whitespace;[ ];
Identifier;[@time];
LessThan;[<];
Slash;[/];
Identifier;[strong];
GreaterThan;[>];
NewLine;[LF];
Whitespace;[ ];
RightBrace;[}];
NewLine;[LF];
RazorMetaCode - [117..118)::1 - Gen<None> - SpanEditHandler;Accepts:None
RightBrace;[}];
MarkupTextLiteral - [118..118)::0 - [] - Gen<Markup> - SpanEditHandler;Accepts:Any
Marker;[];
EndOfFile;[];
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
Whitespace;[ ];
Assign;[=];
Whitespace;[ ];
Transition;[@];
Identifier;[x];
Identifier;[@x];
Semicolon;[;];
Whitespace;[ ];
Keyword;[if];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(1,14): Error RZ1009: The "@" character must be followed by a ":", "(", or a C# identifier. If you intended to switch to markup, use an HTML start tag, for example:
333fred marked this conversation as resolved.
Show resolved Hide resolved

@if(isLoggedIn) {
<p>Hello, @user!</p>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
Transition;[@];
CSharpStatementLiteral - [12..28)::16 - [@@@class.Foo() }] - Gen<Stmt> - SpanEditHandler;Accepts:Any
Transition;[@];
Transition;[@];
Transition;[@];
Keyword;[class];
Identifier;[@];
Identifier;[@class];
Dot;[.];
Identifier;[Foo];
LeftParenthesis;[(];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [65] )
Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [65] )
Code span at (1:0,1 [43] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] )
Markup span at (44:2,4 [3] ) (Accepts:None) - Parent: Tag block at (44:2,4 [3] )
Markup span at (47:2,7 [7] ) (Accepts:Any) - Parent: Markup block at (44:2,4 [20] )
Transition span at (54:2,14 [1] ) (Accepts:None) - Parent: Expression block at (54:2,14 [4] )
Code span at (55:2,15 [3] ) (Accepts:NonWhitespace) - Parent: Expression block at (54:2,14 [4] )
Markup span at (58:2,18 [4] ) (Accepts:None) - Parent: Tag block at (58:2,18 [4] )
Markup span at (62:2,22 [2] ) (Accepts:None) - Parent: Markup block at (44:2,4 [20] )
Code span at (64:3,0 [1] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] )
Code span at (1:0,1 [64] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] )
Loading