Parsing support for the :first-child pseudo class.

This commit is contained in:
Yorick Peterse 2014-11-03 22:45:00 +01:00
parent 020d979fba
commit b4fec3cc8c
2 changed files with 24 additions and 0 deletions

View File

@ -488,6 +488,19 @@ end
return node
end
##
# Generates the AST for the `:first-child` selector.
#
# @return [AST::Node]
#
def on_pseudo_class_first_child
return s(
:eq,
s(:call, 'count', s(:axis, 'preceding-sibling', s(:test, nil, '*'))),
s(:int, 0)
)
end
private
##

View File

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