Don't error out on empty Sass function arglists.

This also means we've got to add a Nil type for Sass.
This commit is contained in:
Nathan Weizenbaum 2008-06-05 14:31:48 -07:00
parent f7596639f0
commit 6e18008a5d
4 changed files with 18 additions and 5 deletions

View File

@ -207,7 +207,10 @@ module Sass
#++
def operationalize(value, constants)
value = [value] unless value.is_a?(Array)
if value.length == 1
case value.length
when 0
Sass::Constant::Nil.new
when 1
value = value[0]
if value.is_a? Array
operationalize(value, constants)
@ -216,7 +219,7 @@ module Sass
else
Literal.parse(value)
end
elsif value.length == 2
when 2
if value[0] == :neg
Operation.new(Sass::Constant::Number.new('0'), operationalize(value[1], constants), :minus)
elsif value[0] == :const
@ -224,7 +227,7 @@ module Sass
else
raise SyntaxError.new("Constant arithmetic error")
end
elsif value.length == 3
when 3
Operation.new(operationalize(value[0], constants), operationalize(value[2], constants), value[1])
else
if SECOND_ORDER.include?(value[1]) && FIRST_ORDER.include?(value[3])

View File

@ -4,6 +4,7 @@ module Sass::Constant; class Literal; end; end; # :nodoc:
require 'sass/constant/string'
require 'sass/constant/number'
require 'sass/constant/color'
require 'sass/constant/nil'
class Sass::Constant::Literal # :nodoc:
# The regular expression matching numbers.

9
lib/sass/constant/nil.rb Normal file
View File

@ -0,0 +1,9 @@
require 'sass/constant/literal'
module Sass::Constant # :nodoc:
class Nil < Literal # :nodoc:
def to_s
''
end
end
end

View File

@ -132,8 +132,8 @@ END
end
def test_default_function
assert_equal("foo {\n bar: url(foo.png); }\n",
render("foo\n bar = url(foo.png)\n"));
assert_equal("foo {\n bar: url(foo.png); }\n", render("foo\n bar = url(foo.png)\n"));
assert_equal("foo {\n bar: url(); }\n", render("foo\n bar = url()\n"));
end
def test_basic_multiline_selector