Skip to content

[TASK] Add CompoundSelector class - #1488

Merged
oliverklee merged 3 commits into
mainfrom
task/compound-selector
Feb 4, 2026
Merged

[TASK] Add CompoundSelector class#1488
oliverklee merged 3 commits into
mainfrom
task/compound-selector

Conversation

@JakeQZ

@JakeQZ JakeQZ commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator

Part of #1325.

@JakeQZ JakeQZ self-assigned this Feb 1, 2026
@JakeQZ JakeQZ added enhancement refactor For PRs that refactor code without changing functionality labels Feb 1, 2026
@coveralls

coveralls commented Feb 1, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 72.97% (+1.2%) from 71.792%
when pulling 8247d8b on task/compound-selector
into 34df8f9 on main.

@JakeQZ

JakeQZ commented Feb 3, 2026

Copy link
Copy Markdown
Collaborator Author

Marking as 'draft' for now, as will need to include changes from #1485.

@JakeQZ
JakeQZ marked this pull request as draft February 3, 2026 02:13
@JakeQZ
JakeQZ force-pushed the task/compound-selector branch 4 times, most recently from fa8cc89 to 86a8bbf Compare February 4, 2026 21:21
@JakeQZ
JakeQZ marked this pull request as ready for review February 4, 2026 21:21
@JakeQZ
JakeQZ force-pushed the task/compound-selector branch from 86a8bbf to 328481e Compare February 4, 2026 21:22
@JakeQZ

JakeQZ commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator Author

This now includes the changes from #1485 (parsing functionality is duplicated, but the duplication will eventually be removed from Selector when that is changed to use the new classes instead of a string), and is ready for review.

@oliverklee oliverklee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks generally very good! Just some nits.

Also, this should get a changelog entry (and maybe we can add the changelog entry for #1487 as well while we're at it).

$selectorParts = [];
$stringWrapperCharacter = null;
$functionNestingLevel = 0;
static $stopCharacters = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to move this to a class constant instead? (In general, I'm not a big fan of static local variables as these are not constant and hence might introduce hidden state.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

My thinking was that having them in the method makes it easier to check that the cases in the switch statement cover them all. There are arguments either way; I've moved them to a constant.

{
return [
'escaped double quote in double-quoted attribute' => ['a[href="test\\"value"]'],
'escaped single quote in single-quoted attribute' => ['a[href=\'test\\\'value\']'],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For the cases with escaped single quotes, I propose we use double quotes for the string itself, which would reduce additional quoting and make the data easier to read (for humans).

@JakeQZ JakeQZ Feb 4, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've changed the represntation of the strings that contain only single quotes.

I read somewhere that using double quotes to enclose strings no longer has any impact on performance. If that's true, it may even be the case that using double quotes to enclose strings containing single quotes improves performance, since the interpreter doesn't have to deal with unescaping.

@JakeQZ

JakeQZ commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator Author

Also, this should get a changelog entry (and maybe we can add the changelog entry for #1487 as well while we're at it).

I was planning to do that when the new classes are actually used in the Selector representation (and can reference these PRs in the changelog entry at that time). At the moment they are just spare parts.

@JakeQZ
JakeQZ requested a review from oliverklee February 4, 2026 23:15
@oliverklee
oliverklee merged commit 2f99028 into main Feb 4, 2026
24 checks passed
@oliverklee
oliverklee deleted the task/compound-selector branch February 4, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement refactor For PRs that refactor code without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants