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

CrockfordJsMinifier: RegEx in Js fail to minify unless end with g #80

Closed VisualMicro closed 9 months ago

VisualMicro commented 9 months ago

We have a number of regex expressions that cause the JsMin to fail.

For example we have a pattern as below which causes the minifier to fail

/^[^\s-!@#$%^&()_+{}[]:;<>,.?~\/-]([^\s-!@#$%^&*()+{}[]:;<>,.?~\/-])$/

But the minifier works if we add the trailing "g"

pattern: /^[^\s-!@#$%^&()_+{}[]:;<>,.?~\/-]([^\s-!@#$%^&*()+{}[]:;<>,.?~\/-])$/g

Does anyone have any suggestions for a fix or a workaround?

Thank you

VisualMicro commented 9 months ago

I think I found a solution. The regex appears to work if it is set into a variable and then used in a json structure. for example

The regex must also have a trailing semi colon...

var vreg = /^[^\s-!@#$%^&()_+{}[]:;<>,.?~\/-]([^\s-!@#$%^&*()+{}[]:;<>,.?~\/-])$/;

{ foo: "baa", pattern: vreg, }

This fails to minify:-

{ foo: "baa", pattern: /^[^\s-!@#$%^&()_+{}[]:;<>,.?~\/-]([^\s-!@#$%^&*()+{}[]:;<>,.?~\/-])$/, }