-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[styled-components] Using expression inside template literal along with attribute selector results in invalid CSS syntax. #4520
Copy link
Copy link
Closed
Labels
area:multiparserIssues with printing one language inside another, like CSS-in-JSIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSIssues affecting CSS, Less or SCSSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!
Description
Styling component based on the attribute state of its neighbour element results in invalid CSS markup. Space is being added between expression and attribute selector. It happens only when styled-components are being used with their default "styled" alias. Using any other name seem to cause prettier ignore insides of template literals.
It' quite a border use case, but unfortunately it results in broken CSS syntax not recognised by browser engine.
Prettier 1.12.1
Playground link
Input:
const x = styled.div``;
const a = anything.anything`
${x}[value=true] + & {
}
`;
const b = styled.anything`
${x}[value=true] + & {
}
`;Output:
const x = styled.div``;
const a = anything.anything`
${x}[value=true] + & {
}
`;
const b = styled.anything`
${x} [value=true] + & {
}
`;Expected behavior:
const x = styled.div``;
const a = anything.anything`
${x}[value=true] + & {
}
`;
const b = styled.anything`
${x}[value=true] + & {
}
`;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:multiparserIssues with printing one language inside another, like CSS-in-JSIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSIssues affecting CSS, Less or SCSSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!