-
Notifications
You must be signed in to change notification settings - Fork 68
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
BEM + pseudo trips up custom var extraction: .a--b:hover{} #31
Comments
Update: it seems the problem isn't BEM alone. The Here's another test: const dropcss = require('dropcss');
let html = `
<html>
<head></head>
<body>
<div class="anything">anything 1</div>
<div class="anything anything--modified">anything 2</div>
</body>
</html>
`;
let css = `
:root {
--main-color: deeppink;
}
.anything {
display: inline-flex;
background: var(--main-color);
}
.anything::before {
color: deepskyblue;
}
.anything--modified {
color: crimson;
}
.anything--modified::before {
color: tomato;
}
.anything--modified::after {
color: papayawhip;
}
`;
let cleaned = dropcss({
html,
css,
});
console.log(cleaned);
/*
{ css:
':root{--main-color: deeppink;}.anything{display: inline-flex;\n background: var(--main-color);}.anything::before{color: deepskyblue;}.anything--modified{color: crimson;}.anything}.anything}',
sels:
Set {
':root', '.anything',
'.anything::before',
'.anything--modified',
'.anything--modified::before',
'.anything--modified::after' } }
*/ Again, the final I'm not sure if this is the appropriate fix or not, but adding a negative-lookbehind (how to do this in JS?) for any word-char seems hone the regex to only CSS vars (because CSS vars should always begin with Original CUSTOM_PROP_DEF regex: https://regex101.com/r/0sb17w/2 |
hey @saltymouse thanks for the repro and diagnosis.
lookbehinds are pretty new in js: https://caniuse.com/#feat=js-regexp-lookbehind, so i'd prefer not to use them. we can probably get away with just capturing any non-word char at the start of the match via wanna give it a go? |
actually |
ok, this should be fixed now. i tried both of your cases in https://codepen.io/leeoniya/pen/LvbRyq and they work as expected. |
Awesome—thanks for the quick response. I upgraded to the |
Seems like there's some trouble parsing BEM selectors, namely the
--modifier
bit.Formatted CSS to more clearly see what's going on:
dropcss version:
1.0.12
node version:
10.16.0
The text was updated successfully, but these errors were encountered: