Skip to content

Declarations in wrong specificity order #92

@jednano

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!

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