Skip to content

Commit

Permalink
Deprecate the reference combinator. (#2298)
Browse files Browse the repository at this point in the history
See #303
  • Loading branch information
nex3 committed Jun 9, 2017
1 parent cece53f commit ebdffd1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
[color functions][] are a much cleaner and more comprehensible way of
manipulating colors dynamically.

* The reference combinator, `/foo/`, is deprecated since it hasn't been in the
CSS specification for some time.

* The old-style `:name value` property syntax is deprecated. This syntax is not
widely used, and is unnecessarily different from CSS.

Expand Down
7 changes: 7 additions & 0 deletions lib/sass/scss/static_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def reference_combinator
ns, name = expr!(:qualified_name)
res << ns << '|' if ns
res << name << tok!(%r{/})

location = " of #{@filename}" if @filename
Sass::Util.sass_warn <<MESSAGE
DEPRECATION WARNING on line #{@line}, column #{@offset}#{location}:
The reference combinator #{res} is deprecated and will be removed in a future release.
MESSAGE

res
end

Expand Down
17 changes: 13 additions & 4 deletions lib/sass/tree/rule_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ def try_to_parse_non_interpolated_rules

# We don't use real filename/line info because we don't have it yet.
# When we get it, we'll set it on the parsed rules if possible.
parser = Sass::SCSS::StaticParser.new(@rule.join.strip, nil, nil, 1)
# rubocop:disable RescueModifier
@parsed_rules = parser.parse_selector rescue nil
# rubocop:enable RescueModifier
parser = nil
warnings = Sass::Util.silence_warnings do
parser = Sass::SCSS::StaticParser.new(@rule.join.strip, nil, nil, 1)
# rubocop:disable RescueModifier
@parsed_rules = parser.parse_selector rescue nil
# rubocop:enable RescueModifier

$stderr.string
end

# If parsing produces a warning, throw away the result so we can parse
# later with the real filename info.
@parsed_rules = nil unless warnings.empty?
end
end
end
6 changes: 3 additions & 3 deletions test/sass/extend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ def test_nested_extender_doesnt_find_common_selectors_around_sibling_selector
end

def test_nested_extender_doesnt_find_common_selectors_around_reference_selector
assert_extends 'a /for/ b c .c1', 'a c .c2 {@extend .c1}', 'a /for/ b c .c1, a /for/ b a c .c2, a a /for/ b c .c2'
assert_extends 'a /for/ b c .c1', 'a b .c2 {@extend .c1}', 'a /for/ b c .c1, a a /for/ b c .c2'
assert_extends 'a /for/ b c .c1', 'b c .c2 {@extend .c1}', 'a /for/ b c .c1, a /for/ b c .c2'
silence_warnings {assert_extends 'a /for/ b c .c1', 'a c .c2 {@extend .c1}', 'a /for/ b c .c1, a /for/ b a c .c2, a a /for/ b c .c2'}
silence_warnings {assert_extends 'a /for/ b c .c1', 'a b .c2 {@extend .c1}', 'a /for/ b c .c1, a a /for/ b c .c2'}
silence_warnings {assert_extends 'a /for/ b c .c1', 'b c .c2 {@extend .c1}', 'a /for/ b c .c1, a /for/ b c .c2'}
end

def test_nested_extender_with_early_child_selectors_doesnt_subseq_them
Expand Down
4 changes: 2 additions & 2 deletions test/sass/scss/css_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,10 @@ def test_summarized_selectors_with_element
assert_selector_parses('E > F')
assert_selector_parses('E + F')
assert_selector_parses('E ~ F')
assert_selector_parses('E /foo/ F')
silence_warnings {assert_selector_parses('E /foo/ F')}
silence_warnings {assert_selector_parses('E! > F')}

assert_selector_parses('E /ns|foo/ F')
silence_warnings {assert_selector_parses('E /ns|foo/ F')}

# From http://dev.w3.org/csswg/css-scoping-1/
assert_selector_parses('E:host(s)')
Expand Down
16 changes: 14 additions & 2 deletions test/sass/scss/scss_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ def test_selector_interpolation_at_dashes
end

def test_selector_interpolation_in_reference_combinator
assert_equal <<CSS, render(<<SCSS)
silence_warnings {assert_equal <<CSS, render(<<SCSS)}
.foo /a/ .bar /b|c/ .baz {
a: b; }
CSS
Expand Down Expand Up @@ -3857,7 +3857,19 @@ def test_import_comments_in_imports
end

def test_reference_combinator_with_parent_ref
assert_equal <<CSS, render(<<SCSS)
silence_warnings {assert_equal <<CSS, render(<<SCSS)}
a /foo/ b {
c: d; }
CSS
a {& /foo/ b {c: d}}
SCSS
end

def test_reference_combinator_warning
assert_warning(<<WARNING) {assert_equal <<CSS, render(<<SCSS)}
DEPRECATION WARNING on line 1, column 8 of test_reference_combinator_warning_inline.scss:
The reference combinator /foo/ is deprecated and will be removed in a future release.
WARNING
a /foo/ b {
c: d; }
CSS
Expand Down

0 comments on commit ebdffd1

Please sign in to comment.