Skip to content

Conversation

@chsienki
Copy link
Member

Fixes #7230

Comment on lines +34 to +50
LessThan;[<];
Identifier;[span];
GreaterThan;[>];
Identifier;[some];
Whitespace;[ ];
LessThan;[<];
Identifier;[i];
GreaterThan;[>];
Identifier;[html];
LessThan;[<];
CSharpOperator;[/];
Identifier;[i];
GreaterThan;[>];
LessThan;[<];
CSharpOperator;[/];
Identifier;[span];
GreaterThan;[>];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, we're saying that this is interpreted as C#, not razor? That seems reasonable, but just wanted to make sure that's what was intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once inside a switch expression everything is parsed as C# and you can't drop into HTML.

Accept(in read);
return;
}
else if (At(SyntaxKind.Keyword))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that ParseStatement will handle all possible locations here. What if it's an embedded expression inside a @(), for example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, so I tried that and it actually just works. Because we don't allow you to drop to HTML inside an explicit expression, we don't have to do any special handling for it.

I added some tests to cover it too.

@chsienki chsienki marked this pull request as ready for review November 18, 2025 23:24
@chsienki chsienki requested a review from a team as a code owner November 18, 2025 23:24
Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed early, this is valid in Razor files today:

@{ 
    RenderFragment x = val switch 
    {
        true => @<div></div>,
        false => @<div></div>
    };
}

Would be good to add a test, even if it's skipped for now, with what that looks like now, and what it looks like with a less than as the first character in the first arm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relational Patterns are confused with tags in Razor

3 participants