diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs index 8849039cbf..f5f3217e2e 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution const string TypeHelper = "__typeHelper"; var tokenKind = node.Descriptor.Kind; - if (node.Source == null || node.Descriptor.Kind == DirectiveTokenKind.Literal) + if (node.Source == null) { return; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveDescriptorBuilder.cs index d8d58e87d0..65d91d144d 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveDescriptorBuilder.cs @@ -68,18 +68,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution return this; } - public IDirectiveDescriptorBuilder AddLiteral(string literal) - { - var descriptor = new DirectiveTokenDescriptor() - { - Kind = DirectiveTokenKind.Literal, - Value = literal, - }; - _tokenDescriptors.Add(descriptor); - - return this; - } - public DirectiveDescriptor Build() { var descriptor = new DirectiveDescriptor diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptor.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptor.cs index fe06c94bb3..074f4003ea 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptor.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptor.cs @@ -6,7 +6,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution public class DirectiveTokenDescriptor { public DirectiveTokenKind Kind { get; set; } - - public string Value { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptorComparer.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptorComparer.cs index 1a2fe3a271..45a67ada3f 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptorComparer.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenDescriptorComparer.cs @@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution } return descriptorX != null && - string.Equals(descriptorX.Value, descriptorY.Value, StringComparison.Ordinal) && descriptorX.Kind == descriptorY.Kind; } @@ -34,11 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution throw new ArgumentNullException(nameof(descriptor)); } - var hashCodeCombiner = HashCodeCombiner.Start(); - hashCodeCombiner.Add(descriptor.Value, StringComparer.Ordinal); - hashCodeCombiner.Add(descriptor.Kind); - - return hashCodeCombiner.CombinedHash; + return descriptor.Kind.GetHashCode(); } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenKind.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenKind.cs index 0d52914806..f17bcc2057 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenKind.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DirectiveTokenKind.cs @@ -8,6 +8,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution Type, Member, String, - Literal } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/IDirectiveDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Evolution/IDirectiveDescriptorBuilder.cs index 8a537ca667..2fcab31c39 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/IDirectiveDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/IDirectiveDescriptorBuilder.cs @@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution IDirectiveDescriptorBuilder AddString(); - IDirectiveDescriptorBuilder AddLiteral(string literal); - DirectiveDescriptor Build(); } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeParser.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeParser.cs index 086fa5f3af..4524902dda 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeParser.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeParser.cs @@ -1551,20 +1551,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy case DirectiveTokenKind.String: AcceptAndMoveNext(); break; - case DirectiveTokenKind.Literal: - if (string.Equals(CurrentSymbol.Content, tokenDescriptor.Value, StringComparison.Ordinal)) - { - AcceptAndMoveNext(); - } - else - { - Context.ErrorSink.OnError( - CurrentStart, - LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Name, tokenDescriptor.Value), - CurrentSymbol.Content.Length); - return; - } - break; } Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DirectiveDescriptorBuilderTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DirectiveDescriptorBuilderTest.cs index 270d961649..5050e2297b 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DirectiveDescriptorBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DirectiveDescriptorBuilderTest.cs @@ -79,21 +79,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution Assert.Equal(DirectiveTokenKind.String, token.Kind); } - [Fact] - public void AddLiteral_AddsToken() - { - // Arrange - var builder = DirectiveDescriptorBuilder.Create("custom"); - - // Act - var descriptor = builder.AddLiteral(",").Build(); - - // Assert - var token = Assert.Single(descriptor.Tokens); - Assert.Equal(DirectiveTokenKind.Literal, token.Kind); - Assert.Equal(",", token.Value); - } - [Fact] public void AddX_MaintainsMultipleTokens() { @@ -105,19 +90,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution .AddType() .AddMember() .AddString() - .AddLiteral(",") .Build(); // Assert Assert.Collection(descriptor.Tokens, token => Assert.Equal(DirectiveTokenKind.Type, token.Kind), token => Assert.Equal(DirectiveTokenKind.Member, token.Kind), - token => Assert.Equal(DirectiveTokenKind.String, token.Kind), - token => - { - Assert.Equal(DirectiveTokenKind.Literal, token.Kind); - Assert.Equal(",", token.Value); - }); + token => Assert.Equal(DirectiveTokenKind.String, token.Kind)); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs index 596dd7abe4..08d1f8c64c 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs @@ -70,26 +70,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy .Accepts(AcceptedCharacters.NonWhiteSpace))); } - [Fact] - public void DirectiveDescriptor_UnderstandsLiteralTokens() - { - // Arrange - var descriptor = DirectiveDescriptorBuilder.Create("custom").AddLiteral("!").Build(); - - // Act & Assert - ParseCodeBlockTest( - "@custom !", - new[] { descriptor }, - new DirectiveBlock( - new DirectiveChunkGenerator(descriptor), - Factory.CodeTransition(), - Factory.MetaCode("custom").Accepts(AcceptedCharacters.None), - Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace), - Factory.Span(SpanKind.Markup, "!", markup: false) - .With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0])) - .Accepts(AcceptedCharacters.NonWhiteSpace))); - } - [Fact] public void DirectiveDescriptor_UnderstandsMultipleTokens() { @@ -98,12 +78,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy .AddType() .AddMember() .AddString() - .AddLiteral("!") .Build(); // Act & Assert ParseCodeBlockTest( - "@custom System.Text.Encoding.ASCIIEncoding Some_Member AString !", + "@custom System.Text.Encoding.ASCIIEncoding Some_Member AString", new[] { descriptor }, new DirectiveBlock( new DirectiveChunkGenerator(descriptor), @@ -123,11 +102,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace), Factory.Span(SpanKind.Markup, "AString", markup: false) .With(new DirectiveTokenChunkGenerator(descriptor.Tokens[2])) - .Accepts(AcceptedCharacters.NonWhiteSpace), - - Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace), - Factory.Span(SpanKind.Markup, "!", markup: false) - .With(new DirectiveTokenChunkGenerator(descriptor.Tokens[3])) .Accepts(AcceptedCharacters.NonWhiteSpace))); } @@ -244,28 +218,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy expectedErorr); } - [Fact] - public void DirectiveDescriptor_ErrorsForUnmatchedLiteralTokens() - { - // Arrange - var descriptor = DirectiveDescriptorBuilder.Create("custom").AddLiteral("!").Build(); - var expectedErorr = new RazorError( - LegacyResources.FormatUnexpectedDirectiveLiteral("custom", "!"), - new SourceLocation(8, 0, 8), - length: 2); - - // Act & Assert - ParseCodeBlockTest( - "@custom hi", - new[] { descriptor }, - new DirectiveBlock( - new DirectiveChunkGenerator(descriptor), - Factory.CodeTransition(), - Factory.MetaCode("custom").Accepts(AcceptedCharacters.None), - Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace)), - expectedErorr); - } - [Fact] public void DirectiveDescriptor_ErrorsExtraContentAfterDirective() {