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

Support for CSS variables #46

Merged
merged 4 commits into from
Apr 5, 2018
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/Selectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,11 @@ public void Any()
{
TestHelper.Instance.RunTest();
}

[Test]
public void Bootstrap4CssVariables()
{
TestHelper.Instance.RunTest();
}
}
}
6 changes: 6 additions & 0 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,15 @@
<Content Include="TestData\CSS\Expected\AtRules\RazorEscapedDoubleAt.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Expected\Selectors\Bootstrap4CssVariables.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Input\AtRules\RazorEscapedDoubleAt.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\CSS\Input\Selectors\Bootstrap4CssVariables.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\ControlFlow\BreakNoLabel.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
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
@@ -0,0 +1,30 @@
:root {
--blue: #007bff;
--indigo: #6610f2;
--purple: #6f42c1;
--pink: #e83e8c;
--red: #dc3545;
--orange: #fd7e14;
--yellow: #ffc107;
--green: #28a745;
--teal: #20c997;
--cyan: #17a2b8;
--white: #fff;
--gray: #6c757d;
--gray-dark: #343a40;
--primary: #007bff;
--secondary: #6c757d;
--success: #28a745;
--info: #17a2b8;
--warning: #ffc107;
--danger: #dc3545;
--light: #f8f9fa;
--dark: #343a40;
--breakpoint-xs: 0;
--breakpoint-sm: 576px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
--font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
3 changes: 2 additions & 1 deletion src/NUglify.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
},
"dependencies": {
"NUnit": "3.5.0"
"NUnit": "3.5.0",
"NUnit3TestAdapter": "3.5.0"
}
}
7 changes: 7 additions & 0 deletions src/NUglify/Css/CssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,13 @@ private bool Append(object obj, TokenType tokenType)
// for identifiers, if the first character is a hyphen or an underscore, then it's a prefix
// and we want to look at the next character for nmstart.
firstIndex = text[0] == '_' || text[0] == '-' ? 1 : 0;

var isCssVariable = text.StartsWith("--") && text.Length >= 3;
if (isCssVariable)
{
firstIndex = 2;
}

if (firstIndex < text.Length)
{
// the only valid non-escaped first characters are A-Z (and a-z)
Expand Down
1 change: 1 addition & 0 deletions src/NUglify/Css/CssScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ private string GetNmStart()
{
if (IsNonAscii(m_currentChar)
|| (m_currentChar == '_')
|| (m_currentChar == '-') // CSS variables start with double dash
|| ('a' <= m_currentChar && m_currentChar <= 'z')
|| ('A' <= m_currentChar && m_currentChar <= 'Z'))
{
Expand Down