Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

New baselines for TagHelperParseTreeRewriterTest #2639

Merged

Conversation

ajaybhargavb
Copy link
Contributor

@ajaybhargavb ajaybhargavb commented Oct 9, 2018

Part of #2584

Converted all of the TagHelperParseTreeRewriter tests. I understand it is impossible to look through each and every test. I suggest looking at as many different types of test as possible.

I'm only including the test changes here because the source may change a lot and it isn't worth reviewing at this point. If anyone is interested the source is here.

Here is the syntax for tag helpers,

  <Node Name="MarkupTagHelperElementSyntax" Base="MarkupSyntaxNode">
    <Kind Name="MarkupTagHelperElement" />
    <Field Name="StartTag" Type="MarkupTagHelperStartTagSyntax" />
    <Field Name="Body" Type="SyntaxList&lt;RazorSyntaxNode&gt;" Optional="true" />
    <Field Name="EndTag" Type="MarkupTagHelperEndTagSyntax" Optional="true" />
  </Node>
  <Node Name="MarkupTagHelperStartTagSyntax" Base="RazorBlockSyntax">
    <Kind Name="MarkupTagHelperStartTag" />
    <Field Name="Children" Type="SyntaxList&lt;RazorSyntaxNode&gt;" Override="true" />
  </Node>
  <Node Name="MarkupTagHelperEndTagSyntax" Base="RazorBlockSyntax">
    <Kind Name="MarkupTagHelperEndTag" />
    <Field Name="Children" Type="SyntaxList&lt;RazorSyntaxNode&gt;" Override="true" />
  </Node>
  <Node Name="MarkupTagHelperAttributeSyntax" Base="MarkupSyntaxNode">
    <Kind Name="MarkupTagHelperAttribute" />
    <Field Name="NamePrefix" Type="MarkupTextLiteralSyntax" Optional="true" />
    <Field Name="Name" Type="MarkupTextLiteralSyntax" />
    <Field Name="NameSuffix" Type="MarkupTextLiteralSyntax" Optional="true" />
    <Field Name="EqualsToken" Type="SyntaxToken">
      <Kind Name="Equals" />
    </Field>
    <Field Name="ValuePrefix" Type="MarkupTextLiteralSyntax" Optional="true" />
    <Field Name="Value" Type="MarkupTagHelperAttributeValueSyntax" />
    <Field Name="ValueSuffix" Type="MarkupTextLiteralSyntax" Optional="true" />
  </Node>
  <Node Name="MarkupMinimizedTagHelperAttributeSyntax" Base="MarkupSyntaxNode">
    <Kind Name="MarkupMinimizedTagHelperAttribute" />
    <Field Name="NamePrefix" Type="MarkupTextLiteralSyntax" Optional="true" />
    <Field Name="Name" Type="MarkupTextLiteralSyntax" />
  </Node>
  <Node Name="MarkupTagHelperAttributeValueSyntax" Base="RazorBlockSyntax">
    <Kind Name="MarkupTagHelperAttributeValue" />
    <Field Name="Children" Type="SyntaxList&lt;RazorSyntaxNode&gt;" Override="true" />
  </Node>

@@ -16,15 +16,6 @@ public TagHelperParseTreeRewriterTest()
UseNewSyntaxTree = true;
}

[Fact]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore. Just something I added in a previous commit.

Text;[and];
Whitespace;[ ];
Text;[spaces];
MarkupTagHelperEndTag - [37..47)::10
Copy link
Contributor Author

@ajaybhargavb ajaybhargavb Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main structural change. Tag helper end tags are now well represented in the tree.
I am currently not generating the corresponding classified spans for this to keep them consistent with the old tree. But ideally we should generate those. We should discuss this at some point. I've added it to the tracking list https://github.com/aspnet/Razor/issues/2619. @rynowak this is what I was trying to explain earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the behaviour isn't changing right now, then that sounds great!

Equals;[=];
MarkupTextLiteral - [15..16)::1 - ["] - Gen<None> - SpanEditHandler;Accepts:Any
DoubleQuote;["];
MarkupTagHelperAttributeValue - [16..19)::3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the attibute value of tag helpers use a specific type (MarkupTagHelperAttributeValue) as opposed to using a GenericBlock.

DoubleQuote;["];
MarkupTagHelperAttributeValue - [17..30)::13
MarkupDynamicAttributeValue - [17..30)::13 - [@DateTime.Now]
GenericBlock - [17..30)::13
Copy link
Contributor Author

@ajaybhargavb ajaybhargavb Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed earlier, we will get rid of GenericBlock at some point. I've added that to the feedback list https://github.com/aspnet/Razor/issues/2619

(0,0): Error RZ3008: Tag helpers cannot target tag name '?xml' because it contains a '?' character.
(0,0): Error RZ3008: Tag helpers cannot target tag name '![CDATA[' because it contains a '!' character.
(0,0): Error RZ3008: Tag helpers cannot target tag name '![CDATA[' because it contains a '[' character.
(0,0): Error RZ3008: Tag helpers cannot target tag name '!DOCTYPE' because it contains a '!' character.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a bug. These are the errors generated when the tag helper descriptors are found. Previously, TagHelperParseTreeRewriter was not responsible for combing these errors so test code never saw that. But I had to refactor some of that code and now the errors are combined in TagHelperParseTreeRewriter. Hence these errors show up.

Transition;[@];
CSharpImplicitExpressionBody - [18..30)::12
CSharpCodeBlock - [18..30)::12
CSharpExpressionLiteral - [18..30)::12 - [DateTime.Now] - Gen<Expr> - ImplicitExpressionEditHandler;Accepts:AnyExceptNewline;ImplicitExpression[ATD];K14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of where we rewrite the EditHandler and AcceptedCharacters for a bound non-string attribute. Before the rewrite the AcceptedCharacters for this would be NonWhitespace.

OpenAngle;[<];
ForwardSlash;[/];
Text;[th:p];
CloseAngle;[>];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here's an example of how this syntax representation is SO MUCH BETTER and more accurate than what we had before. 👍

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a random sampling of this, and WOW so much better. I want @NTaylorMullen to look at this as well.

Copy link

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super dope, looking sweet man.

MarkupTextLiteral - [0..8)::8 - [<th:myth] - Gen<Markup> - SpanEditHandler;Accepts:Any
OpenAngle;[<];
Text;[th:myth];
MarkupTagHelperAttribute - [8..20)::12 - class - DoubleQuotes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should spit out the content of this like you do in MarkupTextLiteral

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/th-parsetree-rewriter-test branch from 23ad206 to 25c7a17 Compare October 9, 2018 22:43
@ajaybhargavb ajaybhargavb merged commit 25c7a17 into ajbaaska/taghelper-parser Oct 9, 2018
@ajaybhargavb ajaybhargavb deleted the ajbaaska/th-parsetree-rewriter-test branch October 9, 2018 22:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants