Skip to content

Commit 692bb94

Browse files
committed
[CssSelector] Support *:only-of-type pseudo class selector
1 parent 1f8fa58 commit 692bb94

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.4.0
5+
-----
6+
7+
* Added support for `*:only-of-type`
8+
49
2.8.0
510
-----
611

Diff for: Tests/XPath/TranslatorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ public function getHtmlIdsTestData()
308308
['li div:only-child', ['li-div']],
309309
['div *:only-child', ['li-div', 'foobar-span']],
310310
['p:only-of-type', ['paragraph']],
311+
[':only-of-type', ['html', 'li-div', 'foobar-span', 'paragraph']],
312+
['div#foobar-div :only-of-type', ['foobar-span']],
311313
['a:empty', ['name-anchor']],
312314
['a:EMpty', ['name-anchor']],
313315
['li:empty', ['third-li', 'fourth-li', 'fifth-li', 'sixth-li']],

Diff for: XPath/Extension/PseudoClassExtension.php

-7
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,10 @@ public function translateOnlyChild(XPathExpr $xpath): XPathExpr
100100
->addCondition('last() = 1');
101101
}
102102

103-
/**
104-
* @throws ExpressionErrorException
105-
*/
106103
public function translateOnlyOfType(XPathExpr $xpath): XPathExpr
107104
{
108105
$element = $xpath->getElement();
109106

110-
if ('*' === $element) {
111-
throw new ExpressionErrorException('"*:only-of-type" is not implemented.');
112-
}
113-
114107
return $xpath->addCondition(sprintf('count(preceding-sibling::%s)=0 and count(following-sibling::%s)=0', $element, $element));
115108
}
116109

0 commit comments

Comments
 (0)