keeganstreet / specificity

A JavaScript module for calculating the specificity of CSS selectors
MIT License
624 stars 39 forks source link

Fix a parse error on ie8. #25

Closed jhaines closed 4 years ago

jhaines commented 8 years ago

Currently, when trying to load specificity in ie8, the script will fail to parse due to this line of regex: var regex = /{[^]*/gm,

Changing from literal to constructor notation allows the script to be parsed on ie8.

Note that this is not intended to make the script work on ie8, but at least it won't throw an error while loading the file.

keeganstreet commented 8 years ago

Hi @jhaines,

I would like to keep the notation of the regular expressions in this code base consistent. I am using the literal notation for the other ones, so I don't want to change this one to constructor notation.

However, maybe we can address the parse error by escaping the left brace. And also I don't see why I used [^]* instead of .*. We could probably change that whole regex to /\{.*/gm. But I haven't tested this yet.

jhaines commented 8 years ago

Hi @keeganstreet, At the moment, [^]* captures all characters including newlines, so I'd say that .* won't be enough.

Instead, I've updated the pull request with a non-capturing group that includes newlines, so it should match the existing expression while also fixing the parse error on ie8.

Not sure if the tests are currently expansive enough to prove that this isn't a breaking change, though.

Cheers, Josh