diff --git a/src/Microsoft.AspNet.Razor/Editor/EditorHints.cs b/src/Microsoft.AspNet.Razor/Editor/EditorHints.cs index 972d0c0293..fd2f4344d8 100644 --- a/src/Microsoft.AspNet.Razor/Editor/EditorHints.cs +++ b/src/Microsoft.AspNet.Razor/Editor/EditorHints.cs @@ -23,10 +23,5 @@ namespace Microsoft.AspNet.Razor.Editor /// if they do not support it. /// VirtualPath = 1, // 0000 0001 - - /// - /// Indicates that this span's content contains the path to the layout page for this document. - /// - LayoutPage = 2, // 0000 0010 } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs index e2cc70e5ec..8ce53a33db 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs @@ -79,17 +79,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp Accept(chunk.Children); } - protected override void Visit(SetLayoutChunk chunk) - { - if (!Context.Host.DesignTimeMode && !string.IsNullOrEmpty(Context.Host.GeneratedClassContext.LayoutPropertyName)) - { - Writer.Write(Context.Host.GeneratedClassContext.LayoutPropertyName) - .Write(" = ") - .WriteStringLiteral(chunk.Layout) - .WriteLine(";"); - } - } - protected override void Visit(TemplateChunk chunk) { Writer.Write(ItemParameterName).Write(" => ") diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs index ec6172aa8f..5dc7298310 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperAttributeValueVisitor.cs @@ -119,22 +119,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp chunk.Association.Length); } - /// - /// Writes code for the given . - /// - /// The to render. - /// - /// Unconditionally adds a to inform user of unexpected @layout directive. - /// - protected override void Visit(SetLayoutChunk chunk) - { - Context.ErrorSink.OnError( - chunk.Association.Start, - RazorResources.FormatTagHelpers_Directives_NotSupported_InAttributes( - SyntaxConstants.CSharp.LayoutKeyword), - chunk.Association.Length); - } - /// /// Writes code for the given . /// diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs index 73c25b3378..817bb129c2 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/ChunkVisitor.cs @@ -69,10 +69,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler { Visit((RemoveTagHelperChunk)chunk); } - else if (chunk is SetLayoutChunk) - { - Visit((SetLayoutChunk)chunk); - } else if (chunk is ResolveUrlChunk) { Visit((ResolveUrlChunk)chunk); @@ -132,7 +128,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler protected abstract void Visit(ResolveUrlChunk chunk); protected abstract void Visit(SetBaseTypeChunk chunk); protected abstract void Visit(TemplateChunk chunk); - protected abstract void Visit(SetLayoutChunk chunk); protected abstract void Visit(ExpressionBlockChunk chunk); } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs index dedeb3ae6e..1bff29641f 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CodeVisitor.cs @@ -63,8 +63,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler protected override void Visit(TemplateChunk chunk) { } - protected override void Visit(SetLayoutChunk chunk) - { - } } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/Chunks/SetLayoutChunk.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/Chunks/SetLayoutChunk.cs deleted file mode 100644 index 077ed39f72..0000000000 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/Chunks/SetLayoutChunk.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Razor.Generator.Compiler -{ - public class SetLayoutChunk : Chunk - { - public string Layout { get; set; } - } -} diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs index 148337eea3..bb15018f8b 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs @@ -140,14 +140,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler }, association); } - public void AddSetLayoutChunk(string layout, SyntaxTreeNode association) - { - AddChunk(new SetLayoutChunk - { - Layout = layout - }, association); - } - public void AddSetBaseTypeChunk(string typeName, SyntaxTreeNode association) { AddChunk(new SetBaseTypeChunk diff --git a/src/Microsoft.AspNet.Razor/Generator/GeneratedClassContext.cs b/src/Microsoft.AspNet.Razor/Generator/GeneratedClassContext.cs index 02e23f07fb..0715b2463d 100644 --- a/src/Microsoft.AspNet.Razor/Generator/GeneratedClassContext.cs +++ b/src/Microsoft.AspNet.Razor/Generator/GeneratedClassContext.cs @@ -11,7 +11,6 @@ namespace Microsoft.AspNet.Razor.Generator public static readonly string DefaultWriteMethodName = "Write"; public static readonly string DefaultWriteLiteralMethodName = "WriteLiteral"; public static readonly string DefaultExecuteMethodName = "ExecuteAsync"; - public static readonly string DefaultLayoutPropertyName = "Layout"; public static readonly string DefaultWriteAttributeMethodName = "WriteAttribute"; public static readonly string DefaultWriteAttributeToMethodName = "WriteAttributeTo"; @@ -57,7 +56,6 @@ namespace Microsoft.AspNet.Razor.Generator TemplateTypeName = null; DefineSectionMethodName = null; - LayoutPropertyName = DefaultLayoutPropertyName; WriteAttributeMethodName = DefaultWriteAttributeMethodName; WriteAttributeToMethodName = DefaultWriteAttributeToMethodName; } @@ -132,7 +130,6 @@ namespace Microsoft.AspNet.Razor.Generator // Optional Items public string BeginContextMethodName { get; set; } public string EndContextMethodName { get; set; } - public string LayoutPropertyName { get; set; } public string DefineSectionMethodName { get; set; } public string TemplateTypeName { get; set; } public string WriteAttributeMethodName { get; set; } diff --git a/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs deleted file mode 100644 index 6b56d2e16c..0000000000 --- a/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNet.Razor.Parser.SyntaxTree; - -namespace Microsoft.AspNet.Razor.Generator -{ - public class SetLayoutCodeGenerator : SpanCodeGenerator - { - public SetLayoutCodeGenerator(string layoutPath) - { - LayoutPath = layoutPath; - } - - public string LayoutPath { get; set; } - - public override void GenerateCode(Span target, CodeGeneratorContext context) - { - context.CodeTreeBuilder.AddSetLayoutChunk(LayoutPath, target); - } - - public override string ToString() - { - return "Layout: " + LayoutPath; - } - - public override bool Equals(object obj) - { - var other = obj as SetLayoutCodeGenerator; - return other != null && string.Equals(other.LayoutPath, LayoutPath, StringComparison.Ordinal); - } - - public override int GetHashCode() - { - return LayoutPath.GetHashCode(); - } - } -} diff --git a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Directives.cs b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Directives.cs index 23bcfd812a..7042231491 100644 --- a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Directives.cs +++ b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Directives.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Razor.Parser MapDirectives(InheritsDirective, SyntaxConstants.CSharp.InheritsKeyword); MapDirectives(FunctionsDirective, SyntaxConstants.CSharp.FunctionsKeyword); MapDirectives(SectionDirective, SyntaxConstants.CSharp.SectionKeyword); - MapDirectives(LayoutDirective, SyntaxConstants.CSharp.LayoutKeyword); } protected virtual void TagHelperPrefixDirective() @@ -43,31 +42,11 @@ namespace Microsoft.AspNet.Razor.Parser protected virtual void RemoveTagHelperDirective() { TagHelperDirective( - SyntaxConstants.CSharp.RemoveTagHelperKeyword, + SyntaxConstants.CSharp.RemoveTagHelperKeyword, lookupText => new AddOrRemoveTagHelperCodeGenerator(removeTagHelperDescriptors: true, lookupText: lookupText)); } - protected virtual void LayoutDirective() - { - AssertDirective(SyntaxConstants.CSharp.LayoutKeyword); - AcceptAndMoveNext(); - Context.CurrentBlock.Type = BlockType.Directive; - - // Accept spaces, but not newlines - var foundSomeWhitespace = At(CSharpSymbolType.WhiteSpace); - AcceptWhile(CSharpSymbolType.WhiteSpace); - Output(SpanKind.MetaCode, foundSomeWhitespace ? AcceptedCharacters.None : AcceptedCharacters.Any); - - // First non-whitespace character starts the Layout Page, then newline ends it - AcceptUntil(CSharpSymbolType.NewLine); - Span.CodeGenerator = new SetLayoutCodeGenerator(Span.GetContent()); - Span.EditHandler.EditorHints = EditorHints.LayoutPage | EditorHints.VirtualPath; - var foundNewline = Optional(CSharpSymbolType.NewLine); - AddMarkerSymbolIfNecessary(); - Output(SpanKind.MetaCode, foundNewline ? AcceptedCharacters.None : AcceptedCharacters.AnyExceptNewline); - } - protected virtual void SectionDirective() { var nested = Context.IsWithin(BlockType.Section); diff --git a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs index 1c4119e9dc..ff70d33509 100644 --- a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs +++ b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs @@ -36,7 +36,6 @@ namespace Microsoft.AspNet.Razor.Parser "functions", "namespace", "class", - "layout", }; private Dictionary _directiveParsers = new Dictionary(); diff --git a/src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs b/src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs index 63a430a0c8..0eed526fed 100644 --- a/src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs +++ b/src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs @@ -27,7 +27,6 @@ namespace Microsoft.AspNet.Razor.Parser public static readonly string ElseIfKeyword = "else if"; public static readonly string NamespaceKeyword = "namespace"; public static readonly string ClassKeyword = "class"; - public static readonly string LayoutKeyword = "layout"; } } } diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs index 4260d4ae0e..2b6443b6d9 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs @@ -75,7 +75,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator [InlineData("Sections")] [InlineData("RazorComments")] [InlineData("InlineBlocks")] - [InlineData("LayoutDirective")] [InlineData("ConditionalAttributes")] [InlineData("ResolveUrl")] [InlineData("Await")] diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs index 34405888b0..05c8edd04f 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator inputStream.Position = 0; var reader = new StreamReader(inputStream); - // Normalize newlines to be \r\n. This is to ensure when running tests cross plat the final test output + // Normalize newlines to be \r\n. This is to ensure when running tests cross plat the final test output // is compared against test files in a normalized fashion. var fileContents = reader.ReadToEnd().Replace(Environment.NewLine, "\r\n"); @@ -150,7 +150,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator "Instrumentation.EndContext", new GeneratedTagHelperContext()) { - LayoutPropertyName = "Layout", ResolveUrlMethodName = "Href" }; if (hostConfig != null) diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpLayoutDirectiveTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpLayoutDirectiveTest.cs deleted file mode 100644 index 925ad9af58..0000000000 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpLayoutDirectiveTest.cs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNet.Razor.Editor; -using Microsoft.AspNet.Razor.Generator; -using Microsoft.AspNet.Razor.Parser; -using Microsoft.AspNet.Razor.Parser.SyntaxTree; -using Microsoft.AspNet.Razor.Test.Framework; -using Xunit; - -namespace Microsoft.AspNet.Razor.Test.Parser.CSharp -{ - public class CSharpLayoutDirectiveTest : CsHtmlCodeParserTestBase - { - [Theory] - [InlineData("Layout")] - [InlineData("LAYOUT")] - [InlineData("layOut")] - [InlineData("LayOut")] - private void LayoutKeywordIsCaseSensitive(string word) - { - ParseBlockTest(word, - new ExpressionBlock( - Factory.Code(word) - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharacters.NonWhiteSpace) - )); - } - - [Fact] - public void LayoutDirectiveAcceptsAllTextToEndOfLine() - { - ParseBlockTest("@layout Foo Bar Baz", - new DirectiveBlock( - Factory.CodeTransition(), - Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None), - Factory.MetaCode("Foo Bar Baz") - .With(new SetLayoutCodeGenerator("Foo Bar Baz")) - .Accepts(AcceptedCharacters.AnyExceptNewline) - .WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage) - ) - ); - } - - [Fact] - public void LayoutDirectiveAcceptsAnyIfNoWhitespaceFollowingLayoutKeyword() - { - ParseBlockTest("@layout", - new DirectiveBlock( - Factory.CodeTransition(), - Factory.MetaCode("layout") - ) - ); - } - - [Fact] - public void LayoutDirectiveOutputsMarkerSpanIfAnyWhitespaceAfterLayoutKeyword() - { - ParseBlockTest("@layout ", - new DirectiveBlock( - Factory.CodeTransition(), - Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None), - Factory.EmptyCSharp() - .AsMetaCode() - .With(new SetLayoutCodeGenerator(string.Empty)) - .Accepts(AcceptedCharacters.AnyExceptNewline) - .WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage) - ) - ); - } - - [Fact] - public void LayoutDirectiveAcceptsTrailingNewlineButDoesNotIncludeItInLayoutPath() - { - ParseBlockTest("@layout Foo" + Environment.NewLine, - new DirectiveBlock( - Factory.CodeTransition(), - Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None), - Factory.MetaCode("Foo" + Environment.NewLine) - .With(new SetLayoutCodeGenerator("Foo")) - .Accepts(AcceptedCharacters.None) - .WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage) - ) - ); - } - - [Fact] - public void LayoutDirectiveCorrectlyRestoresContextAfterCompleting() - { - ParseDocumentTest("@layout Foo" + Environment.NewLine - + "@foo", - new MarkupBlock( - Factory.EmptyHtml(), - new DirectiveBlock( - Factory.CodeTransition(), - Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None), - Factory.MetaCode("Foo" + Environment.NewLine) - .With(new SetLayoutCodeGenerator("Foo")) - .Accepts(AcceptedCharacters.None) - .WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage) - ), - Factory.EmptyHtml(), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.Code("foo") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false) - .Accepts(AcceptedCharacters.NonWhiteSpace)), - Factory.EmptyHtml())); - } - } -} diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/PartialParsing/CSharpPartialParsingTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/PartialParsing/CSharpPartialParsingTest.cs index 2677b3e106..fed4aa19e4 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/PartialParsing/CSharpPartialParsingTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/PartialParsing/CSharpPartialParsingTest.cs @@ -653,11 +653,5 @@ namespace Microsoft.AspNet.Razor.Test.Parser.PartialParsing { RunTypeKeywordTest("class"); } - - [Fact] - public void ImplicitExpressionCorrectlyTriggersReparseIfLayoutKeywordTyped() - { - RunTypeKeywordTest("layout"); - } } } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/LayoutDirective.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/LayoutDirective.cs deleted file mode 100644 index 1bef53d9e9..0000000000 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/LayoutDirective.cs +++ /dev/null @@ -1,21 +0,0 @@ -#pragma checksum "LayoutDirective.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "018a686988146d5eb7d51f83c22f820e66b276e0" -namespace TestOutput -{ - using System; - using System.Threading.Tasks; - - public class LayoutDirective - { - #line hidden - public LayoutDirective() - { - } - - #pragma warning disable 1998 - public override async Task ExecuteAsync() - { - Layout = "~/Foo/Bar/Baz"; - } - #pragma warning restore 1998 - } -} diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/LayoutDirective.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/LayoutDirective.cshtml deleted file mode 100644 index 155c550b8e..0000000000 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/LayoutDirective.cshtml +++ /dev/null @@ -1 +0,0 @@ -@layout ~/Foo/Bar/Baz \ No newline at end of file