Skip to content

Commit

Permalink
improvement cloning of the parent node
Browse files Browse the repository at this point in the history
We used to clone the full tree and then remove all the children, this
was a bit too slow so therefore we will now create a new tree based on
the old information.
  • Loading branch information
RobinMalfait authored and adamwathan committed Aug 18, 2020
1 parent 78df100 commit 00f4427
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/flagged/applyComplexClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ function hasAtRule(css, atRule) {
return foundAtRule
}

function cloneWithoutChildren(node) {
if (node.type === 'atrule') {
return postcss.atRule({ name: node.name, params: node.params })
}

if (node.type === 'rule') {
return postcss.rule({ name: node.name, selectors: node.selectors })
}

const clone = node.clone()
clone.removeAll()
return clone
}

const tailwindApplyPlaceholder = selectorParser.attribute({
attribute: '__TAILWIND-APPLY-PLACEHOLDER__',
})
Expand All @@ -46,8 +60,8 @@ function generateRulesFromApply({ rule, utilityName: className, classPosition },
let parent = rule.parent

while (parent && parent.type !== 'root') {
const parentClone = parent.clone()
parentClone.removeAll()
const parentClone = cloneWithoutChildren(parent)

parentClone.append(current)
current.parent = parentClone
current = parentClone
Expand Down

0 comments on commit 00f4427

Please sign in to comment.