Skip to content

Commit b94d565

Browse files
Preserve source maps for generated CSS (#7588)
* Preserve source maps for `@apply` * Overwrite the source for all cloned descendants * Preserve source maps when expanding defaults * Verify that source maps are correctly generated * Update changelog
1 parent d72b277 commit b94d565

File tree

9 files changed

+532
-6
lines changed

9 files changed

+532
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Prevent nesting plugin from breaking other plugins ([#7563](https://github.com/tailwindlabs/tailwindcss/pull/7563))
1111
- Recursively collapse adjacent rules ([#7565](https://github.com/tailwindlabs/tailwindcss/pull/7565))
1212
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
13+
- Preserve source maps for generated CSS ([#7588](https://github.com/tailwindlabs/tailwindcss/pull/7588))
1314

1415
## [3.0.23] - 2022-02-16
1516

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"jest-diff": "^27.5.1",
5353
"prettier": "^2.5.1",
5454
"prettier-plugin-tailwindcss": "^0.1.7",
55-
"rimraf": "^3.0.0"
55+
"rimraf": "^3.0.0",
56+
"source-map-js": "^1.0.2"
5657
},
5758
"peerDependencies": {
5859
"autoprefixer": "^10.0.2",

src/lib/expandApplyAtRules.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function processApply(root, context) {
140140
for (let apply of applies) {
141141
let candidates = perParentApplies.get(apply.parent) || []
142142

143-
perParentApplies.set(apply.parent, candidates)
143+
perParentApplies.set(apply.parent, [candidates, apply.source])
144144

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

@@ -178,7 +178,7 @@ function processApply(root, context) {
178178
}
179179
}
180180

181-
for (const [parent, candidates] of perParentApplies) {
181+
for (const [parent, [candidates, atApplySource]] of perParentApplies) {
182182
let siblings = []
183183

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

222222
let root = postcss.root({ nodes: [node.clone()] })
223+
224+
// Make sure every node in the entire tree points back at the @apply rule that generated it
225+
root.walk((node) => {
226+
node.source = atApplySource
227+
})
228+
223229
let canRewriteSelector =
224230
node.type !== 'atrule' || (node.type === 'atrule' && node.name !== 'keyframes')
225231

src/lib/resolveDefaultsAtRules.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,19 @@ export default function resolveDefaultsAtRules({ tailwindConfig }) {
120120
}
121121

122122
for (let [, selectors] of selectorGroups) {
123-
let universalRule = postcss.rule()
123+
let universalRule = postcss.rule({
124+
source: universal.source,
125+
})
124126

125127
universalRule.selectors = [...selectors]
126128

127129
universalRule.append(universal.nodes.map((node) => node.clone()))
128130
universal.before(universalRule)
129131
}
130132
} else {
131-
let universalRule = postcss.rule()
133+
let universalRule = postcss.rule({
134+
source: universal.source,
135+
})
132136

133137
universalRule.selectors = ['*', '::before', '::after']
134138

src/util/cloneNodes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ export default function cloneNodes(nodes, source) {
44

55
if (source !== undefined) {
66
cloned.source = source
7+
8+
if ('walk' in cloned) {
9+
cloned.walk((child) => {
10+
child.source = source
11+
})
12+
}
713
}
814

915
return cloned

0 commit comments

Comments
 (0)