From 3abccd90fbfb268cf0656ef6a502a4027bdd7431 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Mon, 8 Mar 2010 23:02:43 -0800 Subject: [PATCH] [Sass] Make sure the description of extend loops are deterministically ordered. --- lib/sass/selector.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/sass/selector.rb b/lib/sass/selector.rb index 1a07c020..b86b7e69 100644 --- a/lib/sass/selector.rb +++ b/lib/sass/selector.rb @@ -432,21 +432,20 @@ module Sass # Raise a {Sass::SyntaxError} describing a loop of `@extend` directives. # - # @todo Deterministically order the description based on line numbers - # # @param supers [Array] The stack of selectors that contains the loop, # ordered from deepest to most shallow. # @raise [Sass::SyntaxError] Describing the loop def handle_extend_loop(supers) supers.inject([]) do |sels, sel| next sels.push(sel) unless sels.first.eql?(sel) - raise Sass::SyntaxError.new("An @extend loop was found:\n" + - Haml::Util.enum_cons(sels.push(sel), 2). - map do |sel1, sel2| - str = " #{sel1.inspect} extends #{sel2.inspect} on line #{sel1.line}" - str << " of " + sel1.filename if sel1.filename - str - end.join(",\n")) + conses = Haml::Util.enum_cons(sels.push(sel), 2).to_a + _, i = Haml::Util.enum_with_index(conses).max {|((_, sel1), _), ((_, sel2), _)| sel1.line <=> sel2.line} + loop = (conses[i..-1] + conses[0...i]).map do |sel1, sel2| + str = " #{sel1.inspect} extends #{sel2.inspect} on line #{sel1.line}" + str << " of " << sel1.filename if sel1.filename + str + end.join(",\n") + raise Sass::SyntaxError.new("An @extend loop was found:\n#{loop}") end # Should never get here raise Sass::SyntaxError.new("An @extend loop exists, but the exact loop couldn't be found")