Skip to content

Commit

Permalink
Merge branch 'release/vs16.0-preview4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaybhargavb committed Feb 7, 2019
2 parents 437b652 + 56fa17b commit 408b123
Show file tree
Hide file tree
Showing 43 changed files with 729 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ public override SyntaxNode Visit(SyntaxNode node)

public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
{
if (_nestedLevel > 0)
if (node.DirectiveDescriptor?.Directive != SectionDirective.Directive.Directive)
{
// We only want to track the nesting of section directives.
return base.VisitRazorDirective(node);
}

_nestedLevel++;
var result = (RazorDirectiveSyntax)base.VisitRazorDirective(node);

if (_nestedLevel > 1)
{
var directiveStart = node.Transition.GetSourceLocation(_syntaxTree.Source);
var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length;
var error = RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(new SourceSpan(directiveStart, errorLength));
node = node.AppendDiagnostic(error);
result = result.AppendDiagnostic(error);
}
_nestedLevel++;
var result = base.VisitRazorDirective(node);

_nestedLevel--;

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,9 @@ private void ParseReservedDirective(SyntaxListBuilder<RazorSyntaxNode> builder,
CompleteBlock();
var keyword = OutputAsMetaCode(Output());
var directiveBody = SyntaxFactory.RazorDirectiveBody(keyword, cSharpCode: null);

// transition could be null if we're already inside a code block.
transition = transition ?? SyntaxFactory.CSharpTransition(SyntaxFactory.MissingToken(SyntaxKind.Transition));
var directive = SyntaxFactory.RazorDirective(transition, directiveBody);
builder.Add(directive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,6 @@ private void ParseJavascriptAndEndScriptTag(in SyntaxListBuilder<RazorSyntaxNode
var tagStart = CurrentStart;
builder.Add(OutputAsMarkupLiteral());

SpanContext.EditHandler.AcceptedCharacters = endTagAcceptedCharacters;

var openAngleToken = EatCurrentToken(); // '<'
var forwardSlashToken = EatCurrentToken(); // '/'
var tagNameToken = EatCurrentToken(); // 'script'
Expand All @@ -1369,8 +1367,10 @@ private void ParseJavascriptAndEndScriptTag(in SyntaxListBuilder<RazorSyntaxNode
{
var miscAttributeBuilder = pooledResult.Builder;

ParseMarkupNodes(miscAttributeBuilder, ParseMode.Text, token => token.Kind == SyntaxKind.CloseAngle);
// We want to accept malformed end tags as content.
AcceptUntil(SyntaxKind.CloseAngle, SyntaxKind.OpenAngle);
miscAttributeBuilder.Add(OutputAsMarkupLiteral());

if (miscAttributeBuilder.Count > 0)
{
miscContent = SyntaxFactory.MarkupMiscAttributeContent(miscAttributeBuilder.ToList());
Expand All @@ -1390,6 +1390,8 @@ private void ParseJavascriptAndEndScriptTag(in SyntaxListBuilder<RazorSyntaxNode
}
}

SpanContext.EditHandler.AcceptedCharacters = endTagAcceptedCharacters;

endTag = SyntaxFactory.MarkupEndTag(
openAngleToken,
forwardSlashToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,28 @@ public override SyntaxNode VisitRazorMetaCode(RazorMetaCodeSyntax node)
return base.VisitRazorMetaCode(node);
}

public override SyntaxNode VisitCSharpStatement(CSharpStatementSyntax node)
{
// We don't support code blocks inside tag helper attributes. Don't rewrite anything inside a code block.
// E.g, <p age="@{1 + 2}"> is not supported.
return node;
}

public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
{
// We don't support directives inside tag helper attributes. Don't rewrite anything inside a directive.
// E.g, <p age="@functions { }"> is not supported.
return node;
}

public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
{
// We're visiting an attribute value. If we encounter a MarkupElement this means the attribute value is invalid.
// We don't want to rewrite anything here.
// E.g, <my age="@if (true) { <my4 age=... }"></my4>
return node;
}

public override SyntaxNode VisitCSharpExpressionLiteral(CSharpExpressionLiteralSyntax node)
{
if (!_tryParseResult.IsBoundNonStringAttribute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public void Await_Runtime()
RunTimeTest();
}

[Fact]
public void Tags_Runtime()
{
RunTimeTest();
}

[Fact]
public void SimpleTagHelpers_Runtime()
{
Expand Down Expand Up @@ -707,6 +713,12 @@ public void Await_DesignTime()
DesignTimeTest();
}

[Fact]
public void Tags_DesignTime()
{
DesignTimeTest();
}

[Fact]
public void AddTagHelperDirective_DesignTime()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class ModelState
}
}

[Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/6113")] // Regression test for #1068
[Fact] // Regression test for #1068
public void Regression_1068()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ public void ParserOutputsErrorOnNestedSections()
new[] { SectionDirective.Directive });
}

[Fact]
public void ParserOutputsErrorOnMultipleNestedSections()
{
ParseDocumentTest(
"@section foo { @section bar { <p>Foo</p> @section baz { } } }",
new[] { SectionDirective.Directive });
}

[Fact]
public void ParserDoesNotOutputErrorOtherNestedDirectives()
{
// This isn't a real scenario but we just want to verify we don't show misleading errors.
ParseDocumentTest(
"@section foo { @inherits Bar }",
new[] { SectionDirective.Directive, InheritsDirective.Directive });
}

[Fact]
public void HandlesEOFAfterOpenBrace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public void ScriptTag_Incomplete()
ParseDocumentTest("<script type=");
}

[Fact]
public void ScriptTag_Invalid()
{
ParseDocumentTest("@{ <script></script @ > }");
}

[Fact]
public void VoidElementFollowedByContent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,5 +900,11 @@ public void Directives_CanUseReservedWord_Namespace()
"@namespace",
new[] { descriptor });
}

[Fact]
public void Directives_ReservedWordInsideCodeBlock()
{
ParseDocumentTest("@{ class }");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ public void CreatesErrorForMalformedTagHelpersWithAttributes19()
RunParseTreeRewriterTest("<p class=some=thing attr=\"@value\"></p>", "strong", "p");
}

[Fact]
public void CreatesErrorForMalformedTagHelpersWithAttributes20()
{
RunParseTreeRewriterTest("<p attr=\"@if (true) <p attr='@foo'> }\"></p>", "strong", "p");
}

[Fact]
public void CreatesErrorForMalformedTagHelper1()
{
Expand Down Expand Up @@ -482,6 +488,12 @@ public void CreatesMarkupCodeSpansForNonStringTagHelperAttributes11()
EvaluateData(CodeTagHelperAttributes_Descriptors, "<person age=\"@@@(11+1)\" birthday=\"DateTime.Now\" name=\"Time: @DateTime.Now\" />");
}

[Fact]
public void CreatesMarkupCodeSpansForNonStringTagHelperAttributes12()
{
EvaluateData(CodeTagHelperAttributes_Descriptors, "<person age=\"@{flag == 0 ? 11 : 12}\" />");
}

[Fact]
public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
<input checked=" @( DateTimeOffset.Now.Year ) > 2014 " />
</p>
@someMethod(@<p age="123" class="hello"><input checked=@checked /></p>)
<p age="@{1 + 2}"></p>
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ public async System.Threading.Tasks.Task ExecuteAsync()

#line default
#line hidden
__TestNamespace_PTagHelper = CreateTagHelper<global::TestNamespace.PTagHelper>();
#line 36 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml"
__TestNamespace_PTagHelper.Age = ;

#line default
#line hidden
#line 37 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml"

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml(36,17): Error RZ2006: Code blocks (e.g. @{var variable = 23;}) must not appear in non-string tag helper attribute values.
Already in an expression (code) context. If necessary an explicit expression (e.g. @(@readonly)) may be used.
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,17 @@ Document -
IntermediateToken - (1387:34,41 [5] ComplexTagHelpers.cshtml) - Html - hello
DefaultTagHelperExecute -
IntermediateToken - (1424:34,78 [1] ComplexTagHelpers.cshtml) - CSharp - )
HtmlContent - (1425:34,79 [12] ComplexTagHelpers.cshtml)
IntermediateToken - (1425:34,79 [6] ComplexTagHelpers.cshtml) - Html - \n
IntermediateToken - (1431:35,4 [6] ComplexTagHelpers.cshtml) - Html - </div>
CSharpCode - (1437:35,10 [3] ComplexTagHelpers.cshtml)
IntermediateToken - (1437:35,10 [3] ComplexTagHelpers.cshtml) - CSharp - \n}
HtmlContent - (1425:34,79 [10] ComplexTagHelpers.cshtml)
IntermediateToken - (1425:34,79 [10] ComplexTagHelpers.cshtml) - Html - \n
TagHelper - (1435:35,8 [22] ComplexTagHelpers.cshtml) - p - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
DefaultTagHelperCreate - - TestNamespace.PTagHelper
DefaultTagHelperProperty - (1443:35,16 [8] ComplexTagHelpers.cshtml) - age - int TestNamespace.PTagHelper.Age - HtmlAttributeValueStyle.DoubleQuotes
CSharpCode - (1445:35,18 [5] ComplexTagHelpers.cshtml)
IntermediateToken - (1445:35,18 [5] ComplexTagHelpers.cshtml) - CSharp - 1 + 2
DefaultTagHelperExecute -
HtmlContent - (1457:35,30 [12] ComplexTagHelpers.cshtml)
IntermediateToken - (1457:35,30 [6] ComplexTagHelpers.cshtml) - Html - \n
IntermediateToken - (1463:36,4 [6] ComplexTagHelpers.cshtml) - Html - </div>
CSharpCode - (1469:36,10 [3] ComplexTagHelpers.cshtml)
IntermediateToken - (1469:36,10 [3] ComplexTagHelpers.cshtml) - CSharp - \n}
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ Source Location: (1424:34,78 [1] TestFiles/IntegrationTests/CodeGenerationIntegr
Generated Location: (9546:204,1 [1] )
|)|

