Remove literal directive tokens.
- Literal directive tokens acted as a way for a user to provide markup bits to be required when parsing a directive. - Removed source implementations. - Removed tests validating the feature. #969
This commit is contained in:
parent
a801a49377
commit
3f5d1bb2d6
|
|
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
const string TypeHelper = "__typeHelper";
|
const string TypeHelper = "__typeHelper";
|
||||||
|
|
||||||
var tokenKind = node.Descriptor.Kind;
|
var tokenKind = node.Descriptor.Kind;
|
||||||
if (node.Source == null || node.Descriptor.Kind == DirectiveTokenKind.Literal)
|
if (node.Source == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,18 +68,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDirectiveDescriptorBuilder AddLiteral(string literal)
|
|
||||||
{
|
|
||||||
var descriptor = new DirectiveTokenDescriptor()
|
|
||||||
{
|
|
||||||
Kind = DirectiveTokenKind.Literal,
|
|
||||||
Value = literal,
|
|
||||||
};
|
|
||||||
_tokenDescriptors.Add(descriptor);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirectiveDescriptor Build()
|
public DirectiveDescriptor Build()
|
||||||
{
|
{
|
||||||
var descriptor = new DirectiveDescriptor
|
var descriptor = new DirectiveDescriptor
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
public class DirectiveTokenDescriptor
|
public class DirectiveTokenDescriptor
|
||||||
{
|
{
|
||||||
public DirectiveTokenKind Kind { get; set; }
|
public DirectiveTokenKind Kind { get; set; }
|
||||||
|
|
||||||
public string Value { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
}
|
}
|
||||||
|
|
||||||
return descriptorX != null &&
|
return descriptorX != null &&
|
||||||
string.Equals(descriptorX.Value, descriptorY.Value, StringComparison.Ordinal) &&
|
|
||||||
descriptorX.Kind == descriptorY.Kind;
|
descriptorX.Kind == descriptorY.Kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,11 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
throw new ArgumentNullException(nameof(descriptor));
|
throw new ArgumentNullException(nameof(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
var hashCodeCombiner = HashCodeCombiner.Start();
|
return descriptor.Kind.GetHashCode();
|
||||||
hashCodeCombiner.Add(descriptor.Value, StringComparer.Ordinal);
|
|
||||||
hashCodeCombiner.Add(descriptor.Kind);
|
|
||||||
|
|
||||||
return hashCodeCombiner.CombinedHash;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
Type,
|
Type,
|
||||||
Member,
|
Member,
|
||||||
String,
|
String,
|
||||||
Literal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
IDirectiveDescriptorBuilder AddString();
|
IDirectiveDescriptorBuilder AddString();
|
||||||
|
|
||||||
IDirectiveDescriptorBuilder AddLiteral(string literal);
|
|
||||||
|
|
||||||
DirectiveDescriptor Build();
|
DirectiveDescriptor Build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1551,20 +1551,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
case DirectiveTokenKind.String:
|
case DirectiveTokenKind.String:
|
||||||
AcceptAndMoveNext();
|
AcceptAndMoveNext();
|
||||||
break;
|
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);
|
Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor);
|
||||||
|
|
|
||||||
|
|
@ -79,21 +79,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
Assert.Equal(DirectiveTokenKind.String, token.Kind);
|
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]
|
[Fact]
|
||||||
public void AddX_MaintainsMultipleTokens()
|
public void AddX_MaintainsMultipleTokens()
|
||||||
{
|
{
|
||||||
|
|
@ -105,19 +90,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
.AddType()
|
.AddType()
|
||||||
.AddMember()
|
.AddMember()
|
||||||
.AddString()
|
.AddString()
|
||||||
.AddLiteral(",")
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(descriptor.Tokens,
|
Assert.Collection(descriptor.Tokens,
|
||||||
token => Assert.Equal(DirectiveTokenKind.Type, token.Kind),
|
token => Assert.Equal(DirectiveTokenKind.Type, token.Kind),
|
||||||
token => Assert.Equal(DirectiveTokenKind.Member, token.Kind),
|
token => Assert.Equal(DirectiveTokenKind.Member, token.Kind),
|
||||||
token => Assert.Equal(DirectiveTokenKind.String, token.Kind),
|
token => Assert.Equal(DirectiveTokenKind.String, token.Kind));
|
||||||
token =>
|
|
||||||
{
|
|
||||||
Assert.Equal(DirectiveTokenKind.Literal, token.Kind);
|
|
||||||
Assert.Equal(",", token.Value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,26 +70,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
.Accepts(AcceptedCharacters.NonWhiteSpace)));
|
.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]
|
[Fact]
|
||||||
public void DirectiveDescriptor_UnderstandsMultipleTokens()
|
public void DirectiveDescriptor_UnderstandsMultipleTokens()
|
||||||
{
|
{
|
||||||
|
|
@ -98,12 +78,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
.AddType()
|
.AddType()
|
||||||
.AddMember()
|
.AddMember()
|
||||||
.AddString()
|
.AddString()
|
||||||
.AddLiteral("!")
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
ParseCodeBlockTest(
|
ParseCodeBlockTest(
|
||||||
"@custom System.Text.Encoding.ASCIIEncoding Some_Member AString !",
|
"@custom System.Text.Encoding.ASCIIEncoding Some_Member AString",
|
||||||
new[] { descriptor },
|
new[] { descriptor },
|
||||||
new DirectiveBlock(
|
new DirectiveBlock(
|
||||||
new DirectiveChunkGenerator(descriptor),
|
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, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace),
|
||||||
Factory.Span(SpanKind.Markup, "AString", markup: false)
|
Factory.Span(SpanKind.Markup, "AString", markup: false)
|
||||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[2]))
|
.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)));
|
.Accepts(AcceptedCharacters.NonWhiteSpace)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,28 +218,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
expectedErorr);
|
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]
|
[Fact]
|
||||||
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
|
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue