diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index d71f272..2d270e2 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -581,7 +581,7 @@ end # @return [AST::Node] # def on_pseudo_class_only_of_type - return s(:eq, s(:call, 'last'), s(:int, 1)) + return s(:and, on_pseudo_class_first_of_type, on_pseudo_class_last_of_type) end ## diff --git a/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb b/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb index 3e09a78..8a4c89c 100644 --- a/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb +++ b/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb @@ -4,7 +4,15 @@ describe Oga::CSS::Parser do context ':only-of-type pseudo class' do example 'parse the :only-of-type pseudo class' do parse_css(':only-of-type').should == parse_xpath( - 'descendant::*[last() = 1]' + 'descendant::*[count(preceding-sibling::*) = 0 and ' \ + 'count(following-sibling::*) = 0]' + ) + end + + example 'parse the a:only-of-type pseudo class' do + parse_css('a:only-of-type').should == parse_xpath( + 'descendant::a[count(preceding-sibling::a) = 0 and ' \ + 'count(following-sibling::a) = 0]' ) end end