mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Allow :not to take arbitrary selectors, contrary to the spec.
This commit is contained in:
parent
d5804a90f3
commit
ef92ec6485
5 changed files with 29 additions and 11 deletions
|
@ -381,6 +381,17 @@ module Sass
|
|||
sel.to_a
|
||||
end
|
||||
|
||||
def selector_comma_sequence
|
||||
return unless sel = _selector
|
||||
selectors = [sel]
|
||||
while tok(/,/)
|
||||
ws = str{ss}
|
||||
selectors << expr!(:_selector)
|
||||
selectors[-1] = Selector::Sequence.new(["\n"] + selectors.last.members) if ws.include?("\n")
|
||||
end
|
||||
Selector::CommaSequence.new(selectors)
|
||||
end
|
||||
|
||||
def _selector
|
||||
# The combinator here allows the "> E" hack
|
||||
return unless val = combinator || simple_selector_sequence
|
||||
|
@ -536,7 +547,7 @@ MESSAGE
|
|||
return unless tok(NOT)
|
||||
ss
|
||||
@expected = "selector"
|
||||
sel = element_name || id_selector || class_selector || attrib || expr!(:pseudo)
|
||||
sel = selector_comma_sequence
|
||||
tok!(/\)/)
|
||||
Selector::Negation.new(sel)
|
||||
end
|
||||
|
@ -722,7 +733,7 @@ MESSAGE
|
|||
:interp_ident => "identifier",
|
||||
:interp_name => "identifier",
|
||||
:expr => "expression (e.g. 1px, bold)",
|
||||
:_selector => "selector",
|
||||
:selector_comma_sequence => "selector",
|
||||
:simple_selector_sequence => "selector",
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,8 @@ module Sass
|
|||
# @raise [Sass::SyntaxError] if there's a syntax error in the selector
|
||||
def parse_selector(filename)
|
||||
init_scanner!
|
||||
selectors = [expr!(:_selector)]
|
||||
while tok(/,/)
|
||||
ws = str{ss}
|
||||
selectors << expr!(:_selector)
|
||||
selectors[-1] = Selector::Sequence.new(["\n"] + selectors.last.members) if ws.include?("\n")
|
||||
end
|
||||
seq = expr!(:selector_comma_sequence)
|
||||
expected("selector") unless @scanner.eos?
|
||||
seq = Selector::CommaSequence.new(selectors)
|
||||
seq.line = @line
|
||||
seq.filename = filename
|
||||
seq
|
||||
|
|
|
@ -336,10 +336,10 @@ module Sass
|
|||
class Negation < Simple
|
||||
# The selector to negate.
|
||||
#
|
||||
# @return [Selector]
|
||||
# @return [Selector::Sequence]
|
||||
attr_reader :selector
|
||||
|
||||
# @param [Selector] The selector to negate
|
||||
# @param [Selector::Sequence] The selector to negate
|
||||
def initialize(selector)
|
||||
@selector = selector
|
||||
end
|
||||
|
|
|
@ -61,6 +61,13 @@ module Sass
|
|||
members.map {|m| m.inspect}.join(", ")
|
||||
end
|
||||
|
||||
# @see Simple#to_a
|
||||
def to_a
|
||||
arr = Haml::Util.intersperse(@members.map {|m| m.to_a}, ", ").flatten
|
||||
arr.delete("\n")
|
||||
arr
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _hash
|
||||
|
|
|
@ -706,6 +706,12 @@ SCSS
|
|||
|
||||
assert_selector_parses(':not(:hover)')
|
||||
assert_selector_parses(':not(:nth-child(2n + 3))')
|
||||
|
||||
# Not technically allowed, but what the heck
|
||||
assert_selector_parses(':not(:not(#foo))')
|
||||
assert_selector_parses(':not(a#foo.bar)')
|
||||
assert_selector_parses(':not(#foo .bar > baz)')
|
||||
assert_selector_parses(':not(h1, h2, h3)')
|
||||
end
|
||||
|
||||
def test_namespaced_selectors
|
||||
|
|
Loading…
Add table
Reference in a new issue