Remove support for includes

I was mistaken, this isn't a feature we will need for _ViewStart.
This commit is contained in:
Ryan Nowak 2017-01-18 09:08:50 -08:00
parent ea21469c11
commit be10bb5f7b
9 changed files with 18 additions and 98 deletions

View File

@ -11,8 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{ {
public DefaultRazorCodeDocument( public DefaultRazorCodeDocument(
RazorSourceDocument source, RazorSourceDocument source,
IEnumerable<RazorSourceDocument> imports, IEnumerable<RazorSourceDocument> imports)
IEnumerable<RazorSourceDocument> includes)
{ {
if (source == null) if (source == null)
{ {
@ -21,15 +20,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Source = source; Source = source;
Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray; Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray;
Includes = includes?.ToArray() ?? RazorSourceDocument.EmptyArray;
Items = new DefaultItemCollection(); Items = new DefaultItemCollection();
} }
public override IReadOnlyList<RazorSourceDocument> Imports { get; } public override IReadOnlyList<RazorSourceDocument> Imports { get; }
public override IReadOnlyList<RazorSourceDocument> Includes { get; }
public override ItemCollection Items { get; } public override ItemCollection Items { get; }
public override RazorSourceDocument Source { get; } public override RazorSourceDocument Source { get; }

View File

@ -31,13 +31,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
importSyntaxTrees[i] = RazorSyntaxTree.Parse(codeDocument.Imports[i], options); importSyntaxTrees[i] = RazorSyntaxTree.Parse(codeDocument.Imports[i], options);
} }
codeDocument.SetImportSyntaxTrees(importSyntaxTrees); codeDocument.SetImportSyntaxTrees(importSyntaxTrees);
var includeSyntaxTrees = new RazorSyntaxTree[codeDocument.Includes.Count];
for (var i = 0; i < codeDocument.Includes.Count; i++)
{
includeSyntaxTrees[i] = RazorSyntaxTree.Parse(codeDocument.Includes[i], options);
}
codeDocument.SetIncludeSyntaxTrees(includeSyntaxTrees);
} }
} }
} }

View File

@ -15,28 +15,25 @@ namespace Microsoft.AspNetCore.Razor.Evolution
throw new ArgumentNullException(nameof(source)); throw new ArgumentNullException(nameof(source));
} }
return Create(source, imports: null, includes: null); return Create(source, imports: null);
} }
public static RazorCodeDocument Create( public static RazorCodeDocument Create(
RazorSourceDocument source, RazorSourceDocument source,
IEnumerable<RazorSourceDocument> imports, IEnumerable<RazorSourceDocument> imports)
IEnumerable<RazorSourceDocument> includes)
{ {
if (source == null) if (source == null)
{ {
throw new ArgumentNullException(nameof(source)); throw new ArgumentNullException(nameof(source));
} }
return new DefaultRazorCodeDocument(source, imports, includes); return new DefaultRazorCodeDocument(source, imports);
} }
public abstract IReadOnlyList<RazorSourceDocument> Imports { get; } public abstract IReadOnlyList<RazorSourceDocument> Imports { get; }
public abstract ItemCollection Items { get; } public abstract ItemCollection Items { get; }
public abstract IReadOnlyList<RazorSourceDocument> Includes { get; }
public abstract RazorSourceDocument Source { get; } public abstract RazorSourceDocument Source { get; }
} }
} }

View File

@ -49,26 +49,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
document.Items[typeof(ImportSyntaxTreesHolder)] = new ImportSyntaxTreesHolder(syntaxTrees); document.Items[typeof(ImportSyntaxTreesHolder)] = new ImportSyntaxTreesHolder(syntaxTrees);
} }
public static IReadOnlyList<RazorSyntaxTree> GetIncludeSyntaxTrees(this RazorCodeDocument document)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
return (document.Items[typeof(IncludeSyntaxTreesHolder)] as IncludeSyntaxTreesHolder)?.SyntaxTrees;
}
public static void SetIncludeSyntaxTrees(this RazorCodeDocument document, IReadOnlyList<RazorSyntaxTree> syntaxTrees)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
document.Items[typeof(IncludeSyntaxTreesHolder)] = new IncludeSyntaxTreesHolder(syntaxTrees);
}
public static DocumentIRNode GetIRDocument(this RazorCodeDocument document) public static DocumentIRNode GetIRDocument(this RazorCodeDocument document)
{ {
if (document == null) if (document == null)

View File

@ -18,13 +18,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
TestRazorSourceDocument.Create(), TestRazorSourceDocument.Create(),
}; };
var includes = new RazorSourceDocument[]
{
TestRazorSourceDocument.Create(),
};
// Act // Act
var code = new DefaultRazorCodeDocument(source, imports, includes); var code = new DefaultRazorCodeDocument(source, imports);
// Assert // Assert
Assert.Same(source, code.Source); Assert.Same(source, code.Source);
@ -32,25 +27,21 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.NotSame(imports, code.Imports); Assert.NotSame(imports, code.Imports);
Assert.Collection(imports, d => Assert.Same(imports[0], d)); Assert.Collection(imports, d => Assert.Same(imports[0], d));
Assert.NotSame(includes, code.Includes);
Assert.Collection(includes, d => Assert.Same(includes[0], d));
} }
[Fact] [Fact]
public void Ctor_AllowsNullForImportsAndIncludes() public void Ctor_AllowsNullForImports()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create(); var source = TestRazorSourceDocument.Create();
// Act // Act
var code = new DefaultRazorCodeDocument(source, imports: null, includes: null); var code = new DefaultRazorCodeDocument(source, imports: null);
// Assert // Assert
Assert.Same(source, code.Source); Assert.Same(source, code.Source);
Assert.NotNull(code.Items); Assert.NotNull(code.Items);
Assert.Empty(code.Imports); Assert.Empty(code.Imports);
Assert.Empty(code.Includes);
} }
} }
} }

