[Sass] Allow hyphens in identifiers.

This commit is contained in:
Nathan Weizenbaum 2009-11-10 23:01:13 -08:00
parent 338eb42582
commit 7ef5d5e0cf
3 changed files with 11 additions and 28 deletions

View File

@ -13,6 +13,13 @@ Sass now supports functions that return the values of the
and {Sass::Script::Functions#green green}
components of colors.
### Variable Names
SassScript variable names may now contain hyphens.
For example:
!prettiest-color = #542FA9
### Error Backtraces
Numerous bugs were fixed with the backtraces given for Sass errors,

View File

@ -52,8 +52,8 @@ module Sass
# A hash of regular expressions that are used for tokenizing.
REGULAR_EXPRESSIONS = {
:whitespace => /\s*/,
:variable => /!(\w+)/,
:ident => /(\\.|\#\{|[^\s\\+\-*\/%(),=!])+/,
:variable => /!([\w-]+)/,
:ident => /(\\.|\#\{|[^\s\\+*\/%(),=!])+/,
:string_end => /((?:\\.|\#[^{]|[^"\\#])*)(?:"|(?=#\{))/,
:number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
:color => /\##{"([0-9a-fA-F]{1,2})" * 3}|(#{Color::HTML4_COLORS.keys.join("|")})(?!\()/,
@ -162,16 +162,6 @@ module Sass
def op
prev_chr = @scanner.string[@scanner.pos - 1].chr
return unless op = @scanner.scan(REGULAR_EXPRESSIONS[:op])
if @prev && op == '-' && prev_chr !~ /\s/ &&
[:bool, :ident, :const].include?(@prev.type)
warn(<<END)
DEPRECATION WARNING:
On line #{@line}, character #{last_match_position}#{" of '#{@filename}'" if @filename}
- will be allowed as part of variable names in version 2.4.
Please add whitespace to separate it from the previous token.
END
end
[OPERATORS[op]]
end

View File

@ -102,22 +102,8 @@ WARN
assert_equal "public_instance_methods()", resolve("public_instance_methods()")
end
def test_hyphen_warning
a = Sass::Script::String.new("a")
b = Sass::Script::String.new("b")
assert_warning(<<WARN) {eval("!a-!b", {}, env("a" => a, "b" => b))}
DEPRECATION WARNING:
On line 1, character 3 of 'test_hyphen_warning_inline.sass'
- will be allowed as part of variable names in version 2.4.
Please add whitespace to separate it from the previous token.
WARN
assert_warning(<<WARN) {eval("true-false")}
DEPRECATION WARNING:
On line 1, character 5 of 'test_hyphen_warning_inline.sass'
- will be allowed as part of variable names in version 2.4.
Please add whitespace to separate it from the previous token.
WARN
def test_hyphenated_variables
assert_equal("a-b", resolve("!a-b", {}, env("a-b" => Sass::Script::String.new("a-b"))))
end
def test_ruby_equality