Parsing support for the :only-child pseudo.

This commit is contained in:
Yorick Peterse 2014-11-03 23:27:56 +01:00
parent 759bb71d17
commit 2cf058457d
2 changed files with 21 additions and 0 deletions

View File

@ -532,6 +532,15 @@ end
return s(:eq, s(:call, 'position'), s(:call, 'last'))
end
##
# Generates the AST for the `:only-child` selector.
#
# @return [AST::Node]
#
def on_pseudo_class_only_child
return s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child)
end
private
##

View File

@ -0,0 +1,12 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':only-child pseudo class' do
example 'parse the :only-child pseudo class' do
parse_css(':only-child').should == parse_xpath(
'descendant-or-self::*[count(preceding-sibling::*) = 0 ' \
'and count(following-sibling::*) = 0]'
)
end
end
end