Skip to content

Styled-components and custom css properties #5614

@fedcho

Description

@fedcho

Prettier 1.15.3
Playground link

--parser babylon
--single-quote
--trailing-comma es5

Input:

import React from 'react';
import styled from 'styled-components';
import Card from './Card';

const StyledPurchaseCard = styled(Card)`
  min-width: 200px;
  background-color: var(--${props => props.color});
  color: #fff;
`;

Output:

import React from 'react';
import styled from 'styled-components';
import Card from './Card';

const StyledPurchaseCard = styled(Card)`
  min-width: 200px;
  background-color: var(-- ${props => props.color});
  color: #fff;
`;

Expected behavior:
Prettier should not add a space between the custom property name prefix -- and the template literal placeholder ${props => props.color}. It causes an invalid property value and the style is not applied.

import React from 'react';
import styled from 'styled-components';
import Card from './Card';

const StyledPurchaseCard = styled(Card)`
  min-width: 200px;
  background-color: var(--${props => props.color});
  color: #fff;
`;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSlang:javascriptIssues affecting JSlocked-due-to-inactivityPlease 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!

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions