Skip to content

package : selector specificity - #352

Merged
romainmenke merged 4 commits into
mainfrom
package-selector-specificity--amiable-norfolk-terrier-611d67382d
Apr 26, 2022
Merged

package : selector specificity#352
romainmenke merged 4 commits into
mainfrom
package-selector-specificity--amiable-norfolk-terrier-611d67382d

Conversation

@romainmenke

@romainmenke romainmenke commented Apr 26, 2022

Copy link
Copy Markdown
Member

I wanted to add more tests and some docs for the specificity calculations.
This was non-trivial when the code was embedded in plugins.

I also looked around again but didn't find any existing package that does this without also having a compromise I do not want to make (like adding another parser)

Extracting this into its own package and publishing this will be best.


import parser from 'postcss-selector-parser';
import selectorSpecificity from '@csstools/selector-specificity';

const selectorAST = parser().astSync('#foo:has(> .foo)');
const specificity = selectorSpecificity(selectorAST);

console.log(specificity.a); // 1
console.log(specificity.b); // 1
console.log(specificity.c); // 0

@romainmenke
romainmenke marked this pull request as draft April 26, 2022 11:37
@romainmenke
romainmenke marked this pull request as ready for review April 26, 2022 12:05

@Antonio-Laguna Antonio-Laguna left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great!

Thanks for all of the tests too!

@romainmenke
romainmenke merged commit ae7bd5f into main Apr 26, 2022
@romainmenke
romainmenke deleted the package-selector-specificity--amiable-norfolk-terrier-611d67382d branch April 26, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants