-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
[WIP] Preprocess CSS #25
Conversation
It doesn't have proper testing yet. This is just the result of some experimentation. :)
So for now I completed a minimal CSS parser and have a transformer that flattens it. To continue I'll need to figure out what shape the result should take on for styled-components to consume. Also I haven't quite figured out how the It's still missing a lot of testing since this is pretty much just some experimental stuff right now. Edit: An alternative approach, that is even more naïve and might or might not work, can be found in the |
I reckon the shape needs to be some sort of object that can be parsed with very little effort. Possibly we could even put in just the AST? Would that be too big possibly? |
@mxstbr I do believe that is too big. I think we want to get as close to a normal string as possible, while being able to replace Something like this: {
'&': [[ 'color: ', ';' ], props => props.color ],
'&:hover': [[ 'color: green;' ]]
} |
... Actually we can interleave this and diverge from what template strings need to do: {
'&': [ 'color: ', props => props.color, ';' ],
'&:hover': [ 'color: green;' ]
} Since we don't need to differentiate between interpolations and CSS strings anymore, this should be fine, no? |
Yeah that sounds reasonable! @geelen what do you think? |
@mxstbr Just noticed a small problem with the selector un-nesting. & {
&:hover {
}
} The nested rule here is gonna be kept as & {
> div {
}
} While the nested rule here is going to be `& {
${x => x ? '&:hover' : '> div'} {
}
}` Then we don't know whether to prepend the ancestor's selector or not :( |
It turns out that stylis.js is extremely forgiving with placeholders and really forgiving. So I might replace this with some stylis magic! ✨ We can still keep the AST parser around for when we decide to actually do static/dynamic css splitting, but for now it's totes not needed 😄 Edit: DEMO! http://www.webpackbin.com/41LPGnEDz Edit 2: Actually, I just discovered that |
Another thing 😭 inline placeholders that are placed some lines before Edit: I can solve this by appending each placeholder with a semicolon |
Closing this PR in favour of #26. That one will probably be closer to how |
Edit: Closed since the Stylis one will likely work out better
styled-components
to consumepreprocessTemplateLiterals
visitor (Very easy; can be seen in thepostcss-preprocessing
branch)