Skip to content

Commit

Permalink
Parse pseudo selector arguments as declaration values. (#2304)
Browse files Browse the repository at this point in the history
Closes #2120
  • Loading branch information
nex3 committed Jun 3, 2017
1 parent 4d238e2 commit 35c70fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
4 changes: 4 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
previously parsed as strings, and in 3.6 they will be parsed as colors
instead.

* Pseudo selectors that take arguments now allow any
[`<declaration-value>`][declaration-value] production in their argument list.
This will provide better forwards-compatibility for future CSS syntax.

[hex alpha spec]: https://drafts.csswg.org/css-color/#hex-notation
[directional focus spec]: https://www.w3.org/TR/css-ui-3/#nav-dir

Expand Down
2 changes: 1 addition & 1 deletion lib/sass/scss/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ def merge(arr)
:media_expr => "media expression (e.g. (min-device-width: 800px))",
:at_root_query => "@at-root query (e.g. (without: media))",
:at_root_directive_list => '* or identifier',
:pseudo_args => "expression (e.g. fr, 2n+1)",
:declaration_value => "expression (e.g. fr, 2n+1)",
:interp_ident => "identifier",
:qualified_name => "identifier",
:expr => "expression (e.g. 1px, bold)",
Expand Down
25 changes: 1 addition & 24 deletions lib/sass/scss/static_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,37 +282,14 @@ def pseudo
elsif s == ':' && PREFIXED_SELECTOR_PSEUDO_CLASSES.include?(deprefixed)
arg, sel = prefixed_selector_pseudo
else
arg = expr!(:pseudo_args)
arg = expr!(:declaration_value).join
end

tok!(/\)/)
end
Selector::Pseudo.new(s == ':' ? :class : :element, name, arg, sel)
end

def pseudo_args
arg = expr!(:pseudo_expr)
while tok(/,/)
arg << ',' << str {ss}
arg.concat expr!(:pseudo_expr)
end
arg
end

def pseudo_expr
res = pseudo_expr_token
return unless res
res << str {ss}
while (e = pseudo_expr_token)
res << e << str {ss}
end
res
end

def pseudo_expr_token
tok(PLUS) || tok(/[-*]/) || tok(NUMBER) || tok(STRING) || tok(IDENT)
end

def prefixed_selector_pseudo
prefix = str do
expr = str {expr!(:a_n_plus_b)}
Expand Down

0 comments on commit 35c70fb

Please sign in to comment.