React to change in Razor
This commit is contained in:
parent
b520b0cb22
commit
a65a6a7cab
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
// If there's more than 1 model chunk there will be a Razor error BUT we want intellisense to show up on
|
// If there's more than 1 model chunk there will be a Razor error BUT we want intellisense to show up on
|
||||||
// the current model chunk that the user is typing.
|
// the current model chunk that the user is typing.
|
||||||
return chunkTree
|
return chunkTree
|
||||||
.Chunks
|
.Children
|
||||||
.OfType<ModelChunk>()
|
.OfType<ModelChunk>()
|
||||||
.LastOrDefault();
|
.LastOrDefault();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
var chunkMergers = GetChunkMergers(chunkTree, defaultModel);
|
var chunkMergers = GetChunkMergers(chunkTree, defaultModel);
|
||||||
// We merge chunks into the ChunkTree in two passes. In the first pass, we traverse the ChunkTree visiting
|
// We merge chunks into the ChunkTree in two passes. In the first pass, we traverse the ChunkTree visiting
|
||||||
// a mapped IChunkMerger for types that are registered.
|
// a mapped IChunkMerger for types that are registered.
|
||||||
foreach (var chunk in chunkTree.Chunks)
|
foreach (var chunk in chunkTree.Children)
|
||||||
{
|
{
|
||||||
foreach (var merger in chunkMergers)
|
foreach (var merger in chunkMergers)
|
||||||
{
|
{
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
}
|
}
|
||||||
|
|
||||||
var inheritedChunks = _defaultInheritedChunks.Concat(
|
var inheritedChunks = _defaultInheritedChunks.Concat(
|
||||||
inheritedChunkTrees.SelectMany(tree => tree.Chunks)).ToArray();
|
inheritedChunkTrees.SelectMany(tree => tree.Children)).ToArray();
|
||||||
|
|
||||||
foreach (var merger in chunkMergers)
|
foreach (var merger in chunkMergers)
|
||||||
{
|
{
|
||||||
|
|
@ -175,8 +175,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
chunkGenerator.Visit(parseResults);
|
chunkGenerator.Visit(parseResults);
|
||||||
|
|
||||||
// Rewrite the location of inherited chunks so they point to the global import file.
|
// Rewrite the location of inherited chunks so they point to the global import file.
|
||||||
var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree;
|
var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.Root;
|
||||||
foreach (var chunk in chunkTree.Chunks)
|
foreach (var chunk in chunkTree.Children)
|
||||||
{
|
{
|
||||||
chunk.Start = new SourceLocation(
|
chunk.Start = new SourceLocation(
|
||||||
viewImportsPath,
|
viewImportsPath,
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
if (injectChunk != null &&
|
if (injectChunk != null &&
|
||||||
_addedMemberNames.Add(injectChunk.MemberName))
|
_addedMemberNames.Add(injectChunk.MemberName))
|
||||||
{
|
{
|
||||||
chunkTree.Chunks.Add(TransformChunk(injectChunk));
|
chunkTree.Children.Add(TransformChunk(injectChunk));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
var baseTypeChunk = inheritedChunks[i] as SetBaseTypeChunk;
|
var baseTypeChunk = inheritedChunks[i] as SetBaseTypeChunk;
|
||||||
if (baseTypeChunk != null)
|
if (baseTypeChunk != null)
|
||||||
{
|
{
|
||||||
chunkTree.Chunks.Add(TransformChunk(baseTypeChunk));
|
chunkTree.Children.Add(TransformChunk(baseTypeChunk));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
{
|
{
|
||||||
if (_currentUsings.Add(namespaceChunk.Namespace))
|
if (_currentUsings.Add(namespaceChunk.Namespace))
|
||||||
{
|
{
|
||||||
chunkTree.Chunks.Add(namespaceChunk);
|
chunkTree.Children.Add(namespaceChunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
writer.WriteLineHiddenDirective();
|
writer.WriteLineHiddenDirective();
|
||||||
|
|
||||||
var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
|
var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
|
||||||
injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);
|
injectVisitor.Accept(Context.ChunkTreeBuilder.Root.Children);
|
||||||
|
|
||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
writer.WriteLineHiddenDirective();
|
writer.WriteLineHiddenDirective();
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var inheritedChunkTrees = GetInheritedChunkTrees(context.SourceFile);
|
var inheritedChunkTrees = GetInheritedChunkTrees(context.SourceFile);
|
||||||
|
|
||||||
ChunkInheritanceUtility.MergeInheritedChunkTrees(
|
ChunkInheritanceUtility.MergeInheritedChunkTrees(
|
||||||
context.ChunkTreeBuilder.ChunkTree,
|
context.ChunkTreeBuilder.Root,
|
||||||
inheritedChunkTrees,
|
inheritedChunkTrees,
|
||||||
DefaultModel);
|
DefaultModel);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
var descriptors = new List<TagHelperDirectiveDescriptor>();
|
var descriptors = new List<TagHelperDirectiveDescriptor>();
|
||||||
|
|
||||||
var inheritedChunks = defaultInheritedChunks.Concat(inheritedChunkTrees.SelectMany(tree => tree.Chunks));
|
var inheritedChunks = defaultInheritedChunks.Concat(inheritedChunkTrees.SelectMany(tree => tree.Children));
|
||||||
foreach (var chunk in inheritedChunks)
|
foreach (var chunk in inheritedChunks)
|
||||||
{
|
{
|
||||||
// All TagHelperDirectiveDescriptors created here have undefined source locations because the source
|
// All TagHelperDirectiveDescriptors created here have undefined source locations because the source
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
chunkTreeResult =>
|
chunkTreeResult =>
|
||||||
{
|
{
|
||||||
var viewImportsPath = @"/Views/_ViewImports.cshtml";
|
var viewImportsPath = @"/Views/_ViewImports.cshtml";
|
||||||
Assert.Collection(chunkTreeResult.ChunkTree.Chunks,
|
Assert.Collection(chunkTreeResult.ChunkTree.Children,
|
||||||
chunk =>
|
chunk =>
|
||||||
{
|
{
|
||||||
Assert.IsType<LiteralChunk>(chunk);
|
Assert.IsType<LiteralChunk>(chunk);
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
chunkTreeResult =>
|
chunkTreeResult =>
|
||||||
{
|
{
|
||||||
var viewImportsPath = "/Views/home/_ViewImports.cshtml";
|
var viewImportsPath = "/Views/home/_ViewImports.cshtml";
|
||||||
Assert.Collection(chunkTreeResult.ChunkTree.Chunks,
|
Assert.Collection(chunkTreeResult.ChunkTree.Children,
|
||||||
chunk =>
|
chunk =>
|
||||||
{
|
{
|
||||||
Assert.IsType<LiteralChunk>(chunk);
|
Assert.IsType<LiteralChunk>(chunk);
|
||||||
|
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
{
|
{
|
||||||
new ChunkTree
|
new ChunkTree
|
||||||
{
|
{
|
||||||
Chunks = new Chunk[]
|
Children = new Chunk[]
|
||||||
{
|
{
|
||||||
new UsingChunk { Namespace = "InheritedNamespace" },
|
new UsingChunk { Namespace = "InheritedNamespace" },
|
||||||
new LiteralChunk { Text = "some text" }
|
new LiteralChunk { Text = "some text" }
|
||||||
|
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
},
|
},
|
||||||
new ChunkTree
|
new ChunkTree
|
||||||
{
|
{
|
||||||
Chunks = new Chunk[]
|
Children = new Chunk[]
|
||||||
{
|
{
|
||||||
new UsingChunk { Namespace = "AppNamespace.Model" },
|
new UsingChunk { Namespace = "AppNamespace.Model" },
|
||||||
}
|
}
|
||||||
|
|
@ -172,9 +172,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
utility.MergeInheritedChunkTrees(chunkTree, inheritedChunkTrees, "dynamic");
|
utility.MergeInheritedChunkTrees(chunkTree, inheritedChunkTrees, "dynamic");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(chunkTree.Chunks,
|
Assert.Collection(chunkTree.Children,
|
||||||
chunk => Assert.Same(defaultChunks[1], chunk),
|
chunk => Assert.Same(defaultChunks[1], chunk),
|
||||||
chunk => Assert.Same(inheritedChunkTrees[0].Chunks[0], chunk),
|
chunk => Assert.Same(inheritedChunkTrees[0].Children[0], chunk),
|
||||||
chunk => Assert.Same(defaultChunks[0], chunk));
|
chunk => Assert.Same(defaultChunks[0], chunk));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||||
Assert.Equal(expectedType, injectChunk.TypeName);
|
Assert.Equal(expectedType, injectChunk.TypeName);
|
||||||
Assert.Equal(expectedProperty, injectChunk.MemberName);
|
Assert.Equal(expectedProperty, injectChunk.MemberName);
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(chunkTree.Chunks);
|
Assert.Empty(chunkTree.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -84,12 +84,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
Assert.Equal(2, chunkTree.Children.Count);
|
||||||
var injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[0]);
|
var injectChunk = Assert.IsType<InjectChunk>(chunkTree.Children[0]);
|
||||||
Assert.Equal("MyType", injectChunk.TypeName);
|
Assert.Equal("MyType", injectChunk.TypeName);
|
||||||
Assert.Equal("myproperty", injectChunk.MemberName);
|
Assert.Equal("myproperty", injectChunk.MemberName);
|
||||||
|
|
||||||
injectChunk = Assert.IsType<InjectChunk>(chunkTree.Chunks[1]);
|
injectChunk = Assert.IsType<InjectChunk>(chunkTree.Children[1]);
|
||||||
Assert.Equal("MyTypeB", injectChunk.TypeName);
|
Assert.Equal("MyTypeB", injectChunk.TypeName);
|
||||||
Assert.Equal("different-property", injectChunk.MemberName);
|
Assert.Equal("different-property", injectChunk.MemberName);
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||||
Assert.Equal("MyHelper<dynamic>", injectChunk.TypeName);
|
Assert.Equal("MyHelper<dynamic>", injectChunk.TypeName);
|
||||||
Assert.Equal("MyProperty", injectChunk.MemberName);
|
Assert.Equal("MyProperty", injectChunk.MemberName);
|
||||||
|
|
@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||||
Assert.Equal("MyHelper<MyTestModel2>", injectChunk.TypeName);
|
Assert.Equal("MyHelper<MyTestModel2>", injectChunk.TypeName);
|
||||||
Assert.Equal("MyProperty", injectChunk.MemberName);
|
Assert.Equal("MyProperty", injectChunk.MemberName);
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(chunkTree.Chunks,
|
Assert.Collection(chunkTree.Children,
|
||||||
chunk =>
|
chunk =>
|
||||||
{
|
{
|
||||||
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
var injectChunk = Assert.IsType<InjectChunk>(chunk);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
||||||
Assert.Equal(expected, setBaseTypeChunk.TypeName);
|
Assert.Equal(expected, setBaseTypeChunk.TypeName);
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(chunkTree.Chunks);
|
Assert.Empty(chunkTree.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
|
||||||
Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
|
Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var chunk = Assert.Single(chunkTree.Chunks);
|
var chunk = Assert.Single(chunkTree.Children);
|
||||||
var usingChunk = Assert.IsType<UsingChunk>(chunk);
|
var usingChunk = Assert.IsType<UsingChunk>(chunk);
|
||||||
Assert.Equal(expected, usingChunk.Namespace);
|
Assert.Equal(expected, usingChunk.Namespace);
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(chunkTree.Chunks);
|
Assert.Empty(chunkTree.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -69,10 +69,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
Assert.Equal(2, chunkTree.Children.Count);
|
||||||
var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
|
var chunk = Assert.IsType<UsingChunk>(chunkTree.Children[0]);
|
||||||
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
||||||
chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
|
chunk = Assert.IsType<UsingChunk>(chunkTree.Children[1]);
|
||||||
Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace);
|
Assert.Equal("Microsoft.AspNet.Mvc.Razor", chunk.Namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,10 +92,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
merger.MergeInheritedChunks(chunkTree, inheritedChunks);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, chunkTree.Chunks.Count);
|
Assert.Equal(2, chunkTree.Children.Count);
|
||||||
var chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[0]);
|
var chunk = Assert.IsType<UsingChunk>(chunkTree.Children[0]);
|
||||||
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
Assert.Equal("Microsoft.AspNet.Mvc", chunk.Namespace);
|
||||||
chunk = Assert.IsType<UsingChunk>(chunkTree.Chunks[1]);
|
chunk = Assert.IsType<UsingChunk>(chunkTree.Children[1]);
|
||||||
Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace);
|
Assert.Equal("Microsoft.AspNet.mvc", chunk.Namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
return new ChunkTree
|
return new ChunkTree
|
||||||
{
|
{
|
||||||
Chunks = chunks
|
Children = chunks
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue