Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(merge-rules): don't change specificity of prefixed properties #723

Merged

Conversation

clshortfuse
Copy link
Contributor

fixes #717

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 99.104% when pulling 535933f on clshortfuse:fix/mergerules-avoidvendoroverride into cdedda7 on cssnano:master.

@clshortfuse
Copy link
Contributor Author

This is a pretty significant change. It essentially a rewrite of the merging function. The logic is mostly the same save for some optimizations.

  • Instead of converting the postCss.Rule nodes to string, the code now directly uses the postCss.Declaration class. It helps a bit with type-checking and ensure we're using the right objects. It also avoids a couple of string concatenation and manipulation functions.
  • Instead of iterating through all of the declarations in the first rule in reverse, we iterate through the collected set of intersections. Each intersected declaration is then compared against the first rule's declarations and any rule with a later override/conflict (based on property name) is filtered out.
  • After, instead of iterating through all declarations inside second rule, we iterate through the previously filtered intersections. For each intersected declaration, we filter, in order, those that do not appear in the same order as in the second rule's declarations, based on the declaration's base property name (without prefixes).

This allows use to safely merge new rulesets, such as:

.a{
  transform:scaleY(1);
  -webkit-transform:scaleX(-1)
}
.b{
  -webkit-transform:scaleX(-1);
  transform:scaleY(1)
}

Here, -webkit-transform:scaleX(-1) could safely be merged together, despite both having other transform rules.

Also, we can now merge this:

  .a{ display:block }
  .b{ display:block }
  .c{ display:block; display:inline-block}

Previously, the algorithm wouldn't break apart the display rules in .c because it wasn't analyzing the rule order. Now, the result would be: .a,.b,.c{display:block} .c{display:inline-block};

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, thanks for helping, maybe you can help with other issues? Just don't have time on this right now, anyway thanks again

@alexander-akait alexander-akait merged commit 863cf2b into cssnano:master Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mergeRules can change order of properties when it matters
3 participants