Skip to content

Commit 29deee8

Browse files
Add TagHelperInfo and TagHelperAttributeInfo to syntax model and remove from annotations
1 parent 2e62cfd commit 29deee8

13 files changed

+185
-257
lines changed

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/TagHelperBlockRewriter.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,13 @@ private static TryParseResult TryParseMinimizedAttribute(
236236
{
237237
var rewritten = SyntaxFactory.MarkupMinimizedTagHelperAttribute(
238238
attributeBlock.NamePrefix,
239-
attributeBlock.Name);
240-
241-
rewritten = rewritten.WithTagHelperAttributeInfo(
242-
new TagHelperAttributeInfo(result.AttributeName, parameterName: null, result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: false));
239+
attributeBlock.Name,
240+
new TagHelperAttributeInfo(
241+
result.AttributeName,
242+
parameterName: null,
243+
result.AttributeStructure,
244+
result.IsBoundAttribute,
245+
isDirectiveAttribute: false));
243246

244247
result.RewrittenAttribute = rewritten;
245248

@@ -314,10 +317,13 @@ private static TryParseResult TryParseAttribute(
314317
attributeBlock.EqualsToken,
315318
attributeBlock.ValuePrefix,
316319
rewrittenValue,
317-
attributeBlock.ValueSuffix);
318-
319-
rewritten = rewritten.WithTagHelperAttributeInfo(
320-
new TagHelperAttributeInfo(result.AttributeName, parameterName: null, result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: false));
320+
attributeBlock.ValueSuffix,
321+
new TagHelperAttributeInfo(
322+
result.AttributeName,
323+
parameterName: null,
324+
result.AttributeStructure,
325+
result.IsBoundAttribute,
326+
isDirectiveAttribute: false));
321327

322328
result.RewrittenAttribute = rewritten;
323329

@@ -368,7 +374,7 @@ private static MarkupTagHelperDirectiveAttributeSyntax RewriteToDirectiveAttribu
368374
parameterName = SyntaxFactory.MarkupTextLiteral(parameterNameToken);
369375
}
370376

371-
var rewritten = SyntaxFactory.MarkupTagHelperDirectiveAttribute(
377+
return SyntaxFactory.MarkupTagHelperDirectiveAttribute(
372378
attributeBlock.NamePrefix,
373379
transition,
374380
attributeNameSyntax,
@@ -378,12 +384,13 @@ private static MarkupTagHelperDirectiveAttributeSyntax RewriteToDirectiveAttribu
378384
attributeBlock.EqualsToken,
379385
attributeBlock.ValuePrefix,
380386
rewrittenValue,
381-
attributeBlock.ValueSuffix);
382-
383-
rewritten = rewritten.WithTagHelperAttributeInfo(
384-
new TagHelperAttributeInfo(result.AttributeName, parameterName?.GetContent(), result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: true));
385-
386-
return rewritten;
387+
attributeBlock.ValueSuffix,
388+
new TagHelperAttributeInfo(
389+
result.AttributeName,
390+
parameterName?.GetContent(),
391+
result.AttributeStructure,
392+
result.IsBoundAttribute,
393+
isDirectiveAttribute: true));
387394
}
388395

389396
private static MarkupMinimizedTagHelperDirectiveAttributeSyntax RewriteToMinimizedDirectiveAttribute(
@@ -428,17 +435,18 @@ private static MarkupMinimizedTagHelperDirectiveAttributeSyntax RewriteToMinimiz
428435
parameterName = SyntaxFactory.MarkupTextLiteral(parameterNameToken);
429436
}
430437

431-
var rewritten = SyntaxFactory.MarkupMinimizedTagHelperDirectiveAttribute(
438+
return SyntaxFactory.MarkupMinimizedTagHelperDirectiveAttribute(
432439
attributeBlock.NamePrefix,
433440
transition,
434441
attributeNameSyntax,
435442
colon,
436-
parameterName);
437-
438-
rewritten = rewritten.WithTagHelperAttributeInfo(
439-
new TagHelperAttributeInfo(result.AttributeName, parameterName?.GetContent(), result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: true));
440-
441-
return rewritten;
443+
parameterName,
444+
new TagHelperAttributeInfo(
445+
result.AttributeName,
446+
parameterName?.GetContent(),
447+
result.AttributeStructure,
448+
result.IsBoundAttribute,
449+
isDirectiveAttribute: true));
442450
}
443451

444452
private static MarkupTagHelperAttributeValueSyntax RewriteAttributeValue(TryParseResult result, RazorBlockSyntax attributeValue, RazorParserOptions options)

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/TagHelperParseTreeRewriter.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
120120
// This is a tag helper.
121121
if (tagHelperInfo.TagMode == TagMode.SelfClosing || tagHelperInfo.TagMode == TagMode.StartTagOnly)
122122
{
123-
var tagHelperElement = SyntaxFactory.MarkupTagHelperElement(tagHelperStart, body: default, endTag: null);
124-
var rewrittenTagHelper = tagHelperElement.WithTagHelperInfo(tagHelperInfo);
123+
var tagHelperElement = SyntaxFactory.MarkupTagHelperElement(tagHelperStart, body: default, endTag: null, tagHelperInfo);
124+
125125
if (node.Body.Count == 0 && node.EndTag == null)
126126
{
127-
return rewrittenTagHelper;
127+
return tagHelperElement;
128128
}
129129

130130
// This tag contains a body and/or an end tag which needs to be moved to the parent.
131131
using PooledArrayBuilder<RazorSyntaxNode> rewrittenNodes = [];
132132

133-
rewrittenNodes.Add(rewrittenTagHelper);
133+
rewrittenNodes.Add(tagHelperElement);
134134
var rewrittenBody = VisitList(node.Body);
135135
rewrittenNodes.AddRange(rewrittenBody);
136136

@@ -208,8 +208,7 @@ public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
208208
if (tagHelperInfo != null)
209209
{
210210
// If we get here it means this element was rewritten as a tag helper.
211-
var tagHelperElement = SyntaxFactory.MarkupTagHelperElement(tagHelperStart, body, tagHelperEnd);
212-
return tagHelperElement.WithTagHelperInfo(tagHelperInfo);
211+
return SyntaxFactory.MarkupTagHelperElement(tagHelperStart, body, tagHelperEnd, tagHelperInfo);
213212
}
214213

215214
// There was no matching tag helper for this element. Return.

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/TagHelperSpanVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static ImmutableArray<TagHelperSpanInternal> VisitRoot(RazorSyntaxTree sy
3030

3131
public override void VisitMarkupTagHelperElement(MarkupTagHelperElementSyntax node)
3232
{
33-
var span = new TagHelperSpanInternal(node.GetSourceSpan(_source), node.TagHelperInfo.AssumeNotNull().BindingResult);
33+
var span = new TagHelperSpanInternal(node.GetSourceSpan(_source), node.TagHelperInfo.BindingResult);
3434
_spans.Add(span);
3535

3636
base.VisitMarkupTagHelperElement(node);

0 commit comments

Comments
 (0)