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(deps): update dependency css-selector-parser to v2 #1759

Merged
merged 3 commits into from
Jun 16, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Jun 13, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
css-selector-parser 1.4.1 -> 2.2.3 age adoption passing confidence

Release Notes

mdevils/css-selector-parser

v2.2.3

Compare Source

  • Update published docs.

v2.2.2

Compare Source

v2.2.1

Compare Source

  • Update published docs.

v2.2.0

Compare Source

  • Full refactoring.
  • Switch to typescript.
  • Pre-defined CSS syntaxes were included.
  • The whole AST was documented.
Migrating from 1.x
CssSelectorParser -> createParser

In 1.x versions there was CssSelectorParser class which had to be contructed and then configured.
In 2.x versions there is createParser() function which returns a parse() function. All the configutation is passed
to createParser() params.

Before:

var CssSelectorParser = require('css-selector-parser').CssSelectorParser,
parser = new CssSelectorParser();
parser.registerSelectorPseudos('has');
parser.registerNumericPseudos('nth-child');
parser.registerNestingOperators('>', '+', '~');
parser.registerAttrEqualityMods('^', '$', '*', '~');

const selector = parser.parse('a[href^=/], .container:has(nav) > a[href]:lt($var):nth-child(5)');

After:

import {createParser} from 'css-selector-parser';

const parse = createParser({
    syntax: {
        pseudoClasses: {
            // In 1.x any pseudo-classes were accepted.
            // in 2.x parser only accepts known psuedo-classes unless `unknown: accept` was specified. 
            unknown: 'accept',
            definitions: {
                // This is a replacement for registerSelectorPseudos().
                Selector: ['has'],
                // This is a replacement for registerNumericPseudos().
                Formula: ['nth-child']
            }
        },
        // This is a replacement for registerNestingOperators().
        combinators: ['>', '+', '~'],
        attributes: {
            // This a replacement for registerAttrEqualityMods().
            // Note that equals sign ("=") is included into the operator definitions.
            operators: ['^=', '$=', '*=', '~=']
        }
    },
    // This is a replacement for enableSubstitutes()
    substitutes: true
});

const selector = parse('a[href^=/], .container:has(nav) > a[href]:lt($var):nth-child(5)');
Predefined CSS syntax definitions

You no longer need to make an extensive configuration of css-selector-parser in order to make it understand
the necessary CSS standards. You can now just define CSS/CSS selectors version directly:

import {createParser} from 'css-selector-parser';

const parse = createParser({syntax: 'css3'});

const selector = parse('a[href^=/], .container:has(nav) > a[href]:nth-child(2n + 1)::before');

Here are the pre-defined CSS standards for your disposal:

Make sure you use proper strict value

CSS selector parser in modern browsers is very forgiving. For instance, it works fine with unclosed attribute
selectors: "[attr=value". If you would like to mimic this behavior from browsers, set strict to false, i.e.:

import {createParser} from 'css-selector-parser';

const parse = createParser({syntax: 'css3', strict: false});

const selector = parse(':lang(en'); // doesn't crash
Render is now a separate export

render() method used to be a method of CssSelectorParser class. Now it can be imported directly and used.

Example:

import {createParser, render} from 'css-selector-parser';

const parse = createParser({syntax: 'progressive'});

const selector = parse('div#user-123.user:lang(en)');

console.log(render(selector)); // div#user-123.user:lang(en)
AST changes

AST had a lot of changes.

Selector

New type info.

  1. Type changed: selector -> Selector.
  2. Prop changed: selectors -> rules, also selectors contained ruleSet[], which in turn has rule field,
    and new rules contains Rule[] directly.

Before: {type: 'selector', selectors: [ {type: 'ruleSet', rule: {<RULE 1 DATA>}}, {type: 'ruleSet', rule: {<RULE 2 DATA>}} ]}.

After: {type: 'Selector', rules: [ {<RULE 1 DATA>}, {<RULE 2 DATA>} ]}.

Rule

