Skip to content

Declarations in wrong specificity order #92

Closed

Description

@jednano

Steps to reproduce

Run postcss-cli with the following command:

postcss test.css -u postcss-nested

Given the following input from test.css:

.a {
  .b {
    c: d;
    &e {
      f: g
    }
    h: i
  }
}

I am given the following output:

.a .b {
    c: d;
    h: i;
  }
    .a .be {
      f: g
    }

Issues

  1. Both rules .a .b and .a .be have the same specificity, so the h: i declaration should come at the very end in a new .a .b rule, based on the order in which declarations were originally defined (not how Sass does it, but more accurate).
  2. The h: i declaration was given a semi-colon that it didn't previously have. This might be an issue with the structure of the AST raws, as the rule defines the semi-colon and not the declaration?
  3. All rule indentation should be at the root of the document (definitely how Sass does it).
  4. Sending the AST directly through postcss-nested doesn't completely unwrap the rules. I have to call the plugin multiple times to get complete unwrapping. If I have rules nested 4 levels deep, I have to call the plugin 4x!

For the last issue, this is what I was doing from within a custom plugin:

const nested = postcssNested();
return (root, result) => {
  // do stuff
  nested(root, result);
};

Also, hi @ai! 👋 Long time, no see!

Activity

  1. ai commented on Jun 7, 2020

    @ai
    Member
    1. Both rules .a .b and .a .be have the same specificity, so the h: i declaration should come at the very end in a new .a .b rule, based on the order in which declarations were originally defined (not how Sass does it, but more accurate).

    Yeap, let’s fix it. Can you send PR, because I am working on another project right now?

    1. The h: i declaration was given a semi-colon that it didn't previously have.
    2. All rule indentation should be at the root of the document (definitely how Sass does it).

    I decided that postcss-nested will not take care bout good formation. It is hard and most of the users will even not see this.

    It could increase code 2x-3x times, especially if we will take care of all use cases.

    1. Sending the AST directly through postcss-nested doesn't completely unwrap the rules. I have to call the plugin multiple times to get complete unwrapping. If I have rules nested 4 levels deep, I have to call the plugin 4x!

    It is very strange because PostCSS itself does exactly the same nested(root, result) call.

    Can you create a simple test stand to reproduce the issue?

    Also, hi @ai! wave Long time, no see!

    Nice to see you again =^_^=. I started to use TypeScript in some of my projects. Also, I am planning to visit Austin in August.

  2. jednano commented on Jun 8, 2020

    @jednano
    Author
    1. I can't, actually.
    2. In hindsight, I agree.
    3. Agreed.
    4. I figured out that the culprit was my plugin when I converted at-rules into rules w/o using newRule.append. Turns out you also can't loop through container.nodes, which is what I was doing as well. Would love a generator method so I can do for (const node of rule.nodes()), because then I can continue and break and even yield if I wanted to.

    I sent you an email with my phone number for when you come to Austin 😃

  3. changed the title [-]Declarations in wrong order, extra semi, indentation, multiple passes[/-] [+]Declarations in wrong specificity order[/+] on Jun 8, 2020
  4. ai commented on Jul 4, 2020

    @ai
    Member
  5. jednano commented on Jul 4, 2020

    @jednano
    Author
  6. demikhovr commented on Jul 4, 2020

    @demikhovr
    Contributor

    Hi, I created PR #93

  7. ai commented on Jul 4, 2020

    @ai
    Member

    The fix by @demikhovr was released in 4.2.2

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions