22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
5+ using System . Collections . Frozen ;
56using System . Collections . Generic ;
6- using System . Collections . Immutable ;
77using System . Runtime . CompilerServices ;
88using Microsoft . AspNetCore . Razor . Language . Syntax ;
99
@@ -25,44 +25,38 @@ private class SpanData
2525 /// </summary>
2626 private static readonly ConditionalWeakTable < SyntaxNode , SpanData > s_spanDataTable = new ( ) ;
2727
28- private static readonly ImmutableHashSet < SyntaxKind > s_transitionSpanKinds = ImmutableHashSet . Create (
28+ private static readonly FrozenSet < SyntaxKind > s_transitionSpanKinds = FrozenSet . Create (
2929 SyntaxKind . CSharpTransition ,
3030 SyntaxKind . MarkupTransition ) ;
3131
32- private static readonly ImmutableHashSet < SyntaxKind > s_metaCodeSpanKinds = ImmutableHashSet . Create (
33- SyntaxKind . RazorMetaCode ) ;
34-
35- private static readonly ImmutableHashSet < SyntaxKind > s_commentSpanKinds = ImmutableHashSet . Create (
32+ private static readonly FrozenSet < SyntaxKind > s_commentSpanKinds = FrozenSet . Create (
3633 SyntaxKind . RazorCommentTransition ,
3734 SyntaxKind . RazorCommentStar ,
3835 SyntaxKind . RazorCommentLiteral ) ;
3936
40- private static readonly ImmutableHashSet < SyntaxKind > s_codeSpanKinds = ImmutableHashSet . Create (
37+ private static readonly FrozenSet < SyntaxKind > s_codeSpanKinds = FrozenSet . Create (
4138 SyntaxKind . CSharpStatementLiteral ,
4239 SyntaxKind . CSharpExpressionLiteral ,
4340 SyntaxKind . CSharpEphemeralTextLiteral ) ;
4441
45- private static readonly ImmutableHashSet < SyntaxKind > s_markupSpanKinds = ImmutableHashSet . Create (
42+ private static readonly FrozenSet < SyntaxKind > s_markupSpanKinds = FrozenSet . Create (
4643 SyntaxKind . MarkupTextLiteral ,
4744 SyntaxKind . MarkupEphemeralTextLiteral ) ;
4845
49- private static readonly ImmutableHashSet < SyntaxKind > s_noneSpanKinds = ImmutableHashSet . Create (
50- SyntaxKind . UnclassifiedTextLiteral ) ;
51-
52- private static readonly ImmutableHashSet < SyntaxKind > s_allSpanKinds = CreateAllSpanKindsSet ( ) ;
46+ private static readonly FrozenSet < SyntaxKind > s_allSpanKinds = CreateAllSpanKindsSet ( ) ;
5347
54- private static ImmutableHashSet < SyntaxKind > CreateAllSpanKindsSet ( )
48+ private static FrozenSet < SyntaxKind > CreateAllSpanKindsSet ( )
5549 {
56- var set = ImmutableHashSet < SyntaxKind > . Empty . ToBuilder ( ) ;
50+ var set = new HashSet < SyntaxKind > ( ) ;
5751
5852 set . UnionWith ( s_transitionSpanKinds ) ;
59- set . UnionWith ( s_metaCodeSpanKinds ) ;
53+ set . Add ( SyntaxKind . RazorMetaCode ) ;
6054 set . UnionWith ( s_commentSpanKinds ) ;
6155 set . UnionWith ( s_codeSpanKinds ) ;
6256 set . UnionWith ( s_markupSpanKinds ) ;
63- set . UnionWith ( s_noneSpanKinds ) ;
57+ set . Add ( SyntaxKind . UnclassifiedTextLiteral ) ;
6458
65- return set . ToImmutable ( ) ;
59+ return set . ToFrozenSet ( ) ;
6660 }
6761
6862 internal static ISpanChunkGenerator ? GetChunkGenerator ( this SyntaxNode node )
@@ -141,16 +135,14 @@ public static bool IsTransitionSpanKind(this SyntaxNode node)
141135
142136 public static bool IsMetaCodeSpanKind ( this SyntaxNodeOrToken nodeOrToken )
143137 {
144- ArgHelper . ThrowIfNull ( nodeOrToken ) ;
145-
146- return s_metaCodeSpanKinds . Contains ( nodeOrToken . Kind ) ;
138+ return nodeOrToken . AsNode ( out var node ) && node . IsMetaCodeSpanKind ( ) ;
147139 }
148140
149141 public static bool IsMetaCodeSpanKind ( this SyntaxNode node )
150142 {
151143 ArgHelper . ThrowIfNull ( node ) ;
152144
153- return s_metaCodeSpanKinds . Contains ( node . Kind ) ;
145+ return node . Kind is SyntaxKind . RazorMetaCode ;
154146 }
155147
156148 public static bool IsCommentSpanKind ( this SyntaxNode node )
@@ -178,7 +170,7 @@ public static bool IsNoneSpanKind(this SyntaxNode node)
178170 {
179171 ArgHelper . ThrowIfNull ( node ) ;
180172
181- return s_noneSpanKinds . Contains ( node . Kind ) ;
173+ return node . Kind is SyntaxKind . UnclassifiedTextLiteral ;
182174 }
183175
184176 public static bool IsSpanKind ( this SyntaxNode node )
0 commit comments