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

Conversation

@ajaybhargavb
Copy link
Contributor

@ajaybhargavb ajaybhargavb commented Sep 20, 2018

I added a bunch of syntax manipulation APIs as part of 623d743 (Didn't add that here because it might be too much noise)

  • Used some of those APIs to rewrite WhitespaceRewriter
  • The new syntax tree makes it so that we don't need ConditionalAttributeCollapser (Needs some changes at the IR lowering level)
  • Updated the test

In the future, we could also think about removing the need for WhitespaceRewriter entirely.

span.ChunkGenerator is MarkupChunkGenerator ||
span.ChunkGenerator == SpanChunkGenerator.Null);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming that this is just a rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

newBlock.Children.Add(node);
}
return newBlock.Build();
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming that this is just a rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

// Replace the existing code block with the whitespace literal
// followed by the rewritten code block (with the code whitespace removed).
result = result.ReplaceNode(codeBlock, new SyntaxNode[] { whitespaceLiteral, rewritten });
}
Copy link
Member

Choose a reason for hiding this comment

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

The idiomatic way to implement this is to override Visit(CSharpCodeBlock ) and do your work in there.

Copy link
Member

Choose a reason for hiding this comment

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

Ah NVM, I see that you're doing operating on result. NP.

{
newBlock.Children.Add(node);
var literalContent = GetContent(literal);
if (literalContent.All(char.IsWhiteSpace))
Copy link
Member

Choose a reason for hiding this comment

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

Should this be string.IsWhitespace(? This is a really inefficient way to implement that kind of check.

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 line was copy-paste from old code. Will replace.

public override SyntaxNode Visit(SyntaxNode node)
{
return block.Type == BlockKindInternal.Expression && Parent != null;
var result = node;
Copy link
Member

Choose a reason for hiding this comment

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

This isn't really needed. You could use node instead becuase the result isn't really ever returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't follow. It is used later in base.Visit(result).

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying you could just reassign node. This is a nitpick anyways, you do you

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/taghelper-parser branch from 343bee4 to 8101726 Compare September 20, 2018 19:48
{
newBlock.Children.Add(node);
var literalContent = GetContent(literal);
if (literalContent != null && string.IsNullOrWhiteSpace(literalContent))
Copy link
Contributor

Choose a reason for hiding this comment

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

string.IsNullOrWhiteSpace should take care of literalContent being null.

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, you could get away with just checking if it has non-whitespace content no? node.DescendantNodes().Where(n => n.IsToken).Cast<SyntaxToken>().Any(t => !string.IsNullOrWhitespace(t.Content))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

string.IsNullOrWhiteSpace should take care of literalContent being null.

Not really. I don't want the if block to execute when literalContent is null.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/taghelper-parser branch from 8101726 to 87842cc Compare September 20, 2018 20:31
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.

Everything else looks good, clarified most feedback offline.

@ajaybhargavb ajaybhargavb merged commit 3532097 into feature/razor-parser Sep 21, 2018
@ajaybhargavb ajaybhargavb deleted the ajbaaska/taghelper-parser branch September 21, 2018 00:22
ajaybhargavb added a commit that referenced this pull request Sep 27, 2018
* Rewrite WhitespaceRewriter

* Rename CSharpExpression to CSharpExplicitExpression
ajaybhargavb added a commit that referenced this pull request Sep 27, 2018
* Rewrite WhitespaceRewriter

* Rename CSharpExpression to CSharpExplicitExpression
ajaybhargavb added a commit that referenced this pull request Nov 2, 2018
* Rewrite WhitespaceRewriter

* Rename CSharpExpression to CSharpExplicitExpression
ajaybhargavb added a commit that referenced this pull request Nov 9, 2018
* Rewrite WhitespaceRewriter

* Rename CSharpExpression to CSharpExplicitExpression
ajaybhargavb added a commit that referenced this pull request Nov 10, 2018
* Rewrite WhitespaceRewriter

* Rename CSharpExpression to CSharpExplicitExpression
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.

5 participants