Fixed CSS evaluation of :first-of-type

The old XPath "position() = 1" would work in Nokogiri due to the way they
retrieve descendants. In Oga however this would simply always return the first
node.

To fix this Oga now counts the amount of preceding siblings that match the same
full name.
This commit is contained in:
Yorick Peterse committed 2014-11-14 01:25:03 +01:00
1 parent e3a26c5d15
commit 0128dc50ae
3 files changed
+28 -15

No files matched your search

+5 -1
View File
@@ -515,7 +515,11 @@ end
# @return [AST::Node]
#
def on_pseudo_class_first_of_type
return s(:eq, s(:call, 'position'), s(:int, 1))
return s(
:eq,
s(:call, 'count', s(:axis, 'preceding-sibling', s(:call, 'name'))),
s(:int, 0)
)
end
##