Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a62cd4

Browse files
committed
fix: parse Selectors::ComplexSelectors properly
- avoid clobbering the combinator method with a local variable- return a recursive tree of complex selectorsPartial fix for#25
1 parent1a50f58 commit6a62cd4

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

‎lib/syntax_tree/css/selectors.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,19 @@ def relative_selector_list
339339
defcomplex_selector
340340
left=compound_selector
341341

342-
loopdo
343-
if(combinator=maybe{combinator})
344-
ComplexSelector.new(left:left,combinator:combinator,right:compound_selector)
345-
elsif(right=maybe{compound_selector})
346-
ComplexSelector.new(left:left,combinator:nil,right:right)
347-
else
348-
break
349-
end
342+
if(c=maybe{combinator})
343+
ComplexSelector.new(left:left,combinator:c,right:complex_selector)
344+
elsif(right=maybe{complex_selector})
345+
ComplexSelector.new(left:left,combinator:nil,right:right)
346+
else
347+
left
350348
end
351-
352-
left
353349
end
354350

355351
# <relative-selector> = <combinator>? <complex-selector>
356352
defrelative_selector
357-
combinator=maybe{combinator}
358-
359-
ifcombinator
360-
RelativeSelector.new(combinator:combinator,complex_selector:complex_selector)
353+
if(c=maybe{combinator})
354+
RelativeSelector.new(combinator:c,complex_selector:complex_selector)
361355
else
362356
complex_selector
363357
end

‎test/selectors_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@ class SelectorsTest < Minitest::Spec
6565
end
6666
end
6767

68+
it"parses a complex selector"do
69+
actual=parse_selectors("section>table")
70+
71+
assert_patterndo
72+
actual=>[
73+
Selectors::ComplexSelector[
74+
left:Selectors::TypeSelector[value:{name:{value:"section"}}],
75+
combinator:{value:{value:">"}},
76+
right:Selectors::TypeSelector[value:{name:{value:"table"}}]
77+
]
78+
]
79+
end
80+
end
81+
82+
it"parses a complex selector with many selectors"do
83+
actual=parse_selectors("section>table>tr")
84+
85+
assert_patterndo
86+
actual=>[
87+
Selectors::ComplexSelector[
88+
left:Selectors::TypeSelector[value:{name:{value:"section"}}],
89+
combinator:{value:{value:">"}},
90+
right:Selectors::ComplexSelector[
91+
left:Selectors::TypeSelector[value:{name:{value:"table"}}],
92+
combinator:{value:{value:">"}},
93+
right:Selectors::TypeSelector[value:{name:{value:"tr"}}]
94+
]
95+
]
96+
]
97+
end
98+
end
99+
68100
private
69101

70102
defparse_selectors(selectors)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp