Taritsyn / BundleTransformer

Bundle Transformer - a modular extension for System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework).
Apache License 2.0
130 stars 19 forks source link

MicrosoftAjaxCssMinifier does not support CSS :has() pseudo-class #78

Closed leandrodeopereira closed 10 months ago

leandrodeopereira commented 1 year ago

Hello,

I'm currently using BundleTransformer in an ASP.NET project and have come across an issue with the MicrosoftAjaxCssMinifier.

Here is the usage of BundleTransformer in my project:

bundles.Add(new CustomStyleBundle("~/bundles/SampleStyles").Include(
    "~/App/Sample.less"
));

And the BundleTransformer configuration:

<css defaultMinifier="MicrosoftAjaxCssMinifier">
  <translators>
    <add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
    <add name="LessTranslator" type="BundleTransformer.Less.Translators.LessTranslator, BundleTransformer.Less" />
  </translators>
  <postProcessors>
    <add name="UrlRewritingCssPostProcessor" type="BundleTransformer.Core.PostProcessors.UrlRewritingCssPostProcessor, BundleTransformer.Core" useInDebugMode="false" />
  </postProcessors>
  <minifiers>
    <add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
    <add name="MicrosoftAjaxCssMinifier" type="BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxCssMinifier, BundleTransformer.MicrosoftAjax" />
  </minifiers>
  <fileExtensions>
    <add fileExtension=".css" assetTypeCode="Css" />
    <add fileExtension=".less" assetTypeCode="Less" />
  </fileExtensions>
</css>

When trying to minify CSS code with MicrosoftAjaxCssMinifier that includes the :has() pseudo-class, it throws the following error:

BundleTransformer.Core.Minifiers.AssetMinificationException: During minification of CSS-code, readed from the file '/App/Sample.less', by Microsoft Ajax CSS-minifier syntax error has occurred. 
See more details:Message: Expected identifier, found ':'
Error code: CSS1030
Severity: 0
Subcategory: run-time
File: /App/Sample.less
Start line: 118
Start column: 18
End line: 0
End column: 0 ---> BundleTransformer.MicrosoftAjax.MicrosoftAjaxParsingException: Message: Expected identifier, found ':'
Severity: 0
Subcategory: run-time
File: /App/Sample.less
Start line: 118
Start column: 18
End line: 0
End column: 0
   at void BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxCssMinifier.ParserErrorHandler(object source, ContextErrorEventArgs args)
   at void Microsoft.Ajax.Utilities.CssParser.OnCssError(ContextError cssError)
   at Parsed Microsoft.Ajax.Utilities.CssParser.ParsePseudo()
   at Parsed Microsoft.Ajax.Utilities.CssParser.ParseSimpleSelector()
   at Parsed Microsoft.Ajax.Utilities.CssParser.ParseSelector()
   at Parsed Microsoft.Ajax.Utilities.CssParser.ParseRule()
   at Parsed Microsoft.Ajax.Utilities.CssParser.ParseStylesheet()
   at string Microsoft.Ajax.Utilities.CssParser.Parse(string source)
   at void BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxCssMinifier.InnerMinify(IAsset asset, CssParser cssParser)
   --- End of inner exception stack trace ---

Would it be possible to consider supporting the :has() pseudo-class and other newer CSS features in MicrosoftAjaxCssMinifier to prevent minification errors or am I missing something here?

Thanks for the help.

Taritsyn commented 1 year ago

Hello, Leandro!

Microsoft Ajax Minifier and YUI Compressor for .NET libraries have been deprecated, so it is recommended to replace the BundleTransformer.MicrosoftAjax and BundleTransformer.Yui modules with the BundleTransformer.NUglify module.