Skip to content

Commit

Permalink
Preserve source maps for @apply
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Feb 23, 2022
1 parent d72b277 commit fa3b57e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function processApply(root, context) {
for (let apply of applies) {
let candidates = perParentApplies.get(apply.parent) || []

perParentApplies.set(apply.parent, candidates)
perParentApplies.set(apply.parent, [candidates, apply.source])

let [applyCandidates, important] = extractApplyCandidates(apply.params)

Expand Down Expand Up @@ -178,7 +178,7 @@ function processApply(root, context) {
}
}

for (const [parent, candidates] of perParentApplies) {
for (const [parent, [candidates, atApplySource]] of perParentApplies) {
let siblings = []

for (let [applyCandidate, important, rules] of candidates) {
Expand Down Expand Up @@ -220,6 +220,12 @@ function processApply(root, context) {
}

let root = postcss.root({ nodes: [node.clone()] })

// Make sure every node in the entire tree points back at the @apply rule that generated it
root.walk((node) => {
node.source = atApplySource
})

let canRewriteSelector =
node.type !== 'atrule' || (node.type === 'atrule' && node.name !== 'keyframes')

Expand Down

0 comments on commit fa3b57e

Please sign in to comment.