View File

@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
} }
[Fact] [Fact]
public void Execute_ParsesIncludesAndImports() public void Execute_ParsesImports()
{ {
// Arrange // Arrange
var phase = new DefaultRazorParsingPhase(); var phase = new DefaultRazorParsingPhase();
@ -63,13 +63,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
TestRazorSourceDocument.Create(), TestRazorSourceDocument.Create(),
}; };
var includes = new[] var codeDocument = TestRazorCodeDocument.Create(TestRazorSourceDocument.Create(), imports);
{
TestRazorSourceDocument.Create(),
TestRazorSourceDocument.Create(),
};
var codeDocument = TestRazorCodeDocument.Create(TestRazorSourceDocument.Create(), imports, includes);
// Act // Act
phase.Execute(codeDocument); phase.Execute(codeDocument);
@ -79,11 +73,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
codeDocument.GetImportSyntaxTrees(), codeDocument.GetImportSyntaxTrees(),
t => { Assert.Same(t.Source, imports[0]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); }, t => { Assert.Same(t.Source, imports[0]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); },
t => { Assert.Same(t.Source, imports[1]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); }); t => { Assert.Same(t.Source, imports[1]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); });
Assert.Collection(
codeDocument.GetIncludeSyntaxTrees(),
t => { Assert.Same(t.Source, includes[0]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); },
t => { Assert.Same(t.Source, includes[1]); Assert.Equal("test_directive", Assert.Single(t.Options.Directives).Name); });
} }
private class MyConfigureParserOptions : IRazorConfigureParserFeature private class MyConfigureParserOptions : IRazorConfigureParserFeature

View File

@ -55,22 +55,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.Same(expected, actual); Assert.Same(expected, actual);
} }
[Fact]
public void GetAndSetIncludeSyntaxTrees_ReturnsSyntaxTrees()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var expected = new[] { RazorSyntaxTree.Parse(codeDocument.Source), };
codeDocument.SetIncludeSyntaxTrees(expected);
// Act
var actual = codeDocument.GetIncludeSyntaxTrees();
// Assert
Assert.Same(expected, actual);
}
[Fact] [Fact]
public void GetIRDocument_ReturnsIRDocument() public void GetIRDocument_ReturnsIRDocument()
{ {

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
} }
[Fact] [Fact]
public void Create_WithImportsAndIncludes() public void Create_WithImports()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create(); var source = TestRazorSourceDocument.Create();
@ -32,13 +32,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
TestRazorSourceDocument.Create(), TestRazorSourceDocument.Create(),
}; };
var includes = new RazorSourceDocument[]
{
TestRazorSourceDocument.Create(),
};
// Act // Act
var code = RazorCodeDocument.Create(source, imports, includes); var code = RazorCodeDocument.Create(source, imports);
// Assert // Assert
Assert.Same(source, code.Source); Assert.Same(source, code.Source);
@ -46,25 +41,21 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.NotSame(imports, code.Imports); Assert.NotSame(imports, code.Imports);
Assert.Collection(imports, d => Assert.Same(imports[0], d)); Assert.Collection(imports, d => Assert.Same(imports[0], d));
Assert.NotSame(includes, code.Includes);
Assert.Collection(includes, d => Assert.Same(includes[0], d));
} }
[Fact] [Fact]
public void Create_WithImportsAndIncludes_AllsNull() public void Create_WithImports_AllowsNull()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create(); var source = TestRazorSourceDocument.Create();
// Act // Act
var code = RazorCodeDocument.Create(source, imports: null, includes: null); var code = RazorCodeDocument.Create(source, imports: null);
// Assert // Assert
Assert.Same(source, code.Source); Assert.Same(source, code.Source);
Assert.NotNull(code.Items); Assert.NotNull(code.Items);
Assert.Empty(code.Imports); Assert.Empty(code.Imports);
Assert.Empty(code.Includes);
} }
} }
} }

View File

@ -10,20 +10,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public static TestRazorCodeDocument CreateEmpty() public static TestRazorCodeDocument CreateEmpty()
{ {
var source = TestRazorSourceDocument.Create(content: string.Empty); var source = TestRazorSourceDocument.Create(content: string.Empty);
return new TestRazorCodeDocument(source, imports: null, includes: null); return new TestRazorCodeDocument(source, imports: null);
} }
public static TestRazorCodeDocument Create(string content) public static TestRazorCodeDocument Create(string content)
{ {
var source = TestRazorSourceDocument.Create(content); var source = TestRazorSourceDocument.Create(content);
return new TestRazorCodeDocument(source, imports: null, includes: null); return new TestRazorCodeDocument(source, imports: null);
} }
private TestRazorCodeDocument( private TestRazorCodeDocument(
RazorSourceDocument source, RazorSourceDocument source,
IEnumerable<RazorSourceDocument> imports, IEnumerable<RazorSourceDocument> imports)
IEnumerable<RazorSourceDocument> includes) : base(source, imports)
: base(source, imports, includes)
{ {
} }
} }