Remove support for includes
I was mistaken, this isn't a feature we will need for _ViewStart.
This commit is contained in:
parent
ea21469c11
commit
be10bb5f7b
|
|
@ -11,8 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
{
|
||||
public DefaultRazorCodeDocument(
|
||||
RazorSourceDocument source,
|
||||
IEnumerable<RazorSourceDocument> imports,
|
||||
IEnumerable<RazorSourceDocument> includes)
|
||||
IEnumerable<RazorSourceDocument> imports)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
|
@ -21,15 +20,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
|
||||
Source = source;
|
||||
Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray;
|
||||
Includes = includes?.ToArray() ?? RazorSourceDocument.EmptyArray;
|
||||
|
||||
Items = new DefaultItemCollection();
|
||||
}
|
||||
|
||||
public override IReadOnlyList<RazorSourceDocument> Imports { get; }
|
||||
|
||||
public override IReadOnlyList<RazorSourceDocument> Includes { get; }
|
||||
|
||||
public override ItemCollection Items { get; }
|
||||
|
||||
public override RazorSourceDocument Source { get; }
|
||||
|
|
|
|||
|
|
@ -31,13 +31,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
importSyntaxTrees[i] = RazorSyntaxTree.Parse(codeDocument.Imports[i], options);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,28 +15,25 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return Create(source, imports: null, includes: null);
|
||||
return Create(source, imports: null);
|
||||
}
|
||||
|
||||
public static RazorCodeDocument Create(
|
||||
RazorSourceDocument source,
|
||||
IEnumerable<RazorSourceDocument> imports,
|
||||
IEnumerable<RazorSourceDocument> includes)
|
||||
IEnumerable<RazorSourceDocument> imports)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return new DefaultRazorCodeDocument(source, imports, includes);
|
||||
return new DefaultRazorCodeDocument(source, imports);
|
||||
}
|
||||
|
||||
public abstract IReadOnlyList<RazorSourceDocument> Imports { get; }
|
||||
|
||||
public abstract ItemCollection Items { get; }
|
||||
|
||||
public abstract IReadOnlyList<RazorSourceDocument> Includes { get; }
|
||||
|
||||
public abstract RazorSourceDocument Source { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,26 +49,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
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)
|
||||
{
|
||||
if (document == null)
|
||||
|
|
|
|||
|
|
@ -17,14 +17,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
{
|
||||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
var includes = new RazorSourceDocument[]
|
||||
{
|
||||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
|
||||
// Act
|
||||
var code = new DefaultRazorCodeDocument(source, imports, includes);
|
||||
var code = new DefaultRazorCodeDocument(source, imports);
|
||||
|
||||
// Assert
|
||||
Assert.Same(source, code.Source);
|
||||
|
|
@ -32,25 +27,21 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
|
||||
Assert.NotSame(imports, code.Imports);
|
||||
Assert.Collection(imports, d => Assert.Same(imports[0], d));
|
||||
|
||||
Assert.NotSame(includes, code.Includes);
|
||||
Assert.Collection(includes, d => Assert.Same(includes[0], d));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_AllowsNullForImportsAndIncludes()
|
||||
public void Ctor_AllowsNullForImports()
|
||||
{
|
||||
// Arrange
|
||||
var source = TestRazorSourceDocument.Create();
|
||||
|
||||
// Act
|
||||
var code = new DefaultRazorCodeDocument(source, imports: null, includes: null);
|
||||
var code = new DefaultRazorCodeDocument(source, imports: null);
|
||||
|
||||
// Assert
|
||||
Assert.Same(source, code.Source);
|
||||
Assert.NotNull(code.Items);
|
||||
Assert.Empty(code.Imports);
|
||||
Assert.Empty(code.Includes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ParsesIncludesAndImports()
|
||||
public void Execute_ParsesImports()
|
||||
{
|
||||
// Arrange
|
||||
var phase = new DefaultRazorParsingPhase();
|
||||
|
|
@ -63,13 +63,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
var includes = new[]
|
||||
{
|
||||
TestRazorSourceDocument.Create(),
|
||||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
var codeDocument = TestRazorCodeDocument.Create(TestRazorSourceDocument.Create(), imports, includes);
|
||||
var codeDocument = TestRazorCodeDocument.Create(TestRazorSourceDocument.Create(), imports);
|
||||
|
||||
// Act
|
||||
phase.Execute(codeDocument);
|
||||
|
|
@ -79,11 +73,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
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[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
|
||||
|
|
|
|||
|
|
@ -55,22 +55,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
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]
|
||||
public void GetIRDocument_ReturnsIRDocument()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithImportsAndIncludes()
|
||||
public void Create_WithImports()
|
||||
{
|
||||
// Arrange
|
||||
var source = TestRazorSourceDocument.Create();
|
||||
|
|
@ -32,13 +32,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
var includes = new RazorSourceDocument[]
|
||||
{
|
||||
TestRazorSourceDocument.Create(),
|
||||
};
|
||||
|
||||
// Act
|
||||
var code = RazorCodeDocument.Create(source, imports, includes);
|
||||
var code = RazorCodeDocument.Create(source, imports);
|
||||
|
||||
// Assert
|
||||
Assert.Same(source, code.Source);
|
||||
|
|
@ -46,25 +41,21 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
|
||||
Assert.NotSame(imports, code.Imports);
|
||||
Assert.Collection(imports, d => Assert.Same(imports[0], d));
|
||||
|
||||
Assert.NotSame(includes, code.Includes);
|
||||
Assert.Collection(includes, d => Assert.Same(includes[0], d));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithImportsAndIncludes_AllsNull()
|
||||
public void Create_WithImports_AllowsNull()
|
||||
{
|
||||
// Arrange
|
||||
var source = TestRazorSourceDocument.Create();
|
||||
|
||||
// Act
|
||||
var code = RazorCodeDocument.Create(source, imports: null, includes: null);
|
||||
var code = RazorCodeDocument.Create(source, imports: null);
|
||||
|
||||
// Assert
|
||||
Assert.Same(source, code.Source);
|
||||
Assert.NotNull(code.Items);
|
||||
Assert.Empty(code.Imports);
|
||||
Assert.Empty(code.Includes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,20 +10,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
public static TestRazorCodeDocument CreateEmpty()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var source = TestRazorSourceDocument.Create(content);
|
||||
return new TestRazorCodeDocument(source, imports: null, includes: null);
|
||||
return new TestRazorCodeDocument(source, imports: null);
|
||||
}
|
||||
|
||||
private TestRazorCodeDocument(
|
||||
RazorSourceDocument source,
|
||||
IEnumerable<RazorSourceDocument> imports,
|
||||
IEnumerable<RazorSourceDocument> includes)
|
||||
: base(source, imports, includes)
|
||||
IEnumerable<RazorSourceDocument> imports)
|
||||
: base(source, imports)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue