sass / sassc-ruby

Use libsass with Ruby!
MIT License
367 stars 156 forks source link

Infinite loop with multiple @extends in 2.4.0 #213

Open pmusaraj opened 3 years ago

pmusaraj commented 3 years ago

We upgraded from 2.0.1 to 2.4.0 and ran into a strange issue with a Sassc process going into an infinite loop on one specific stylesheet. I stripped down the stylesheet to its bare minimum to have the following minimal repro:

require 'sassc'

sass = <<SCSS

// Administrative buttons
.btn {
  // Buttons with no extra styles
  &.-flat {
    border: none;

    &,
    &:hover {
      background: transparent;
    }
  }
}

//
// UI Button Corrections
// ---------------------

// "New Topic" button
.btn#create-topic {
  @extend .btn-secondary;
  @extend .btn.-no-icon;
}

// "Create Topic" button
.btn.create,
.btn.edit-category {
  @extend .btn.-no-icon;
}

// Button to load more topics on homepage
.more-topics {
  .btn {
    @extend .btn.-small;
  }
}

// Topic footer buttons
#topic-footer-buttons {
  > button {
    @extend .btn.-flat;
  }

  > .btn-primary {
    @extend .btn-secondary;
  }
}

// Notification options
.notification-options {
  .btn {
    @extend .btn.-flat;
  }
}

// Extra post options
.topic-map {
  .buttons {
    .btn {
      @extend .btn.-flat;
    }
  }
}
SCSS

result = SassC::Engine.new(sass, style: :compressed).render
puts result.inspect

When I run the above, the process never completes and the CPU goes through the roof. Removing only the last @extend results in the following output:

Traceback (most recent call last):
    2: from sass.rb:72:in `<main>'
    1: from /Users/pmusaraj/.gem/ruby/2.6.5/gems/sassc-2.4.0/lib/sassc/engine.rb:50:in `render'
stdin:34: Error: The target selector was not found. (SassC::SyntaxError)
       Use "@extend .-small !optional" to avoid this error.
        on line 34 of stdin
>>     @extend .btn.-small;

Note that I am fully aware the SCSS syntax above is wrong, but shouldn't this return the error message at all times, no matter how many occurrences of the broken @extends are used?