Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :has/:is/:where nested selectors removing significant space #413

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/NUglify.Tests/Css/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public void Bug309()
public void Bug331()
{
TestHelper.Instance.RunTest();
}

[Test]
public void Bug412()
{
TestHelper.Instance.RunTest();
}

[Test]
Expand Down
6 changes: 6 additions & 0 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@
<Content Include="TestData\CSS\Expected\Bugs\Bug331.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Expected\Bugs\Bug412.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Expected\Bugs\Bug74.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -446,6 +449,9 @@
<Content Include="TestData\CSS\Input\Bugs\Bug250.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Input\Bugs\Bug412.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Input\Bugs\Bug74.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
1 change: 1 addition & 0 deletions src/NUglify.Tests/TestData/CSS/Expected/Bugs/Bug412.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.foo:has(span span){color:#f00;text-align:center}
4 changes: 4 additions & 0 deletions src/NUglify.Tests/TestData/CSS/Input/Bugs/Bug412.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.foo:has(span span) {
color: #f00;
text-align: center;
}
5 changes: 4 additions & 1 deletion src/NUglify/Css/CssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,10 @@ Parsed ParsePseudo()

case TokenType.Not:
case TokenType.Any:
case TokenType.Matches:
case TokenType.Matches:
case TokenType.Is:
case TokenType.Where:
case TokenType.Has:
AppendCurrent();
SkipSpace();

Expand Down
13 changes: 13 additions & 0 deletions src/NUglify/Css/CssScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ CssToken ScanIdent()
NextChar();

var tokenType = TokenType.Function;
// TODO: Refactor to shared TokenType of "PsuedoWithNested"
if (ident.Equals("not", StringComparison.OrdinalIgnoreCase))
{
tokenType = TokenType.Not;
Expand All @@ -1197,6 +1198,18 @@ CssToken ScanIdent()
{
tokenType = TokenType.Matches;
}
else if (ident.Equals("has", StringComparison.OrdinalIgnoreCase))
{
tokenType = TokenType.Has;
}
else if (ident.Equals("is", StringComparison.OrdinalIgnoreCase))
{
tokenType = TokenType.Is;
}
else if (ident.Equals("where", StringComparison.OrdinalIgnoreCase))
{
tokenType = TokenType.Where;
}

token = new CssToken(tokenType, ident + '(', m_context);
}
Expand Down
3 changes: 3 additions & 0 deletions src/NUglify/Css/CssToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ enum TokenType
Function,
Not,
Any,
Has,
Is,
Where,
Matches,
UnicodeRange,
ProgId,
Expand Down