Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Razor.Utilities;

namespace Microsoft.AspNetCore.Razor.Language.Components;

// Descriptor-level metadata that records a single element/attribute pair for which the runtime
Comment thread
chsienki marked this conversation as resolved.
Outdated
// has opted into '~/' asset-path expansion via [AcceptsAssetPath(element, attribute)].
public sealed record AssetPathMetadata() : MetadataObject(MetadataKind.AssetPath)
{
public required string Element { get; init; }
public required string Attribute { get; init; }

internal override bool HasDefaultValue => false;

private protected override void BuildChecksum(in Checksum.Builder builder)
{
builder.Append(Element);
builder.Append(Attribute);
}

public ref struct Builder
{
public string? Element { get; set; }
public string? Attribute { get; set; }

public readonly AssetPathMetadata Build()
=> new()
{
Element = Element.AssumeNotNull(),
Attribute = Attribute.AssumeNotNull(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class ComponentBase
public const string MetadataName = FullTypeName;

public const string BuildRenderTree = nameof(BuildRenderTree);
public const string Assets = nameof(Assets);
}

public static class ParameterAttribute
Expand Down Expand Up @@ -161,6 +162,22 @@ public static class EventHandlerAttribute
public const string FullTypeName = "Microsoft.AspNetCore.Components.EventHandlerAttribute";
}

public static class AssetPathAttribute
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.AssetPathAttribute";
public const string MetadataName = FullTypeName;
}

public static class AcceptsAssetPathAttribute
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.AcceptsAssetPathAttribute";
public const string MetadataName = FullTypeName;

// Name of the public type the runtime decorates with [AcceptsAssetPath] declarations;
// the compiler discovers it by name to build the asset-path allowlist.
public const string CandidateTypeName = "AssetPathAttributes";
}

public static class ElementReference
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.ElementReference";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed record PropertyMetadata() : MetadataObject(MetadataKind.Property)
public bool IsGenericTyped { get; init; }
public bool IsInitOnlyProperty { get; init; }
public bool AcceptsStringLiteral { get; init; }
public bool AcceptsAssetPath { get; init; }

internal override bool HasDefaultValue => Equals(Default);

Expand All @@ -30,6 +31,7 @@ private protected override void BuildChecksum(in Checksum.Builder builder)
builder.Append(IsGenericTyped);
builder.Append(IsInitOnlyProperty);
builder.Append(AcceptsStringLiteral);
builder.Append(AcceptsAssetPath);
}

public ref struct Builder
Expand All @@ -42,6 +44,7 @@ public ref struct Builder
public bool IsGenericTyped { get; set; }
public bool IsInitOnlyProperty { get; set; }
public bool AcceptsStringLiteral { get; set; }
public bool AcceptsAssetPath { get; set; }

public readonly PropertyMetadata Build()
=> new()
Expand All @@ -54,6 +57,7 @@ public readonly PropertyMetadata Build()
IsGenericTyped = IsGenericTyped,
IsInitOnlyProperty = IsInitOnlyProperty,
AcceptsStringLiteral = AcceptsStringLiteral,
AcceptsAssetPath = AcceptsAssetPath,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MetadataKind : byte
Bind,
Component,
EventHandler,
ViewComponent
ViewComponent,
AssetPath
}

public abstract record MetadataObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public enum TagHelperKind : byte
Ref,
Splat,
FormName,
RenderMode // Last component kind. If another is added, update TagHelperKindExtensions.IsAnyComponentKind.
RenderMode,
AssetPath // Last component kind. If another is added, update TagHelperKindExtensions.IsAnyComponentKind.
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class TagHelperKindExtensions
extension(TagHelperKind kind)
{
public bool IsAnyComponentKind
=> kind is >= TagHelperKind.Component and <= TagHelperKind.RenderMode;
=> kind is >= TagHelperKind.Component and <= TagHelperKind.AssetPath;

public bool IsComponentOrChildContentKind
=> kind is TagHelperKind.Component or TagHelperKind.ChildContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ internal enum TagHelperProducerKind : ushort
Splat,
MvcViewComponent,
Mvc1_X_ViewComponent,
Mvc2_X_ViewComponent
Mvc2_X_ViewComponent,
AcceptsAssetPath
}