Merge branch 'release/vs16.0-preview4'

\n\nCommit migrated from 408b123a64
This commit is contained in:
Ajay Bhargav Baaskaran 2019-02-07 15:08:16 -08:00
commit 990c585eba
5 changed files with 67 additions and 8 deletions

View File

@ -65,15 +65,23 @@ namespace Microsoft.AspNetCore.Razor.Language
public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax 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 directiveStart = node.Transition.GetSourceLocation(_syntaxTree.Source);
var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length; var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length;
var error = RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(new SourceSpan(directiveStart, errorLength)); var error = RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(new SourceSpan(directiveStart, errorLength));
node = node.AppendDiagnostic(error); result = result.AppendDiagnostic(error);
} }
_nestedLevel++;
var result = base.VisitRazorDirective(node);
_nestedLevel--; _nestedLevel--;
return result; return result;

View File

@ -2179,6 +2179,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
CompleteBlock(); CompleteBlock();
var keyword = OutputAsMetaCode(Output()); var keyword = OutputAsMetaCode(Output());
var directiveBody = SyntaxFactory.RazorDirectiveBody(keyword, cSharpCode: null); 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); var directive = SyntaxFactory.RazorDirective(transition, directiveBody);
builder.Add(directive); builder.Add(directive);
} }

View File

@ -1357,8 +1357,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var tagStart = CurrentStart; var tagStart = CurrentStart;
builder.Add(OutputAsMarkupLiteral()); builder.Add(OutputAsMarkupLiteral());
SpanContext.EditHandler.AcceptedCharacters = endTagAcceptedCharacters;
var openAngleToken = EatCurrentToken(); // '<' var openAngleToken = EatCurrentToken(); // '<'
var forwardSlashToken = EatCurrentToken(); // '/' var forwardSlashToken = EatCurrentToken(); // '/'
var tagNameToken = EatCurrentToken(); // 'script' var tagNameToken = EatCurrentToken(); // 'script'
@ -1369,8 +1367,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{ {
var miscAttributeBuilder = pooledResult.Builder; 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()); miscAttributeBuilder.Add(OutputAsMarkupLiteral());
if (miscAttributeBuilder.Count > 0) if (miscAttributeBuilder.Count > 0)
{ {
miscContent = SyntaxFactory.MarkupMiscAttributeContent(miscAttributeBuilder.ToList()); miscContent = SyntaxFactory.MarkupMiscAttributeContent(miscAttributeBuilder.ToList());
@ -1390,6 +1390,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
} }
} }
SpanContext.EditHandler.AcceptedCharacters = endTagAcceptedCharacters;
endTag = SyntaxFactory.MarkupEndTag( endTag = SyntaxFactory.MarkupEndTag(
openAngleToken, openAngleToken,
forwardSlashToken, forwardSlashToken,

View File

@ -480,6 +480,28 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return base.VisitRazorMetaCode(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) public override SyntaxNode VisitCSharpExpressionLiteral(CSharpExpressionLiteralSyntax node)
{ {
if (!_tryParseResult.IsBoundNonStringAttribute) if (!_tryParseResult.IsBoundNonStringAttribute)

View File

@ -409,7 +409,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
baselineDiagnostics = diagnosticsFile.ReadAllText(); baselineDiagnostics = diagnosticsFile.ReadAllText();
} }
var actualDiagnostics = string.Concat(cSharpDocument.Diagnostics.Select(d => RazorDiagnosticSerializer.Serialize(d) + "\r\n")); var actualDiagnostics = string.Concat(cSharpDocument.Diagnostics.Select(d => NormalizeNewLines(RazorDiagnosticSerializer.Serialize(d)) + "\r\n"));
Assert.Equal(baselineDiagnostics, actualDiagnostics); Assert.Equal(baselineDiagnostics, actualDiagnostics);
} }
@ -541,6 +541,30 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
} }
return base.VisitCSharpExpressionLiteral(node); return base.VisitCSharpExpressionLiteral(node);
} }
public override Syntax.SyntaxNode VisitCSharpStatement(CSharpStatementSyntax node)
{
if (node.FirstAncestorOrSelf<MarkupTagHelperAttributeValueSyntax>() != null)
{
// We don't support code blocks inside tag helper attribute values.
// If it exists, we don't want to track its code spans for source mappings.
return node;
}
return base.VisitCSharpStatement(node);
}
public override Syntax.SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
{
if (node.FirstAncestorOrSelf<MarkupTagHelperAttributeValueSyntax>() != null)
{
// We don't support Razor directives inside tag helper attribute values.
// If it exists, we don't want to track its code spans for source mappings.
return node;
}
return base.VisitRazorDirective(node);
}
} }
private static string EscapeWhitespace(string content) private static string EscapeWhitespace(string content)