fix purgecss-from-pug not handle class attributes with multiple values correctly #677 #678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
Replace
token.valin purgecss-from-pug by...token.val.split(" ")as done in purgecss-from-html to correctly handle class attributes with multiple values.case "tag": case "id": case "class": - selectors.push(token.val); + selectors.push(...token.val.split(" ")); break; case "attribute": if (token.name === "class" || token.name === "id") { selectors.push( - token.mustEscape ? token.val.replace(/"/g, "") : token.val + ...(token.mustEscape ? token.val.replace(/"/g, "") : token.val).split(" ") ); } break;Also complete the unittest for purgecss-from-pug to demonstrate that multiple classes are correctly handled.
See bug #677
Types of changes
Checklist
Further comments
I am fairly new to purgecss, but clearly all CSS classes are not correctly extracted from .pug files and this is related to purgecss-from-pug treating a class attribute with multiple values as a single value as shown in the bug report. When checking the difference with purgecss-from-html, we can see that purgecss-from-pug extract classes with
token.valwhile purgecss-from-html do something likeval.split(" ").