From 6daa3e7a00cd2442117569544860c8ae245dcc4b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 14 Nov 2014 23:51:46 +0100 Subject: [PATCH] Reverted AST changes for first-of-type Functions can't be used in combination with axes, so I'll just need to fix the position() function to work properly. --- lib/oga/css/parser.y | 6 +----- spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 09e5b56..b7f5e8f 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -515,11 +515,7 @@ end # @return [AST::Node] # def on_pseudo_class_first_of_type - return s( - :eq, - s(:call, 'count', s(:axis, 'preceding-sibling', s(:call, 'name'))), - s(:int, 0) - ) + return s(:eq, s(:call, 'position'), s(:int, 1)) end ## diff --git a/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb b/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb index ae88987..97a70a5 100644 --- a/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb +++ b/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb @@ -4,13 +4,13 @@ describe Oga::CSS::Parser do context ':first-of-type pseudo class' do example 'parse the :first-of-type pseudo class' do parse_css(':first-of-type').should == parse_xpath( - 'descendant::*[count(preceding-sibling::name()) = 0]' + 'descendant::*[position() = 1]' ) end example 'parse the a:first-of-type pseudo class' do parse_css('a:first-of-type').should == parse_xpath( - 'descendant::a[count(preceding-sibling::name()) = 0]' + 'descendant::a[position() = 1]' ) end end