New type info.

  1. Type changed: rule -> Rule.
  2. Prop changed: id: string -> ids: string[]. According to the CSS spec one rule may have more than 1 id,
    so #root#root is a valid selector.
  3. Prop renamed: nestingOperator -> combinator. A proper name according to CSS spec was chosen.
  4. Prop renamed: rule -> nestedRule. A proper name to indicate nesting was chosen.
  5. Prop changed: tagName: string -> tag: TagName | WildcardTag. Using explicit distinction between
    TagName (i.e. div) and WildcardTag (*), because tag name can also be * if escaped properly (\*).
  6. Prop changed: attrs -> attributes. Attribute type was changed, see below.
  7. Prop changed: pseudos -> pseudoClasses. There are pseudo-elements and pseudo-classes, now they are separated
    properly (there is a separate pseudoElement property). Pseudo class type was changed, see below.

Before:

({
    type: 'rule',
    tagName: 'div',
    id: 'user-123',
    classNames: ['user'],
    attrs: [
        {name: 'role', operator: '$=', valueType: 'string', value: 'button'}
    ],
    pseudos: [
        {name: 'lang', valueType: 'string', value: 'en'}
    ],
    nestingOperator: '>'
})

After:

({
    type: 'Rule',
    tag: {type: 'TagName', name: 'div'},
    ids: ['user-123'],
    classNames: ['user'],
    attributes: [
        {type: 'Attribute', name: 'role', operator: '$=', value: {type: 'String', value: 'button'}}
    ],
    pseudoClasses: [
        {type: 'PseudoClass', name: 'lang', value: {type: 'String', value: 'en'}}
    ],
    combinator: '>'
})
Attribute

New type info.

  1. Type introduced: Attribute.
  2. Prop value and valueType were combined to a single prop value with a field type.

All possible value types.

Example 1

Before: {name: 'role'}.

After: {type: 'Attribute', name: 'role'}.

Example 2

Before: {name: 'role', operator: '$=', valueType: 'string', value: 'button'}.

After: {type: 'Attribute', name: 'role', operator: '$=', value: {type: 'String', value: 'button'}}.

Example 3

Before: {name: 'role', operator: '=', valueType: 'substitute', value: 'var'}.

After: {type: 'Attribute', name: 'role', operator: '=', value: {type: 'Substitute', name: 'var'}}.

Pseudo Classes

New type info.

  1. Type introduced: PseudoClass.
  2. Prop value and valueType were combined to a single prop argument with a field type.

All possible argument types.

Example 1

Before: {name: 'visited'}.

After: {type: 'PseudoClass', name: 'visited'}.

Example 2

Before: {name: 'lang', valueType: 'string', value: 'en'}.

After: {type: 'PseudoClass', name: 'lang', argument: {type: 'String', value: 'en'}}.

Example 3

Before: {name: 'lang', valueType: 'substitute', value: 'var'}.

After: {type: 'PseudoClass', name: 'lang', argument: {type: 'Substitute', name: 'var'}}.

Example 4

Before: {name: 'has', valueType: 'selector', value: {type: 'selector', selectors: [{type: 'ruleSet', rule: {type: 'rule', tagName: 'div'}}]}}.

After: {type: 'PseudoClass', name: 'has', argument: {type: 'Selector', rules: [{type: 'Rule', tag: {type: 'TagName', name: 'div'}}]}}.

v2.1.0

Compare Source


Configuration

📅 Schedule: Branch creation - "after 10pm,before 5:00am" in timezone America/Vancouver, Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/css-selector-parser-2.x branch 14 times, most recently from 473c4bf to 7ee6093 Compare June 16, 2023 12:06
@renovate renovate bot force-pushed the renovate/css-selector-parser-2.x branch from 7ee6093 to 33b5964 Compare June 16, 2023 12:09
@renovate
Copy link
Contributor Author

renovate bot commented Jun 16, 2023

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

Warning: custom changes will be lost.

@mykola-mokhnach mykola-mokhnach merged commit 0426349 into master Jun 16, 2023
@mykola-mokhnach mykola-mokhnach deleted the renovate/css-selector-parser-2.x branch June 16, 2023 15:38
github-actions bot pushed a commit that referenced this pull request Jun 16, 2023
## [4.32.4](v4.32.3...v4.32.4) (2023-06-16)

### Bug Fixes

* **deps:** update dependency css-selector-parser to v2 ([#1759](#1759)) ([0426349](0426349))
@github-actions
Copy link
Contributor

🎉 This PR is included in version 4.32.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant