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

[CssSelector] add support for :is() and :where() #48803

Open
wants to merge 6 commits into
base: 6.3
Choose a base branch
from

Conversation

Jean-Beru
Copy link
Contributor

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #48772
License MIT
Doc PR symfony/symfony-docs#17628

This PR adds support for :is() and :where() pseudo-classes.

@Jean-Beru Jean-Beru force-pushed the css-selector/add-is-and-where branch 2 times, most recently from d56aef3 to b71d1b6 Compare Dec 30, 2022
@fabpot
Copy link
Member

fabpot commented Dec 30, 2022

You should rebase instead of merging 6.3

@Jean-Beru Jean-Beru force-pushed the css-selector/add-is-and-where branch from 8f4129d to 8872ef6 Compare Dec 30, 2022
@Jean-Beru Jean-Beru force-pushed the css-selector/add-is-and-where branch from 8872ef6 to 26eefb3 Compare Dec 30, 2022
@Jean-Beru
Copy link
Contributor Author

My bad, I used the GitHub UI to resolve conflicts 🤦‍♂️

src/Symfony/Component/CssSelector/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/CssSelector/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/CssSelector/CHANGELOG.md Outdated Show resolved Hide resolved
@@ -46,9 +46,10 @@ public function getElement(): string
/**
* @return $this
*/
public function addCondition(string $condition): static
public function addCondition(string $condition/* , string $conjunction = 'and' */): static
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is internal as well, can't we add the new argument directly?

Copy link
Member

Choose a reason for hiding this comment

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

Internal classes are not covered by the BC policy, so we can add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. Update done.


public function getSpecificity(): Specificity
{
return new Specificity(0, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Does this class represent <selector>:where(<subSelectorList>) or just :where(<subSelectorList>) ? The specificity is 0 only in the second case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class includes the selector. I made changes to add selector specificity.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, this looks broken in the Python library as well.

) {
}

public function getSpecificity(): Specificity
Copy link
Member

Choose a reason for hiding this comment

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

Does this class represent <selector>:is(<subSelectorList>) or only :is(<subSelectorList>) ? In the first case, the specificity of <selector> needs to be taken into account

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class includes the selector. I made changes to add selector specificity.

@@ -34,7 +34,7 @@ public function __construct(

public function getSpecificity(): Specificity
{
return new Specificity(0, 0, 0);
return $this->selector->getSpecificity()->plus(new Specificity(0, 0, 0));
Copy link
Member

Choose a reason for hiding this comment

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

this could be simplified as return $this->selector->getSpecificity();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed !


public function getSpecificity(): Specificity
{
return new Specificity(0, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Btw, this looks broken in the Python library as well.

@@ -46,9 +46,9 @@ public function getElement(): string
/**
* @return $this
*/
public function addCondition(string $condition): static
public function addCondition(string $condition, string $conjunction = 'and'): static
Copy link
Member

Choose a reason for hiding this comment

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

the argument should be named operator, not conjuction. When using or, you create a disjunction.

{
$arguments = [];
while (true) {
[$result, $pseudoElement] = $this->parseSimpleSelector($stream, true);
Copy link
Member

Choose a reason for hiding this comment

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

The naming in this parser is confusing. parseSimpleSelector is not parsing a simple selector but a compound selector. However, this is still wrong for the parsing of is and where. They take a selector list, i.e. a list of complex selectors, not of compound selectors (see https://www.w3.org/TR/selectors-4/#structure for the terminology)

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.

[CssSelector] Add support for :is() and :where()
6 participants