Skip to content

Commit 78df100

Browse files
RobinMalfaitadamwathan
authored andcommitted
hoist the selector parser
No need to re-create the selector parser in the loop for each selector.
1 parent 309b8e5 commit 78df100

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/flagged/applyComplexClasses.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,20 @@ const tailwindApplyPlaceholder = selectorParser.attribute({
2525
})
2626

2727
function generateRulesFromApply({ rule, utilityName: className, classPosition }, replaceWith) {
28-
const processedSelectors = rule.selectors.map(selector => {
29-
const processor = selectorParser(selectors => {
30-
let i = 0
31-
selectors.walkClasses(c => {
32-
if (classPosition === i++ && c.value === className) {
33-
c.replaceWith(tailwindApplyPlaceholder)
34-
}
35-
})
28+
const processor = selectorParser(selectors => {
29+
let i = 0
30+
selectors.walkClasses(c => {
31+
if (classPosition === i++ && c.value === className) {
32+
c.replaceWith(tailwindApplyPlaceholder)
33+
}
3634
})
35+
})
3736

37+
const processedSelectors = rule.selectors.map(selector => {
3838
// You could argue we should make this replacement at the AST level, but if we believe
3939
// the placeholder string is safe from collisions then it is safe to do this is a simple
4040
// string replacement, and much, much faster.
41-
const processedSelector = processor
42-
.processSync(selector)
43-
.replace('[__TAILWIND-APPLY-PLACEHOLDER__]', replaceWith)
44-
45-
return processedSelector
41+
return processor.processSync(selector).replace('[__TAILWIND-APPLY-PLACEHOLDER__]', replaceWith)
4642
})
4743

4844
const cloned = rule.clone()

0 commit comments

Comments
 (0)