Skip to content

SCSS Selector List with Comments loses code, causes syntax error #2686

Closed

Description

@Kerrick

Playground Link

Input:

.field {
  &[data-field-id="1"], // Name
  &[data-field-id="2"], // Email
  &[data-field-id="3"], // Postal Code
  {
    background: green;
  }
}

Output:

.field {
  &[data-field-id="1"],
  // Name &[data-field-id="2"],
  // Email &[data-field-id="3"] {
    background: green;
  }
}

This is a serious problem, as it is invalid CSS syntax and comments out many of the selectors.

Activity

  1. changed the title [-][1.6.0] CSS Selector List with Comments loses code, causes syntax error[/-] [+][1.6.0] SCSS Selector List with Comments loses code, causes syntax error[/+] on Aug 28, 2017
  2. added
    priority:high
    on Aug 28, 2017
  3. changed the title [-][1.6.0] SCSS Selector List with Comments loses code, causes syntax error[/-] [+]SCSS Selector List with Comments loses code, causes syntax error[/+] on Aug 28, 2017
  4. vjeux commented on Aug 28, 2017

    @vjeux
    Contributor

    This is not a 1.6 issue, this has been an issue ever since we shipped support for CSS. We need to fix it at some point, thanks for the report!

  5. jackyho112 commented on Sep 1, 2017

    @jackyho112
    Contributor

    @vjeux

    Should it be printed as

    .field {
      // Name
      &[data-field-id="1"], 
      // Email
      &[data-field-id="2"], 
      // Postal Code
      &[data-field-id="3"] {
        background: green;
      }
    }
    

    ?

    Also, doesn't seem like postcss with the scss plugin specifically handles inline comments written on the same line as a rule or a selector.

    I guess to fix this, we will have to handle this kind of cases on our own?

  6. added
    lang:css/scss/less
    on Oct 1, 2017
  7. dcalhoun commented on Nov 21, 2017

    @dcalhoun

    Below is a slightly different example I use often that suffers similar issues.

    Input

    /**
     * 1. Footnote number one.
     * 2. Footnote number two
     */
    .VideoPlayer .vjs-big-play-button::before, /* 2 */
    .VideoPlayer .vjs-icon-placeholder::before {
      line-height: 1.88; /* 1 */
    }

    Output

    /**
     * 1. Footnote number one.
     * 2. Footnote number two
     */
    .VideoPlayer .vjs-big-play-button::before,
    /* 2 */ .VideoPlayer .vjs-icon-placeholder::before {
      line-height: 1.88; /* 1 */
    }
  8. j-f1 commented on Jan 24, 2018

    @j-f1
    Member

    Current status:

    Prettier 1.10.2
    Playground link

    --arrow-parens 
    --parser scss
    --prose-wrap 

    Input:

    .field {
      &[data-field-id="1"], // Name
      &[data-field-id="2"], // Email
      &[data-field-id="3"], // Postal Code
      {
        background: green;
      }
    }

    Output:

    .field {
      &[data-field-id="1"], // Name
      &[data-field-id="2"], // Email
      &[data-field-id="3"], {
        background: green;
      }
    }
    

    One of the comments is eaten, but the syntax is valid now.

  9. added
    area:comments
    on Jan 24, 2018
  10. alexander-akait commented on Jan 24, 2018

    @alexander-akait
    Member
  11. alexander-akait commented on Feb 7, 2018

    @alexander-akait
    Member

    We fix this, but we have open issue about best place for comments, please see #3905

  12. j-f1 commented on Feb 7, 2018

    @j-f1
    Member

    Status after PR:

    Prettier pr-3909
    Playground link

    --parser scss

    Input:

    .field {
      &[data-field-id="1"], // Name
      &[data-field-id="2"], // Email
      &[data-field-id="3"], // Postal Code
      {
        background: green;
      }
    }

    Output:

    .field {
      &[data-field-id="1"], // Name
      &[data-field-id="2"], // Email
      &[data-field-id="3"], // Postal Code
     {
        background: green;
      }
    }
    
  13. added
    locked-due-to-inactivity
    on Jul 5, 2018
  14. locked as resolved and limited conversation to collaborators on Jul 5, 2018
  15. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentslang:css/scss/lesslocked-due-to-inactivitypriority:high

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions