-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip insignificant whitespace at compile time (#23385)
* Define @preservewhitespace directive attribute * Have ComponentWhitespacePass respect preservewhitespace option * Tests for overriding the preservewhitespace option (and fix implementation) * Begin adding test infrastucture for ComponentWhitespacePass * Remove leading/trailing whitespace from markup elements recursively * Update baselines * Add test showing we don't remove whitespace between sibling elements * Remove whitespace before/after C# code statements (not expressions) * Update baselines * Slight improvements to test * Remove leading/trailing whitespace inside component child content * Update baselines * Fix Razor tests * Fix MVC test * Better fix for MVC test * CR: Make ComponentPreserveWhitespaceDirective conditional on langversion >= 5.0
- Loading branch information
1 parent
126f14d
commit eb76931
Showing
106 changed files
with
1,591 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...icrosoft.AspNetCore.Razor.Language/src/Components/ComponentPreserveWhitespaceDirective.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language.Components | ||
{ | ||
internal static class ComponentPreserveWhitespaceDirective | ||
{ | ||
public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( | ||
"preservewhitespace", | ||
DirectiveKind.SingleLine, | ||
builder => | ||
{ | ||
builder.AddBooleanToken(ComponentResources.PreserveWhitespaceDirective_BooleanToken_Name, ComponentResources.PreserveWhitespaceDirective_BooleanToken_Description); | ||
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; | ||
builder.Description = ComponentResources.PreserveWhitespaceDirective_Description; | ||
}); | ||
|
||
public static void Register(RazorProjectEngineBuilder builder) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
builder.AddDirective(Directive, FileKinds.Component, FileKinds.ComponentImport); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ public enum DirectiveTokenKind | |
Member, | ||
String, | ||
Attribute, | ||
Boolean, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.