This commit is contained in:
Ryan Nowak 2017-05-08 09:21:50 -07:00
Родитель 1705888721
Коммит a570139b08
6 изменённых файлов: 22 добавлений и 49 удалений

Просмотреть файл

@ -17,6 +17,9 @@ namespace Microsoft.AspNetCore.Razor.Language
var syntaxTree = codeDocument.GetSyntaxTree();
ThrowForMissingDependency(syntaxTree);
// This might not have been set if there are no tag helpers.
var tagHelperContext = codeDocument.GetTagHelperContext();
var builder = RazorIRBuilder.Document();
var document = (DocumentIRNode)builder.Current;
@ -46,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language
}
}
var tagHelperPrefix = codeDocument.GetTagHelperPrefix();
var tagHelperPrefix = tagHelperContext?.Prefix;
var visitor = new MainSourceVisitor(document, builder, namespaces, tagHelperPrefix)
{
FileName = syntaxTree.Source.FileName,

Просмотреть файл

@ -31,26 +31,6 @@ namespace Microsoft.AspNetCore.Razor.Language
document.Items[typeof(TagHelperDocumentContext)] = context;
}
public static string GetTagHelperPrefix(this RazorCodeDocument document)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
return document.Items[TagHelperPrefixKey] as string;
}
public static void SetTagHelperPrefix(this RazorCodeDocument document, string tagHelperPrefix)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
document.Items[TagHelperPrefixKey] = tagHelperPrefix;
}
public static RazorSyntaxTree GetSyntaxTree(this RazorCodeDocument document)
{
if (document == null)

Просмотреть файл

@ -106,7 +106,6 @@ namespace Microsoft.AspNetCore.Razor.Language
if (!string.IsNullOrEmpty(prefix))
{
codeDocument.SetTagHelperPrefix(prefixDirective.DirectiveText);
return prefixDirective.DirectiveText;
}

Просмотреть файл

@ -691,7 +691,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void BasicTagHelpers_Prefixed_Runtime()
{
// Arrange, Act & Assert
RunRuntimeTagHelpersTest(TestTagHelperDescriptors.DefaultPAndInputTagHelperDescriptors, tagHelperPrefix: "THS");
RunRuntimeTagHelpersTest(TestTagHelperDescriptors.DefaultPAndInputTagHelperDescriptors);
}
[Fact]
@ -1535,7 +1535,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void BasicTagHelpers_Prefixed_DesignTime()
{
// Arrange, Act & Assert
RunDesignTimeTagHelpersTest(TestTagHelperDescriptors.DefaultPAndInputTagHelperDescriptors, tagHelperPrefix: "THS");
RunDesignTimeTagHelpersTest(TestTagHelperDescriptors.DefaultPAndInputTagHelperDescriptors);
}
[Fact]
@ -1630,20 +1630,16 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
}
#endregion
private void RunRuntimeTagHelpersTest(IEnumerable<TagHelperDescriptor> descriptors, string tagHelperPrefix = null)
private void RunRuntimeTagHelpersTest(IEnumerable<TagHelperDescriptor> descriptors)
{
// Arrange
var engine = RazorEngine.Create(
builder =>
{
builder.Features.Add(new ApiSetsIRTestAdapter());
builder.AddTagHelpers(descriptors);
});
var document = CreateCodeDocument();
if (tagHelperPrefix != null)
var engine = RazorEngine.Create(builder =>
{
document.SetTagHelperPrefix(tagHelperPrefix);
}
builder.Features.Add(new ApiSetsIRTestAdapter());
builder.AddTagHelpers(descriptors);
});
var document = CreateCodeDocument();
// Act
engine.Process(document);
@ -1653,20 +1649,16 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
}
private void RunDesignTimeTagHelpersTest(IEnumerable<TagHelperDescriptor> descriptors, string tagHelperPrefix = null)
private void RunDesignTimeTagHelpersTest(IEnumerable<TagHelperDescriptor> descriptors)
{
// Arrange
var engine = RazorEngine.CreateDesignTime(
builder =>
{
builder.Features.Add(new ApiSetsIRTestAdapter());
builder.AddTagHelpers(descriptors);
});
var document = CreateCodeDocument();
if (tagHelperPrefix != null)
var engine = RazorEngine.CreateDesignTime(builder =>
{
document.SetTagHelperPrefix(tagHelperPrefix);
}
builder.Features.Add(new ApiSetsIRTestAdapter());
builder.AddTagHelpers(descriptors);
});
var document = CreateCodeDocument();
// Act
engine.Process(document);

Просмотреть файл

@ -877,7 +877,7 @@ namespace Microsoft.AspNetCore.Razor.Language
[Theory]
[MemberData(nameof(ProcessTagHelperPrefixData))]
public void ProcessTagHelperPrefix_ParsesPrefixFromDirectives_SetsOnCodeDocument(
public void ProcessTagHelperPrefix_ParsesPrefixFromDirectives(
object directiveDescriptors,
string expectedPrefix)
{
@ -892,7 +892,6 @@ namespace Microsoft.AspNetCore.Razor.Language
// Assert
Assert.Empty(errorSink.Errors);
Assert.Equal(expectedPrefix, prefix);
Assert.Equal(expectedPrefix, document.GetTagHelperPrefix());
}
public static TheoryData ProcessDirectivesData

Просмотреть файл

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Performance
{
public CodeGenerationBenchmark()
{
var current = new DirectoryInfo(Environment.CurrentDirectory);
var current = new DirectoryInfo(AppContext.BaseDirectory);
while (current != null && !File.Exists(Path.Combine(current.FullName, "MSN.cshtml")))
{
current = current.Parent;