diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index ac6cf6a..cedad80 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -550,6 +550,15 @@ end return s(:eq, s(:call, 'last'), s(:int, 1)) end + ## + # Generates the AST for the `:empty` selector. + # + # @return [AST::Node] + # + def on_pseudo_class_empty + return s(:call, 'not', s(:axis, 'child', s(:type_test, 'node'))) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/empty_spec.rb b/spec/oga/css/parser/pseudo_classes/empty_spec.rb new file mode 100644 index 0000000..b487f1d --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/empty_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':empty pseudo class' do + example 'parse the :empty pseudo class' do + parse_css(':empty').should == parse_xpath( + 'descendant-or-self::*[not(node())]' + ) + end + end +end