Source Location: (1437:35,10 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml)
Source Location: (1469:36,10 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml)
|
}|
Generated Location: (9685:209,10 [3] )
Generated Location: (9941:215,10 [3] )
|
}|

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0ebc2a451a011b17f08d86ab395d2ef2bdaaf44e"
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ab167e80e48e48d9984ecd76158a2d87f90f3460"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ComplexTagHelpers_Runtime), @"default", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml")]
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
{
#line hidden
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"0ebc2a451a011b17f08d86ab395d2ef2bdaaf44e", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml")]
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"ab167e80e48e48d9984ecd76158a2d87f90f3460", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml")]
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ComplexTagHelpers_Runtime
{
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("type", "text", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
Expand Down Expand Up @@ -480,8 +480,27 @@ public async System.Threading.Tasks.Task ExecuteAsync()

#line default
#line hidden
WriteLiteral("\r\n ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
}
);
__TestNamespace_PTagHelper = CreateTagHelper<global::TestNamespace.PTagHelper>();
__tagHelperExecutionContext.Add(__TestNamespace_PTagHelper);
#line 36 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml"
__TestNamespace_PTagHelper.Age = ;

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("age", __TestNamespace_PTagHelper.Age, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n </div>\r\n");
#line 37 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml"
#line 38 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml"
}

#line default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ComplexTagHelpers.cshtml(36,17): Error RZ2006: Code blocks (e.g. @{var variable = 23;}) must not appear in non-string tag helper attribute values.
Already in an expression (code) context. If necessary an explicit expression (e.g. @(@readonly)) may be used.
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,18 @@ Document -
PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_7
DefaultTagHelperExecute -
IntermediateToken - (1424:34,78 [1] ComplexTagHelpers.cshtml) - CSharp - )
HtmlContent - (1425:34,79 [14] ComplexTagHelpers.cshtml)
IntermediateToken - (1425:34,79 [6] ComplexTagHelpers.cshtml) - Html - \n
IntermediateToken - (1431:35,4 [6] ComplexTagHelpers.cshtml) - Html - </div>
IntermediateToken - (1437:35,10 [2] ComplexTagHelpers.cshtml) - Html - \n
CSharpCode - (1439:36,0 [1] ComplexTagHelpers.cshtml)
IntermediateToken - (1439:36,0 [1] ComplexTagHelpers.cshtml) - CSharp - }
HtmlContent - (1425:34,79 [10] ComplexTagHelpers.cshtml)
IntermediateToken - (1425:34,79 [10] ComplexTagHelpers.cshtml) - Html - \n
TagHelper - (1435:35,8 [22] ComplexTagHelpers.cshtml) - p - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
DefaultTagHelperCreate - - TestNamespace.PTagHelper
DefaultTagHelperProperty - (1443:35,16 [8] ComplexTagHelpers.cshtml) - age - int TestNamespace.PTagHelper.Age - HtmlAttributeValueStyle.DoubleQuotes
CSharpCode - (1445:35,18 [5] ComplexTagHelpers.cshtml)
IntermediateToken - (1445:35,18 [5] ComplexTagHelpers.cshtml) - CSharp - 1 + 2
DefaultTagHelperExecute -
HtmlContent - (1457:35,30 [14] ComplexTagHelpers.cshtml)
IntermediateToken - (1457:35,30 [6] ComplexTagHelpers.cshtml) - Html - \n
IntermediateToken - (1463:36,4 [6] ComplexTagHelpers.cshtml) - Html - </div>
IntermediateToken - (1469:36,10 [2] ComplexTagHelpers.cshtml) - Html - \n
CSharpCode - (1471:37,0 [1] ComplexTagHelpers.cshtml)
IntermediateToken - (1471:37,0 [1] ComplexTagHelpers.cshtml) - CSharp - }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
<script type="text/javascript" @{} ></script @foo >
}
<script></script @
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
{
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Tags_DesignTime
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
public async System.Threading.Tasks.Task ExecuteAsync()
{
#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Tags.cshtml"



#line default
#line hidden
#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Tags.cshtml"


#line default
#line hidden
#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Tags.cshtml"


#line default
#line hidden
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Tags.cshtml(5,11): Error RZ1024: End of file or an unexpected character was reached before the "script" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing ("<br />") or have matching end tags ("<p>Hello</p>"). If you intended to display a "<" character, use the "&lt;" HTML entity.
Loading

0 comments on commit 408b123

Please sign in to comment.