Permalink
Browse files

Remove support for script &.

Closes #1077
  • Loading branch information...
1 parent 054b486 commit cbd07dac56028e2216972e1c009d7bf24027b588 @nex3 nex3 committed Jan 22, 2014
View
@@ -5,69 +5,35 @@
## 3.3.0 (Unreleased)
-### Using `&` in SassScript
-
-For a long time, Sass has supported a special
-{file:SASS_REFERENCE.md#parent-selector "parent selector", `&`}, which is used
-when nesting selectors to describe how a nested selector relates to the
-selectors above it. Until now, this has only been usable in selectors, but now
-it can be used in SassScript as well.
-
-In a SassScript expression, `&` refers to the current parent selector. It's a
-comma-separated list of space-separated lists. For example:
-
- .foo.bar .baz.bang, .bip.qux {
- $selector: &;
- }
-
-The value of `$selector` is now `((".foo.bar" ".baz.bang"), ".bip.qux")`. The
-compound selectors are quoted here to indicate that they're strings, but in
-reality they would be unquoted.
+#### `@at-root`
-The SassScript `&` may be used in selectors using `#{}` interpolation. By
-treating it as a SassScript value, you can do different things with it than you
-can when treating it as a selector. When `&` is used as a selector, it can only
-appear at the beginning of a compound selector, similarly to a type selector
-like `a` or `h1`. When used with `#{}`, it can go anywhere. For example:
+Sass 3.3 adds the `@at-root` directive, which is a way to tell Sass to
+put a collection of rules at the top-level root of the document. The
+easiest way to use it is with a selector:
.badge {
- @at-root #{&}-info { ... }
- @at-root #{&}-header { ... }
+ @at-root .info { ... }
+ @at-root .header { ... }
}
-Produces:
-
- .badge-info { ... }
- .badge-header { ... }
-
-#### `@at-root`
-
-What's that `@at-root` thing in the previous example? It's a way to tell Sass
-that you don't want that selector to be nested. When you use `&` as a selector,
-Sass can tell automatically that you don't want nesting, but when you use it
-with `#{}` you have to be explicit. After all, you might have put it in a
-variable, returned it from a function, or turned it into a string and reversed
-the characters.
-
In addition to using `@at-root` on a single selector, you can also use it on a
whole block of them. For example:
.badge {
@at-root {
- #{&}-info { ... }
- #{&}-header { ... }
+ .info { ... }
+ .header { ... }
}
}
Also produces:
- .badge-info { ... }
- .badge-header { ... }
+ .info { ... }
+ .header { ... }
#### `@at-root (without: ...)` and `@at-root (with: ...)`
-By default, `@at-root` just excludes selectors to allow `#{&}` to work
-similarly to just including `&` in a selector. However, it's also
+By default, `@at-root` just excludes selectors. However, it's also
possible to use `@at-root` to move outside of nested directives such
as `@media` as well. For example:
View
@@ -1092,37 +1092,6 @@ is compiled to:
p {
font: 12px/30px; }
-### `&` in SassScript {#parent-script}
-
-Just like when it's used [in selectors](#parent-selector), `&` in SassScript
-refers to the current parent selector. It's a comma-separated list of
-space-separated lists. For example:
-
- .foo.bar .baz.bang, .bip.qux {
- $selector: &;
- }
-
-The value of `$selector` is now `((".foo.bar" ".baz.bang"), ".bip.qux")`. The
-compound selectors are quoted here to indicate that they're strings, but in
-reality they would be unquoted. Even if the parent selector doesn't contain a
-comma or a space, `&` will always have two levels of nesting, so it can be
-accessed consistently.
-
-The SassScript `&` may be used in selectors using `#{}` interpolation. Because
-it's often not possible for Sass to detect that you're using it, you need to
-explicitly tell Sass not to do the normal nesting for the selector using the
-[`@at-root` directive](#at-root). For example:
-
- .badge {
- @at-root #{&}-info { ... }
- @at-root #{&}-header { ... }
- }
-
-Produces:
-
- .badge-info { ... }
- .badge-header { ... }
-
### Variable Defaults: `!default`
You can assign to variables if they aren't already assigned
View
@@ -94,7 +94,6 @@ def offset
:color => HEXCOLOR,
:bool => /(true|false)\b/,
:null => /null\b/,
- :selector => /&/,
:ident_op => /(#{Regexp.union(*IDENT_OP_NAMES.map do |s|
Regexp.new(Regexp.escape(s) + "(?!#{NMCHAR}|\Z)")
end)})/,
@@ -255,7 +254,7 @@ def token
end
variable || string(:double, false) || string(:single, false) || number ||
- color || bool || null || selector || string(:uri, false) ||
+ color || bool || null || string(:uri, false) ||
raw(UNICODERANGE) || special_fun || special_val || ident_op || ident || op
end
@@ -322,14 +321,6 @@ def null
[:null, script_null]
end
- def selector
- start_pos = source_position
- return unless scan(REGULAR_EXPRESSIONS[:selector])
- script_selector = Script::Tree::Selector.new
- script_selector.source_range = range(start_pos)
- [:selector, script_selector]
- end
-
def special_fun
str1 = scan(/((-[\w-]+-)?(calc|element)|expression|progid:[a-z\.]*)\(/i)
return unless str1
View
@@ -13,4 +13,3 @@ module Sass::Script::Tree
require 'sass/script/tree/literal'
require 'sass/script/tree/list_literal'
require 'sass/script/tree/map_literal'
-require 'sass/script/tree/selector'
@@ -1,30 +0,0 @@
-module Sass::Script::Tree
- # A SassScript node that will resolve to the current selector.
- class Selector < Node
- def initialize; end
-
- def children
- []
- end
-
- def to_sass(opts = {})
- '&'
- end
-
- def deep_copy
- dup
- end
-
- protected
-
- def _perform(environment)
- selector = environment.selector
- return opts(Sass::Script::Value::Null.new) unless selector
- opts(Sass::Script::Value::List.new(selector.members.map do |seq|
- Sass::Script::Value::List.new(seq.members.map do |component|
- Sass::Script::Value::String.new(component.to_s)
- end, :space)
- end, :comma))
- end
- end
-end
@@ -105,10 +105,6 @@ def test_list_in_map
assert_renders "(foo: (bar, baz), bip: bop)"
end
- def test_selector
- assert_renders "&"
- end
-
def self.test_precedence(outer, inner)
op_outer = Sass::Script::Lexer::OPERATORS_REVERSE[outer]
op_inner = Sass::Script::Lexer::OPERATORS_REVERSE[inner]
View
@@ -570,27 +570,6 @@ def test_boolean_ops_short_circuit
assert_equal "true", resolve("$ie or $undef", {}, env('ie' => Sass::Script::Value::Bool.new(true)))
end
- def test_selector
- env = Sass::Environment.new
- assert_equal "true", resolve("& == null", {}, env)
-
- env.selector = selector('.foo.bar .baz.bang, .bip.bop')
- assert_equal ".foo.bar .baz.bang, .bip.bop", resolve("&", {}, env)
- assert_equal ".foo.bar .baz.bang", resolve("nth(&, 1)", {}, env)
- assert_equal ".bip.bop", resolve("nth(&, 2)", {}, env)
- assert_equal ".foo.bar", resolve("nth(nth(&, 1), 1)", {}, env)
- assert_equal ".baz.bang", resolve("nth(nth(&, 1), 2)", {}, env)
- assert_equal ".bip.bop", resolve("nth(nth(&, 2), 1)", {}, env)
- assert_equal "string", resolve("type-of(nth(nth(&, 1), 1))", {}, env)
-
- env.selector = selector('.foo > .bar')
- assert_equal ".foo > .bar", resolve("&", {}, env)
- assert_equal ".foo > .bar", resolve("nth(&, 1)", {}, env)
- assert_equal ".foo", resolve("nth(nth(&, 1), 1)", {}, env)
- assert_equal ">", resolve("nth(nth(&, 1), 2)", {}, env)
- assert_equal ".bar", resolve("nth(nth(&, 1), 3)", {}, env)
- end
-
def test_setting_global_variable_locally_warns
assert_warning(<<WARNING) {assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))}
DEPRECATION WARNING on line 4 of test_setting_global_variable_locally_warns_inline.scss:
Oops, something went wrong.

0 comments on commit cbd07da

Please sign in to comment.