mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add a deprecation warning for !-variables.
This commit is contained in:
parent
22d7105799
commit
fc0974eee4
5 changed files with 90 additions and 17 deletions
|
@ -423,6 +423,7 @@ WARNING
|
|||
:line => @line + 1) unless line.children.empty?
|
||||
raise SyntaxError.new("Invalid variable: \"#{line.text}\".",
|
||||
:line => @line) unless name && value
|
||||
Script.var_warning(name, @line, line.offset + 1, @options[:filename]) if line.text[0] == ?!
|
||||
|
||||
Tree::VariableNode.new(name, parse_script(value, :offset => line.offset + line.text.index(value)), op == '||=')
|
||||
end
|
||||
|
@ -483,10 +484,14 @@ WARNING
|
|||
raise SyntaxError.new("Invalid for directive '@for #{text}': expected #{expected}.")
|
||||
end
|
||||
raise SyntaxError.new("Invalid variable \"#{var}\".") unless var =~ Script::VALIDATE
|
||||
if var.slice!(0) == ?!
|
||||
offset = line.offset + line.text.index("!" + var) + 1
|
||||
Script.var_warning(var, @line, offset, @options[:filename])
|
||||
end
|
||||
|
||||
parsed_from = parse_script(from_expr, :offset => line.offset + line.text.index(from_expr))
|
||||
parsed_to = parse_script(to_expr, :offset => line.offset + line.text.index(to_expr))
|
||||
Tree::ForNode.new(var[1..-1], parsed_from, parsed_to, to_name == 'to')
|
||||
Tree::ForNode.new(var, parsed_from, parsed_to, to_name == 'to')
|
||||
end
|
||||
|
||||
def parse_else(parent, line, text)
|
||||
|
|
|
@ -37,5 +37,15 @@ module Sass
|
|||
e.modify_backtrace(:line => line, :filename => options[:filename])
|
||||
raise e
|
||||
end
|
||||
|
||||
# @private
|
||||
def self.var_warning(varname, line, offset, filename)
|
||||
warn <<MESSAGE
|
||||
DEPRECATION WARNING:
|
||||
On line #{line}, character #{offset}#{" of '#{filename}'" if filename}
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
Use \"$#{varname}\" instead.
|
||||
MESSAGE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ module Sass
|
|||
:whitespace => /\s+/,
|
||||
:comment => Sass::SCSS::RX::COMMENT,
|
||||
:single_line_comment => Sass::SCSS::RX::SINGLE_LINE_COMMENT,
|
||||
:variable => /[!\$](#{Sass::SCSS::RX::IDENT})/,
|
||||
:variable => /([!\$])(#{Sass::SCSS::RX::IDENT})/,
|
||||
:ident => Sass::SCSS::RX::IDENT,
|
||||
:number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
|
||||
:color => Sass::SCSS::RX::HEXCOLOR,
|
||||
|
@ -174,8 +174,14 @@ module Sass
|
|||
end
|
||||
|
||||
def variable
|
||||
line = @line
|
||||
offset = @offset
|
||||
return unless scan(REGULAR_EXPRESSIONS[:variable])
|
||||
[:const, @scanner[1]]
|
||||
if @scanner[1] == '!' && @scanner[2] != 'important'
|
||||
Script.var_warning(@scanner[2], line, offset + 1, @options[:filename])
|
||||
end
|
||||
|
||||
[:const, @scanner[2]]
|
||||
end
|
||||
|
||||
def ident
|
||||
|
|
|
@ -826,9 +826,31 @@ $a = 3
|
|||
a-\#{$i}
|
||||
2i = 2 * $i
|
||||
|
||||
@for !j from 1 through 4
|
||||
b-\#{!j}
|
||||
j-1 = !j - 1
|
||||
@for $j from 1 through 4
|
||||
b-\#{$j}
|
||||
j-1 = $j - 1
|
||||
SASS
|
||||
end
|
||||
|
||||
def test_for_with_bang_var
|
||||
assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
|
||||
DEPRECATION WARNING:
|
||||
On line 1, character 6 of 'test_for_with_bang_var_inline.sass'
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
Use "$bar" instead.
|
||||
WARN
|
||||
a-0 {
|
||||
b: c; }
|
||||
|
||||
a-1 {
|
||||
b: c; }
|
||||
|
||||
a-2 {
|
||||
b: c; }
|
||||
CSS
|
||||
@for !bar from 0 to 3
|
||||
a-\#{$bar}
|
||||
b: c
|
||||
SASS
|
||||
end
|
||||
|
||||
|
@ -912,18 +934,32 @@ SASS
|
|||
end
|
||||
|
||||
def test_bang_variables
|
||||
assert_equal(<<CSS, render(<<SASS))
|
||||
assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
|
||||
DEPRECATION WARNING:
|
||||
On line 1, character 1 of 'test_bang_variables_inline.sass'
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
Use "$bang-var" instead.
|
||||
WARN
|
||||
foo {
|
||||
one: 1px;
|
||||
two: 2px;
|
||||
both: 3px; }
|
||||
a: 1px; }
|
||||
CSS
|
||||
!var1 = 1px
|
||||
$var2 = 2px
|
||||
!bang-var = 1px
|
||||
foo
|
||||
one= $var1
|
||||
two= !var2
|
||||
both= !var1 + $var2
|
||||
a = $bang-var
|
||||
SASS
|
||||
|
||||
assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
|
||||
DEPRECATION WARNING:
|
||||
On line 3, character 7 of 'test_bang_variables_inline.sass'
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
Use "$dollar-var" instead.
|
||||
WARN
|
||||
foo {
|
||||
a: 1px; }
|
||||
CSS
|
||||
$dollar-var = 1px
|
||||
foo
|
||||
a = !dollar-var
|
||||
SASS
|
||||
end
|
||||
|
||||
|
@ -987,6 +1023,17 @@ a
|
|||
SASS
|
||||
end
|
||||
|
||||
def test_important
|
||||
assert_equal(<<CSS, render(<<SASS))
|
||||
a {
|
||||
b: 12px !important; }
|
||||
CSS
|
||||
$foo = 12px
|
||||
a
|
||||
b = $foo !important
|
||||
SASS
|
||||
end
|
||||
|
||||
def test_argument_error
|
||||
assert_raise(Sass::SyntaxError) { render("a\n b = hsl(1)") }
|
||||
end
|
||||
|
|
|
@ -52,7 +52,12 @@ class SassScriptConversionTest < Test::Unit::TestCase
|
|||
def test_variable
|
||||
assert_renders "$foo-bar"
|
||||
assert_renders "$flaznicate"
|
||||
assert_equal "$tumbly-wumbly", render("!tumbly-wumbly")
|
||||
assert_warning(<<WARN) {assert_equal "$tumbly-wumbly", render("!tumbly-wumbly")}
|
||||
DEPRECATION WARNING:
|
||||
On line 1, character 1 of 'test_variable_inline.sass'
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
Use "$tumbly-wumbly" instead.
|
||||
WARN
|
||||
end
|
||||
|
||||
def test_comma_operator
|
||||
|
@ -126,6 +131,6 @@ RUBY
|
|||
|
||||
def render(script, options = {})
|
||||
munge_filename(options)
|
||||
Sass::Script.parse(script, 0, 0, options).to_sass
|
||||
Sass::Script.parse(script, 1, 0, options).to_sass
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue