Permalink
Browse files

Merge branch 'stable'

Conflicts:
	doc-src/SASS_REFERENCE.md
	lib/sass/tree/directive_node.rb
	test/sass/extend_test.rb
  • Loading branch information...
2 parents 7ce31aa + fe88ee8 commit 319056fea0b2190f25acceb78912ca0ed5831f19 @nex3 nex3 committed May 12, 2012
View
6 doc-src/SASS_CHANGELOG.md
@@ -146,6 +146,12 @@ that make use of `@media` and other directives dynamically.
* Ruby 2.0 compatibility. Thanks to [Jeremy
Kemper](https://github.com/jeremy).
+### Deprecations -- Must Read!
+
+* Deprecate the use of `@extend` within directives such as `@media`. This has
+ never worked correctly, and now it's officially deprecated. It will be an
+ error in 3.2.
+
## 3.1.17
* Don't crash when calling `#inspect` on an internal Sass tree object in Ruby
View
10 doc-src/SASS_REFERENCE.md
@@ -1594,6 +1594,16 @@ Is compiled to:
font-size: 2em;
}
+#### `@extend` in Directives
+
+Unfortunately, `@extend` cannot be used within directives such as `@media`. Sass
+is unable to make CSS rules outside of the `@media` block apply to selectors
+inside it without creating a huge amount of stylesheet bloat by copying styles
+all over the place.
+
+Someday we hope to have `@extend` supported natively in the browser, which will
+allow it to be used within `@media` and other directives.
+
### `@debug`
The `@debug` directive prints the value of a SassScript expression
View
5 lib/sass/tree/directive_node.rb
@@ -33,5 +33,10 @@ def self.resolved(value)
node.resolved_value = value
node
end
+
+ # @return [String] The name of the directive, including `@`.
+ def name
+ value.first.gsub(/ .*$/, '')
+ end
end
end
View
12 lib/sass/tree/extend_node.rb
@@ -25,5 +25,17 @@ def initialize(selector)
@selector = selector
super()
end
+
+ # Disables this `@extend` due to it being inside a directive.
+ def disable!
+ @disabled = true
+ end
+
+ # Whether this `@extend` is disabled due to it being inside a directive.
+ #
+ # @return [Boolean]
+ def disabled?
+ @disabled
+ end
end
end
View
14 lib/sass/tree/visitors/check_nesting.rb
@@ -69,7 +69,19 @@ def invalid_charset_parent?(parent, child)
VALID_EXTEND_PARENTS = [Sass::Tree::RuleNode, Sass::Tree::MixinDefNode, Sass::Tree::MixinNode]
def invalid_extend_parent?(parent, child)
unless is_any_of?(parent, VALID_EXTEND_PARENTS)
- "Extend directives may only be used within rules."
+ return "Extend directives may only be used within rules."
+ end
+
+ if !child.disabled? &&
+ directive = @parents.find {|p| p.is_a?(Sass::Tree::DirectiveNode)}
+ child.disable!
+ Sass::Util.sass_warn <<WARNING
+DEPRECATION WARNING on line #{child.line}#{" of #{child.filename}" if child.filename}:
+ Using @extend within directives (e.g. #{directive.name}) is deprecated.
+ It will be an error in Sass 3.2.
+ This will only work once @extend is supported natively in the browser.
+WARNING
+ nil
end
end
View
1 lib/sass/tree/visitors/cssize.rb
@@ -83,6 +83,7 @@ def visit_root(node)
# Registers an extension in the `@extends` subset map.
def visit_extend(node)
+ return [] if node.disabled?
node.resolved_selector.members.each do |seq|
if seq.members.size > 1
raise Sass::SyntaxError.new("Can't extend #{seq.to_a.join}: can't extend nested selectors")
View
36 test/sass/extend_test.rb
@@ -795,6 +795,42 @@ def test_media_in_placeholder_selector
SCSS
end
+ def test_extend_in_media
+ assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SCSS))}
+DEPRECATION WARNING on line 3 of test_extend_in_media_inline.sass:
+ Using @extend within directives (e.g. @media) is deprecated.
+ It will be an error in Sass 3.2.
+ This will only work once @extend is supported natively in the browser.
+WARN
+.foo {
+ a: b; }
+CSS
+.foo {a: b}
+@media screen {
+ .bar {@extend .foo}
+}
+SCSS
+ end
+
+ def test_extend_in_unknown_directive
+ assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SCSS))}
+DEPRECATION WARNING on line 3 of test_extend_in_unknown_directive_inline.sass:
+ Using @extend within directives (e.g. @flooblehoof) is deprecated.
+ It will be an error in Sass 3.2.
+ This will only work once @extend is supported natively in the browser.
+WARN
+.foo {
+ a: b; }
+
+@flooblehoof {}
+CSS
+.foo {a: b}
+@flooblehoof {
+ .bar {@extend .foo}
+}
+SCSS
+ end
+
# Regression Tests
def test_newline_near_combinator

0 comments on commit 319056f

Please sign in to comment.