Parsing support for the :last-of-type pseudo.

This commit is contained in:
Yorick Peterse 2014-11-03 23:01:44 +01:00
parent 10632eafd4
commit 759bb71d17
2 changed files with 22 additions and 0 deletions

View File

@ -515,12 +515,23 @@ end
end
##
# Generates the AST for the `:first-of-type` selector.
#
# @return [AST::Node]
#
def on_pseudo_class_first_of_type
return s(:eq, s(:call, 'position'), s(:int, 1))
end
##
# Generates the AST for the `:last-of-type` selector.
#
# @return [AST::Node]
#
def on_pseudo_class_last_of_type
return s(:eq, s(:call, 'position'), s(:call, 'last'))
end
private
##

View File

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