lib/sass/scss/parser.rb in haml-3.0.23 vs lib/sass/scss/parser.rb in haml-3.0.24
- old
+ new
@@ -96,12 +96,12 @@
comment = Sass::Tree::CommentNode.new(pre_str + text, single_line)
comment.line = @line - text.count("\n")
node << comment
end
- DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :extend, :import,
- :media, :charset]
+ DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :else,
+ :extend, :import, :media, :charset]
def directive
return unless tok(/@/)
name = tok!(IDENT)
ss
@@ -178,16 +178,18 @@
def if_directive
expr = sass_script(:parse)
ss
node = block(node(Sass::Tree::IfNode.new(expr)), :directive)
pos = @scanner.pos
+ line = @line
ss
else_block(node) ||
begin
# Backtrack in case there are any comments we want to parse
@scanner.pos = pos
+ @line = line
node
end
end
def else_block(node)
@@ -196,17 +198,24 @@
else_node = block(
Sass::Tree::IfNode.new((sass_script(:parse) if tok(/if/))),
:directive)
node.add_else(else_node)
pos = @scanner.pos
+ line = @line
ss
else_block(node) ||
begin
# Backtrack in case there are any comments we want to parse
@scanner.pos = pos
+ @line = line
node
end
+ end
+
+ def else_directive
+ raise Sass::SyntaxError.new(
+ "Invalid CSS: @else must come after @if", :line => @line)
end
def extend_directive
node(Sass::Tree::ExtendNode.new(expr!(:selector)))
end