leafo / scssphp

SCSS compiler written in PHP
MIT License
1.34k stars 214 forks source link

Avoid infinitely duplicating parts when extending selector #635

Closed cyberalien closed 5 years ago

cyberalien commented 5 years ago

Fix for issue https://github.com/leafo/scssphp/issues/634

Compiler was duplicating selectors, resulting in ".foo.bar.bar.bar.bar" that ended up failing at comparison, so compiler assumed it was new selector. Whole thing ended up in infinite loop.

Added code that prevents duplicates and a test case.

Output matches Ruby version, except that Ruby additionally shows a deprecation notice:

DEPRECATION WARNING on line 18 of test.scss:
Extending a compound selector, .bar:before, is deprecated and will not be supported in a future release.
Consider "@extend .bar, :before" instead.
See http://bit.ly/ExtendCompound for details.
cyberalien commented 5 years ago

Actually there is a small difference in output with Ruby that I missed.

In second selectors list Ruby parser doesn't include .baz.bar:before:hover, though I think it should. First extend on .bar should add :hover:after to it with blue color, second extend should make it available in :before, so blue color should be in .bar:hover:before and third extend should make it available as .baz.bar:before:hover.

Since sass code is invalid and causing infinite loop, looks like its caused by difference in handling bad code.

Cerdic commented 5 years ago

Checked this patch, it's OK, fixing the bug and, tests are OK and PSR2 OK

robocoder commented 5 years ago

Some temporary breakage from conflicting PRs. I'll commit the fixes shortly.