Fixed parsing of nth-child(n) and nth-child(-n)
This commit is contained in:
parent
87f6b9c723
commit
0e6aefb727
|
@ -272,7 +272,7 @@ rule
|
||||||
|
|
||||||
nth
|
nth
|
||||||
: T_NTH { s(:nth, s(:int, 1)) }
|
: T_NTH { s(:nth, s(:int, 1)) }
|
||||||
| T_MINUS T_NTH { s(:nth) }
|
| T_MINUS T_NTH { s(:nth, s(:int, 1)) }
|
||||||
| integer T_NTH { s(:nth, val[0]) }
|
| integer T_NTH { s(:nth, val[0]) }
|
||||||
| integer T_NTH integer { s(:nth, val[0], val[2]) }
|
| integer T_NTH integer { s(:nth, val[0], val[2]) }
|
||||||
;
|
;
|
||||||
|
@ -384,7 +384,7 @@ end
|
||||||
s(:eq, s(:mod, s(:sub, before_count, offset), s(:int, 2)), s(:int, 0))
|
s(:eq, s(:mod, s(:sub, before_count, offset), s(:int, 2)), s(:int, 0))
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
node = s(:mod, before_count, step)
|
node = s(:eq, s(:mod, before_count, step), s(:int, 0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe Oga::CSS::Parser do
|
||||||
|
|
||||||
example 'parse the x:nth-child(even) pseudo class' do
|
example 'parse the x:nth-child(even) pseudo class' do
|
||||||
parse_css('x:nth-child(even)').should == parse_xpath(
|
parse_css('x:nth-child(even)').should == parse_xpath(
|
||||||
'descendant-or-self::x[(count(preceding-sibling::*) + 1) mod 2]'
|
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 2) = 0]'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,20 +46,14 @@ describe Oga::CSS::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse the x:nth-child(n) pseudo class' do
|
example 'parse the x:nth-child(n) pseudo class' do
|
||||||
parse_css('x:nth-child(n)').should == s(
|
parse_css('x:nth-child(n)').should == parse_xpath(
|
||||||
:pseudo,
|
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
|
||||||
s(:test, nil, 'x'),
|
|
||||||
'nth-child',
|
|
||||||
s(:nth)
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse the x:nth-child(-n) pseudo class' do
|
example 'parse the x:nth-child(-n) pseudo class' do
|
||||||
parse_css('x:nth-child(-n)').should == s(
|
parse_css('x:nth-child(-n)').should == parse_xpath(
|
||||||
:pseudo,
|
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
|
||||||
s(:test, nil, 'x'),
|
|
||||||
'nth-child',
|
|
||||||
s(:nth)
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue