Skip to content

Commit

Permalink
Merge pull request #413 from jbest84/master
Browse files Browse the repository at this point in the history
Fix :has/:is/:where nested selectors removing significant space
  • Loading branch information
trullock authored Dec 10, 2024
2 parents bf806c1 + b73568c commit 571949a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 1 deletion.
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

0 comments on commit 571949a

Please sign in to comment.