Skip to content

[styled-components] Comments following interpolations are duplicated #5381

@jacobwgillespie

Description

@jacobwgillespie

If a standalone Styled Components interpolation is following by a CSS comment, the CSS comment is duplicated in the resulting output.

Prettier 1.15.1

Playground link

# Options (if any): none / defaults

Input:

const StyledComponent = styled.div`
  ${anInterpolation}

  /* a comment */

  .aRule {
    color: red
  }
`;

Output:

const StyledComponent = styled.div`
  ${anInterpolation}

  /* a comment */

  /* a comment */

  .aRule {
    color: red;
  }
`;

Each subsequent format will continue to duplicate all comments, for example formatting that output again results in the following (playground link):

const StyledComponent = styled.div`
  ${anInterpolation}

  /* a comment */

  /* a comment */

  /* a comment */

  /* a comment */

  .aRule {
    color: red;
  }
`;

Expected behavior:

const StyledComponent = styled.div`
  ${anInterpolation}

  /* a comment */

  .aRule {
    color: red;
  }
`;

Adding a semicolon to the end of the interpolation results in the expected behavior:

-  ${anInterpolation}
+  ${anInterpolation};

However I don't believe a semicolon should be required in this case, given that the interpolation could be the result of a call to css or other similar multi-rule mixins.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentsarea:multiparserIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions