Skip to content

Commit e12a962

Browse files
committed
Add translator test
1 parent 899c929 commit e12a962

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/Symfony/Component/CssSelector/Parser/Parser.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ private function parseSelectorList(TokenStream $stream): array
107107
return $selectors;
108108
}
109109

110-
private function parserSelectorNode(TokenStream $stream, bool $insideRelation = false): Node\SelectorNode
110+
private function parserSelectorNode(TokenStream $stream): Node\SelectorNode
111111
{
112-
[$result, $pseudoElement] = $this->parseSimpleSelector($stream, false, $insideRelation);
112+
[$result, $pseudoElement] = $this->parseSimpleSelector($stream, false);
113113

114114
while (true) {
115115
$stream->skipWhitespace();
116116
$peek = $stream->getPeek();
117117

118-
if ($peek->isFileEnd() || $peek->isDelimiter([',']) || ($insideRelation && $peek->isDelimiter([')']))) {
118+
if ($peek->isFileEnd() || $peek->isDelimiter([','])) {
119119
break;
120120
}
121121

@@ -130,7 +130,7 @@ private function parserSelectorNode(TokenStream $stream, bool $insideRelation =
130130
$combinator = ' ';
131131
}
132132

133-
[$nextSelector, $pseudoElement] = $this->parseSimpleSelector($stream, false, $insideRelation);
133+
[$nextSelector, $pseudoElement] = $this->parseSimpleSelector($stream, false);
134134
$result = new Node\CombinedSelectorNode($result, $combinator, $nextSelector);
135135
}
136136

@@ -142,7 +142,7 @@ private function parserSelectorNode(TokenStream $stream, bool $insideRelation =
142142
*
143143
* @throws SyntaxErrorException
144144
*/
145-
private function parseSimpleSelector(TokenStream $stream, bool $insideNegation = false, bool $insideRelation = false): array
145+
private function parseSimpleSelector(TokenStream $stream, bool $insideNegation = false): array
146146
{
147147
$stream->skipWhitespace();
148148

@@ -156,7 +156,6 @@ private function parseSimpleSelector(TokenStream $stream, bool $insideNegation =
156156
|| $peek->isFileEnd()
157157
|| $peek->isDelimiter([',', '+', '>', '~'])
158158
|| ($insideNegation && $peek->isDelimiter([')']))
159-
|| ($insideRelation && $peek->isDelimiter([')']))
160159
) {
161160
break;
162161
}
@@ -219,13 +218,10 @@ private function parseSimpleSelector(TokenStream $stream, bool $insideNegation =
219218

220219
$result = new Node\NegationNode($result, $argument);
221220
} elseif ('has' === strtolower($identifier)) {
222-
if ($insideRelation) {
223-
throw SyntaxErrorException::nestedHas();
224-
}
225221

226222
[$combinator, $subSelector] = $this->parseRelativeNode($stream);
227-
228223
$result = new Node\RelationNode($result, $combinator,$subSelector);
224+
229225
} else {
230226
$arguments = [];
231227
$next = null;
@@ -258,7 +254,7 @@ private function parseSimpleSelector(TokenStream $stream, bool $insideNegation =
258254
}
259255
}
260256

261-
if (\count($stream->getUsed()) === $selectorStart && !$insideRelation) {
257+
if (\count($stream->getUsed()) === $selectorStart) {
262258
throw SyntaxErrorException::unexpectedToken('selector', $stream->getPeek());
263259
}
264260

src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public static function getParserTestData()
134134
['div:contains("foo")', ["Function[Element[div]:contains(['foo'])]"]],
135135
['div#foobar', ['Hash[Element[div]#foobar]']],
136136
['div:not(div.foo)', ['Negation[Element[div]:not(Class[Element[div].foo])]']],
137+
['div:has(div.foo)', ['Relation[Element[div]:has(Selector[Class[Element[div].foo]])]']],
137138
['td ~ th', ['CombinedSelector[Element[td] ~ Element[th]]']],
138139
['.foo[data-bar][data-baz=0]', ["Attribute[Attribute[Class[Element[*].foo][data-bar]][data-baz = '0']]"]],
139140
['div#foo\.bar', ['Hash[Element[div]#foo.bar]']],

src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ public static function getCssToXPathTestData()
219219
['e + f', "e/following-sibling::*[(name() = 'f') and (position() = 1)]"],
220220
['e ~ f', 'e/following-sibling::f'],
221221
['div#container p', "div[@id = 'container']/descendant-or-self::*/p"],
222-
['div:has(div.foo)', "div[count(descendant-or-self::div[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]) > 0]"],
223-
['div:has(.foo .bar)', "div[count(descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' bar ')]) > 0]"],
224-
['div:has(> .foo)', "div[count(descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]) > 0]"],
225-
['div:has(~ .foo)', "div[count(descendant-or-self::*/following-sibling::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]) > 0]"],
226-
['div:has(+ .foo)', "div[count(descendant-or-self::*/following-sibling::*[(@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')) and (position() = 1)]) > 0]"],
222+
['div:has(bar.foo)', "div[descendant-or-self::bar[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]]"],
223+
['e:has(> f)', "e[./f]"],
224+
['e:has(~ f)', "e[following-sibling::f]"],
225+
['e:has(+ f)', "e[following-sibling::*[(name() = 'f') and (position() = 1)]]"],
226+
['e:has(f)', "e[descendant-or-self::f]"],
227227
];
228228
}
229229

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy