-
Notifications
You must be signed in to change notification settings - Fork 193
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
Fuse incorrect page directives #10907
Fuse incorrect page directives #10907
Conversation
@@ -5550,6 +5550,37 @@ @inherits BaseComponent<string?> | |||
]); | |||
} | |||
|
|||
[IntegrationTestFact] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider adding WorkItem attribute to the new tests
{ | ||
// Act | ||
var generated = CompileToCSharp(@" | ||
@page ""MyPage"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider using raw strings to avoid duplicate quotes
@@ -59,15 +59,16 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte | |||
var pageDirective = (DirectiveIntermediateNode)directives[i].Node; | |||
|
|||
// The parser also adds errors for invalid syntax, we just need to not crash. | |||
var routeToken = pageDirective.Tokens.FirstOrDefault(); | |||
var routeToken = pageDirective.Tokens.First(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change FirstOrDefault
-> First
? Is it guaranteed pageDirective.Tokens
won't be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we won't ever actually encounter a page directive without tokens, because the way it parses goes down a different path. I added the PageDirective_MissingRoute
test to show that behavior.
...Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs
Show resolved
Hide resolved
1309db8
to
38e7f8b
Compare
Fixes #10863
Previously we didn't emit the page directive if it had an error. Now we do, so the user still gets syntax highlighting etc.