diff --git a/src/scope-selector-matchers.coffee b/src/scope-selector-matchers.coffee index 346cf5a..590169d 100644 --- a/src/scope-selector-matchers.coffee +++ b/src/scope-selector-matchers.coffee @@ -78,23 +78,33 @@ class PathMatcher constructor: (prefix, first, others) -> @prefix = prefix?[0] @matchers = [first] - @matchers.push(matcher[1]) for matcher in others + @children = [false] + for matcher in others + @children.push(matcher[1]?) + @matchers.push(matcher[3]) matches: (scopes) -> index = 0 matcher = @matchers[index] for scope in scopes - matcher = @matchers[++index] if matcher.matches(scope) + if matcher.matches(scope) + matcher = @matchers[++index] + else + return false if @children[index] return true unless matcher? false getPrefix: (scopes) -> @prefix if @matches(scopes) toCssSelector: -> - @matchers.map((matcher) -> matcher.toCssSelector()).join(' ') + @matchers.map((matcher, index) => + (if @children[index] then "> " else "") + matcher.toCssSelector() + ).join(' ') toCssSyntaxSelector: -> - @matchers.map((matcher) -> matcher.toCssSyntaxSelector()).join(' ') + @matchers.map((matcher, index) => + (if @children[index] then "> " else "") + matcher.toCssSyntaxSelector() + ).join(' ') class OrMatcher constructor: (@left, @right) -> diff --git a/src/scope-selector-parser.pegjs b/src/scope-selector-parser.pegjs index fed1f11..20c01d4 100644 --- a/src/scope-selector-parser.pegjs +++ b/src/scope-selector-parser.pegjs @@ -19,7 +19,7 @@ scope } path - = prefix:([LRB]":")? first:scope others:(_ scope)* { + = prefix:([LRB]":")? first:scope others:(_ ">"? _ scope)* { return new matchers.PathMatcher(prefix, first, others); }