-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Ensure @typeparam directive descriptor is always set #33456
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language.Components | ||
{ | ||
internal class ComponentConstrainedTypeParamDirective | ||
{ | ||
public static DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( | ||
"typeparam", | ||
DirectiveKind.SingleLine, | ||
builder => | ||
{ | ||
builder.AddMemberToken(ComponentResources.TypeParamDirective_Token_Name, ComponentResources.TypeParamDirective_Token_Description); | ||
builder.AddOptionalGenericTypeConstraintToken(ComponentResources.TypeParamDirective_Constraint_Name, ComponentResources.TypeParamDirective_Constraint_Description); | ||
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; | ||
builder.Description = ComponentResources.TypeParamDirective_Description; | ||
}); | ||
|
||
public static RazorProjectEngineBuilder Register(RazorProjectEngineBuilder builder) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
builder.AddDirective(Directive, FileKinds.Component, FileKinds.ComponentImport); | ||
return builder; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,12 @@ protected override void OnDocumentStructureCreated( | |
{ | ||
@class.BaseType = ComponentsApi.ComponentBase.FullTypeName; | ||
|
||
var typeParamReferences = documentNode.FindDirectiveReferences(ComponentTypeParamDirective.Directive); | ||
// Constrained type parameters are only supported in Razor language versions v6.0 | ||
var razorLanguageVersion = codeDocument.GetParserOptions()?.Version ?? RazorLanguageVersion.Latest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't we want to assume lowest version instead of highest if there isn't one specified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, the only scenario where it is undefined is in some test cases for this pass that don't fully configure the Assuming this happens to a user, I think it also makes sense to default to the latest since the constrained type param directive can still support unconstrained scenarios. |
||
var directiveType = razorLanguageVersion.CompareTo(RazorLanguageVersion.Version_6_0) >= 0 | ||
? ComponentConstrainedTypeParamDirective.Directive | ||
: ComponentTypeParamDirective.Directive; | ||
var typeParamReferences = documentNode.FindDirectiveReferences(directiveType); | ||
for (var i = 0; i < typeParamReferences.Count; i++) | ||
{ | ||
var typeParamNode = (DirectiveIntermediateNode)typeParamReferences[i].Node; | ||
|
Uh oh!
There was an error while loading. Please reload this page.