parent
e14dbdf9be
commit
fbe331c1ab
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
|
|
@ -16,6 +17,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
|||
/// </summary>
|
||||
public class TagHelperDescriptorResolver : ITagHelperDescriptorResolver
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<TagHelperDirectiveType, string> _directiveNames =
|
||||
new Dictionary<TagHelperDirectiveType, string>
|
||||
{
|
||||
{ TagHelperDirectiveType.AddTagHelper, SyntaxConstants.CSharp.AddTagHelperKeyword },
|
||||
{ TagHelperDirectiveType.RemoveTagHelper, SyntaxConstants.CSharp.RemoveTagHelperKeyword },
|
||||
};
|
||||
|
||||
private readonly TagHelperTypeResolver _typeResolver;
|
||||
|
||||
// internal for testing
|
||||
|
|
@ -67,12 +75,14 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var directiveName = "@" + directiveDescriptor.DirectiveType.ToString().ToLowerInvariant();
|
||||
string directiveName;
|
||||
_directiveNames.TryGetValue(directiveDescriptor.DirectiveType, out directiveName);
|
||||
Debug.Assert(!string.IsNullOrEmpty(directiveName));
|
||||
|
||||
context.ErrorSink.OnError(
|
||||
directiveDescriptor.Location,
|
||||
Resources.FormatTagHelperDescriptorResolver_EncounteredUnexpectedError(
|
||||
directiveName,
|
||||
"@" + directiveName,
|
||||
directiveDescriptor.LookupText,
|
||||
ex.Message));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ namespace Microsoft.AspNet.Razor.Parser
|
|||
public static class CSharp
|
||||
{
|
||||
public static readonly int UsingKeywordLength = 5;
|
||||
public static readonly string AddTagHelperKeyword = "addtaghelper";
|
||||
public static readonly string RemoveTagHelperKeyword = "removetaghelper";
|
||||
public static readonly string AddTagHelperKeyword = "addTagHelper";
|
||||
public static readonly string RemoveTagHelperKeyword = "removeTagHelper";
|
||||
public static readonly string InheritsKeyword = "inherits";
|
||||
public static readonly string FunctionsKeyword = "functions";
|
||||
public static readonly string SectionKeyword = "section";
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ namespace Microsoft.AspNet.Razor.TagHelpers
|
|||
public enum TagHelperDirectiveType
|
||||
{
|
||||
/// <summary>
|
||||
/// An @addtaghelper directive.
|
||||
/// An @addTagHelper directive.
|
||||
/// </summary>
|
||||
AddTagHelper,
|
||||
|
||||
/// <summary>
|
||||
/// A @removetaghelper directive.
|
||||
/// A @removeTagHelper directive.
|
||||
/// </summary>
|
||||
RemoveTagHelper
|
||||
}
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
|||
{
|
||||
// Arrange
|
||||
var expectedErrorMessage = "Encountered an unexpected error when attempting to resolve tag helper " +
|
||||
"directive '@addtaghelper' with value 'A custom, lookup text'. Error: A " +
|
||||
"directive '@addTagHelper' with value 'A custom, lookup text'. Error: A " +
|
||||
"custom exception";
|
||||
var documentLocation = new SourceLocation(1, 2, 3);
|
||||
var directiveType = TagHelperDirectiveType.AddTagHelper;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
|||
{
|
||||
if (directiveDescriptor.DirectiveType == TagHelperDirectiveType.RemoveTagHelper)
|
||||
{
|
||||
// We don't yet support "typeName, assemblyName" for @removetaghelper in this test class. Will
|
||||
// We don't yet support "typeName, assemblyName" for @removeTagHelper in this test class. Will
|
||||
// add that ability and add the corresponding end-to-end test verification in:
|
||||
// https://github.com/aspnet/Razor/issues/222
|
||||
descriptors = null;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_Succeeds()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper \"Foo\"",
|
||||
ParseBlockTest("@removeTagHelper \"Foo\"",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_SupportsSpaces()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper \" Foo, Bar \" ",
|
||||
ParseBlockTest("@removeTagHelper \" Foo, Bar \" ",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_RequiresValue()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper ",
|
||||
ParseBlockTest("@removeTagHelper ",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_StartQuoteRequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper \"Foo",
|
||||
ParseBlockTest("@removeTagHelper \"Foo",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_EndQuoteRequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper Foo\"",
|
||||
ParseBlockTest("@removeTagHelper Foo\"",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void RemoveTagHelperDirective_RequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@removetaghelper Foo",
|
||||
ParseBlockTest("@removeTagHelper Foo",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ")
|
||||
|
|
@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirective_Succeeds()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper \"Foo\"",
|
||||
ParseBlockTest("@addTagHelper \"Foo\"",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirectiveSupportsSpaces()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper \" Foo, Bar \" ",
|
||||
ParseBlockTest("@addTagHelper \" Foo, Bar \" ",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirectiveRequiresValue()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper ",
|
||||
ParseBlockTest("@addTagHelper ",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
@ -139,7 +139,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirectiveWithStartQuoteRequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper \"Foo",
|
||||
ParseBlockTest("@addTagHelper \"Foo",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirectiveWithEndQuoteRequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper Foo\"",
|
||||
ParseBlockTest("@addTagHelper Foo\"",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|||
[Fact]
|
||||
public void AddTagHelperDirectiveRequiresDoubleQuotesAroundValue()
|
||||
{
|
||||
ParseBlockTest("@addtaghelper Foo",
|
||||
ParseBlockTest("@addTagHelper Foo",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15cf58241a278a7bfadfefa9ef44742b3fd1074e"
|
||||
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ef59308f8b0456ad2f49a08604e8ba36ca11a4b2"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "BasicTagHelpers.RemoveTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15609cf7c0bff12794453caa4d04e6f5a562e6ed"
|
||||
#pragma checksum "BasicTagHelpers.RemoveTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "48dc91408dc7bf6406139461afa4867d176adaf7"
|
||||
namespace TestOutput
|
||||
{
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "15cf58241a278a7bfadfefa9ef44742b3fd1074e"
|
||||
#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ef59308f8b0456ad2f49a08604e8ba36ca11a4b2"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "b7d9a4dd63a71dcfc8c97a5ee7598214e387e1b6"
|
||||
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "34039b21327142e9261c7acb3bcd0a4365e0cfa2"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "EmptyAttributeTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "828f744feb52d497814b7a018f817f31d92085ce"
|
||||
#pragma checksum "EmptyAttributeTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "20e2b8804c3af56e185a59be9d21ab33fb33774f"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "EscapedTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f1f93dcc77691cc626112fe0475f5c350e5fa802"
|
||||
#pragma checksum "EscapedTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "34a293044db8d18ae2c99fc1e4231e9e7ee96137"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "72db799463dab7865f759d0e3ed3660485d7871d"
|
||||
#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "60ad52f4a16ebc0499d729dfd4b79358331907f4"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "daf9e656da8fef546fe782b39687a5029a852c48"
|
||||
#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5f28fe84901bdeb20db8296b1da1e9a1f1da1023"
|
||||
namespace TestOutput
|
||||
{
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f7dda6348dbd0043f1421eacbbdce3d3c4f21d75"
|
||||
#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "f228c34bdcee3e7f64bc3de14469d11a61efb825"
|
||||
namespace TestOutput
|
||||
{
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
@addtaghelper "something, nice"
|
||||
@removetaghelper "doesntmatter, nice"
|
||||
@addTagHelper "something, nice"
|
||||
@removeTagHelper "doesntmatter, nice"
|
||||
|
||||
<div class="randomNonTagHelperAttribute">
|
||||
<p class="Hello World">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
||||
<div class="randomNonTagHelperAttribute">
|
||||
<p class="Hello World">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
||||
@if (true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something"
|
||||
@addTagHelper "something"
|
||||
|
||||
<div>
|
||||
<input type= checked=""class="" />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something"
|
||||
@addTagHelper "something"
|
||||
|
||||
<!div class="randomNonTagHelperAttribute">
|
||||
<!p class="Hello World" @DateTime.Now>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
@removetaghelper "something, nice"
|
||||
@removeTagHelper "something, nice"
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
||||
<p class="Hello World" age="1337">Body of Tag</p>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
||||
@helper MyHelper(string val)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@addtaghelper "something, nice"
|
||||
@addTagHelper "something, nice"
|
||||
|
||||
@{
|
||||
var code = "some code";
|
||||
|
|
|
|||
Loading…
Reference in New Issue