Skip to content

Commit

Permalink
CSS: support for 'of' keyword in :nth-child and :nth-last-child (trul…
Browse files Browse the repository at this point in the history
  • Loading branch information
giroletm committed Apr 30, 2024
1 parent a10a512 commit 5e62176
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/NUglify.Tests/Css/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ public void Bug343()
}


[Test]
public void Bug366()
{
Assert.AreEqual("#thisisanid :nth-child(1 of ul.firstclass~ul:not(.secondclass)){background:#f00}", Uglify.Css(@"
#thisisanid :nth-child(1 of ul.firstclass ~ ul:not(.secondclass)) {
background: #ff0000;
}
").Code);
}


[Test]
public void Bug379()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{
border-left: 25.0px dashed lightgray;
}
.bar:nth-child(n+1 of .test) {
background-color: #ff0000;
}
/*/#source 1 1 TESTRUNPATH\Out\Dll\Input\ManifestTask\file2.css */
body
{
Expand Down
3 changes: 3 additions & 0 deletions src/NUglify.Tests/TestData/Core/Input/ManifestTask/file1.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.foo:nth-child(n+1)
{
border-left: 25.0px dashed lightgray;
}
.bar:nth-child(n+1 of .test) {
background-color: #ff0000;
}
6 changes: 6 additions & 0 deletions src/NUglify/Css/CssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,12 @@ Parsed ParseExpression()
}
break;

case TokenType.Of:
AppendCurrent();
NextToken();
ParseSelector(); // Selectors v4 indicates that :nth-child and :nth-last-child can have their n argument followed by "of S" with S being a selector
break;

default:
// anything else and we bail
return parsed;
Expand Down
5 changes: 5 additions & 0 deletions src/NUglify/Css/CssScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,11 @@ CssToken ScanIdent()
NextChar();
token = ScanProgId();
}
else if (ident.Equals("of", StringComparison.OrdinalIgnoreCase) && m_currentChar == ' ')
{
NextChar();
token = new CssToken(TokenType.Of, " " + ident + " ", m_context);
}
else
{
token = new CssToken(TokenType.Identifier, ident, m_context);
Expand Down
1 change: 1 addition & 0 deletions src/NUglify/Css/CssToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ enum TokenType
Character,
Comment,
Fraction,
Of,

// CSS3 paged media at-symbols
TopLeftCornerSymbol,
Expand Down

0 comments on commit 5e62176

Please sign in to comment.