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

Minifier: Merging classes with the same name #50

Closed
Marabyte opened this issue Jan 14, 2022 · 2 comments
Closed

Minifier: Merging classes with the same name #50

Marabyte opened this issue Jan 14, 2022 · 2 comments

Comments

@Marabyte
Copy link
Contributor

Marabyte commented Jan 14, 2022

I'm not sure if this is a bug or feature.

/*Input*/
.a { font-size: large; }
#b { color: aqua; }
.a { padding: 0.5rem; }
/*Output*/
.a{font-size:large}#b{color:#0ff}.a{padding:.5rem}

But if we have the same class adjacent to each other

/*Input*/
#b { color: aqua; }
.a { font-size: large; }
.a { padding: 0.5rem; }
/*Output*/
#b{color:#0ff}.a{padding:.5rem;font-size:large}

I would expect both inputs to produce the same output (the second one).

@devongovett
Copy link
Member

devongovett commented Jan 14, 2022

In general, merging non-adjacent selectors is not safe due to specificity. For example:

<div class="a b">hi</div>
<style>
.a { color: green; }
.b { color: aqua; }
.a { color: red; }
</style>

In this example, the div should have red text. But if the .a selectors were merged, it would be aqua.

In your specific example, the id selector has a higher specificity than the class selectors, so it could potentially work. But tracking whether there are only higher specificity selectors between two matching selectors seems hard and likely not worth it.

@Marabyte
Copy link
Contributor Author

Yeah, this can become a nightmare to track.
Thank you for the brilliant work!

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

No branches or pull requests

2 participants